mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
prepare config
This commit is contained in:
parent
0efc746c93
commit
44f25ea3f1
@ -1,4 +1,128 @@
|
||||
# source: https://book.cakephp.org/3.0/en/appendices/3-4-migration-guide.html
|
||||
|
||||
services:
|
||||
# ...
|
||||
Rector\CakePHP\Rector\MethodCall\ModalToGetSetRector:
|
||||
$methodNamesByTypes:
|
||||
Cake\Core\InstanceConfigTrait:
|
||||
- 'config'
|
||||
Cake\Core\StaticConfigTrait:
|
||||
- 'config'
|
||||
- 'dsnClassMap'
|
||||
Cake\Console\ConsoleOptionParser:
|
||||
- 'command'
|
||||
- 'description'
|
||||
- 'epilog'
|
||||
Cake\Database\Connection:
|
||||
- 'driver'
|
||||
- 'schemaCollection'
|
||||
#- 'useSavePoints' #() (now enableSavePoints()/isSavePointsEnabled('
|
||||
Cake\Database\Driver:
|
||||
- 'autoQuoting' # (now enableAutoQuoting()/isAutoQuotingEnabled('
|
||||
Cake\Database\Expression\FunctionExpression:
|
||||
- 'name'
|
||||
Cake\Database\Expression\QueryExpression:
|
||||
#- 'tieWith' #() (now setConjunction()/getConjunction('
|
||||
Cake\Database\Expression\ValuesExpression:
|
||||
- 'columns'
|
||||
- 'values'
|
||||
- 'query'
|
||||
Cake\Database\Query:
|
||||
- 'connection'
|
||||
- 'selectTypeMap'
|
||||
#- 'bufferResults' #() (now enableBufferedResults()/isBufferedResultsEnabled('
|
||||
Cake\Database\Schema\CachedCollection:
|
||||
- 'cacheMetadata'
|
||||
Cake\Database\Schema\TableSchema:
|
||||
- 'options'
|
||||
#- 'temporary' #() (now setTemporary()/isTemporary('
|
||||
Cake\Database\TypeMap:
|
||||
- 'defaults'
|
||||
- 'types'
|
||||
Cake\Database\TypeMapTrait:
|
||||
- 'typeMap'
|
||||
- 'defaultTypes'
|
||||
Cake\ORM\Association:
|
||||
- 'name'
|
||||
- 'cascadeCallbacks'
|
||||
- 'source'
|
||||
- 'target'
|
||||
- 'conditions'
|
||||
- 'bindingKey'
|
||||
- 'foreignKey'
|
||||
- 'dependent'
|
||||
- 'joinType'
|
||||
- 'property'
|
||||
- 'strategy'
|
||||
- 'finder'
|
||||
Cake\ORM\Association\BelongsToMany:
|
||||
- 'targetForeignKey'
|
||||
- 'saveStrategy'
|
||||
- 'conditions'
|
||||
Cake\ORM\Association\HasMany:
|
||||
- 'saveStrategy'
|
||||
- 'foreignKey'
|
||||
- 'sort'
|
||||
Cake\ORM\Association\HasOne:
|
||||
- 'foreignKey'
|
||||
Cake\ORM\EagerLoadable:
|
||||
- 'config'
|
||||
#- 'setter part of canBeJoined() (now setCanBeJoined('
|
||||
Cake\ORM\EagerLoader:
|
||||
#- 'matching' #() (getMatching() will have to be called after setMatching() to keep the old behavio'
|
||||
#- 'autoFields' #() (now enableAutoFields()/isAutoFieldsEnabled('
|
||||
Cake\ORM\Locator\TableLocator:
|
||||
- 'config'
|
||||
Cake\ORM\Query:
|
||||
- 'eagerLoader'
|
||||
#- 'hydrate' #() (now enableHydration()/isHydrationEnabled('
|
||||
#- 'autoFields' #() (now enableAutoFields()/isAutoFieldsEnabled('
|
||||
Cake\ORM\Table:
|
||||
- 'table'
|
||||
- 'alias'
|
||||
- 'registryAlias'
|
||||
- 'connection'
|
||||
- 'schema'
|
||||
- 'primaryKey'
|
||||
- 'displayField'
|
||||
- 'entityClass'
|
||||
Cake\Mailer\Email:
|
||||
- 'from'
|
||||
- 'sender'
|
||||
- 'replyTo'
|
||||
- 'readReceipt'
|
||||
- 'returnPath'
|
||||
- 'to'
|
||||
- 'cc'
|
||||
- 'bcc'
|
||||
- 'charset'
|
||||
- 'headerCharset'
|
||||
- 'emailPattern'
|
||||
- 'subject'
|
||||
#- 'template() (now setTemplate()/getTemplate() and setLayout()/getLayout('
|
||||
#- 'viewRender() (now setViewRenderer()/getViewRenderer('
|
||||
- 'viewVars'
|
||||
- 'theme'
|
||||
- 'helpers'
|
||||
- 'emailFormat'
|
||||
- 'transport'
|
||||
- 'messageId'
|
||||
- 'domain'
|
||||
- 'attachments'
|
||||
- 'configTransport'
|
||||
- 'profile'
|
||||
Cake\Validation\Validator:
|
||||
- 'provider'
|
||||
Cake\View\StringTemplateTrait:
|
||||
- 'templates'
|
||||
Cake\View\ViewBuilder:
|
||||
- 'templatePath'
|
||||
- 'layoutPath'
|
||||
- 'plugin'
|
||||
- 'helpers'
|
||||
- 'theme'
|
||||
- 'template'
|
||||
- 'layout'
|
||||
- 'options'
|
||||
- 'name'
|
||||
- 'className'
|
||||
#- 'autoLayout' #() (now enableAutoLayout()/isAutoLayoutEnabled('
|
@ -102,40 +102,46 @@ CODE_SAMPLE
|
||||
continue;
|
||||
}
|
||||
|
||||
$newNames = $methodNamesToGetAndSetNames[$methodCallNode->name->toString()];
|
||||
if ($newNames === null) {
|
||||
$config = $methodNamesToGetAndSetNames[$methodCallNode->name->toString()];
|
||||
if ($config === null) {
|
||||
$currentMethodName = $methodCallNode->name->toString();
|
||||
|
||||
return [
|
||||
$config = [
|
||||
'get' => 'get' . ucfirst($currentMethodName),
|
||||
'set' => 'set' . ucfirst($currentMethodName),
|
||||
];
|
||||
}
|
||||
|
||||
return $newNames;
|
||||
// default minimal argument count for setter
|
||||
$config['minimal_argument_count'] = $config['minimal_argument_count'] ?? 1;
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $typeAndMethodNames
|
||||
* @param mixed[] $config
|
||||
*/
|
||||
private function resolveNewMethodNameByCondition(MethodCall $methodCallNode, array $typeAndMethodNames): string
|
||||
private function resolveNewMethodNameByCondition(MethodCall $methodCallNode, array $config): string
|
||||
{
|
||||
// default:
|
||||
// - has arguments? => set
|
||||
// - get
|
||||
// "minimal_argument_count" : 2
|
||||
// "first_argument_type" : array
|
||||
|
||||
if (
|
||||
count($methodCallNode->args) >= 2 ||
|
||||
(isset($methodCallNode->args[0]) && $methodCallNode->args[0]->value instanceof Array_)
|
||||
) {
|
||||
return $typeAndMethodNames['set'];
|
||||
if (count($methodCallNode->args) >= $config['minimal_argument_count']) {
|
||||
return $config['set'];
|
||||
}
|
||||
|
||||
return $typeAndMethodNames['get'];
|
||||
if (isset($methodCallNode->args[0])) {
|
||||
// first argument type that is considered setter
|
||||
if (isset($config['first_argument_type_to_set'])) {
|
||||
$argumentType = $config['first_argument_type_to_set'];
|
||||
$argumentValue = $methodCallNode->args[0]->value;
|
||||
|
||||
if ($argumentType === 'array' && $argumentValue instanceof Array_) {
|
||||
return $config['set'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $config['get'];
|
||||
}
|
||||
}
|
||||
|
@ -2,137 +2,13 @@ services:
|
||||
Rector\CakePHP\Rector\MethodCall\ModalToGetSetRector:
|
||||
$methodNamesByTypes:
|
||||
'Rector\CakePHP\Tests\Rector\MethodCall\ModalToGetSetRector\Source\SomeModelType':
|
||||
config: ~
|
||||
config:
|
||||
get: 'getConfig'
|
||||
set: 'setConfig'
|
||||
minimal_argument_count: 2
|
||||
first_argument_type_to_set: 'array'
|
||||
customMethod:
|
||||
get: 'customMethodGetName'
|
||||
set: 'customMethodSetName'
|
||||
|
||||
# config: ~
|
||||
|
||||
# - 'useSavePoints' #() (now enableSavePoints()/isSavePointsEnabled('
|
||||
|
||||
# move to cakephp 3.6 set
|
||||
# Cake\Core\InstanceConfigTrait:
|
||||
# - 'config'
|
||||
# Cake\Core\StaticConfigTrait:
|
||||
# - 'config'
|
||||
# - 'dsnClassMap'
|
||||
# Cake\Console\ConsoleOptionParser:
|
||||
# - 'command'
|
||||
# - 'description'
|
||||
# - 'epilog'
|
||||
# Cake\Database\Connection:
|
||||
# - 'driver'
|
||||
# - 'schemaCollection'
|
||||
# # https://github.com/cakephp/cakephp/blob/4feee5463641e05c068b4d1d31dc5ee882b4240f/src/Database/Connection.php#L611-L640
|
||||
# - 'useSavePoints' #() (now enableSavePoints()/isSavePointsEnabled('
|
||||
# Cake\Database\Driver:
|
||||
# - 'autoQuoting' # (now enableAutoQuoting()/isAutoQuotingEnabled('
|
||||
# Cake\Database\Expression\FunctionExpression:
|
||||
# - 'name'
|
||||
# Cake\Database\Expression\QueryExpression:
|
||||
# - 'tieWith' #() (now setConjunction()/getConjunction('
|
||||
# Cake\Database\Expression\ValuesExpression:
|
||||
# - 'columns'
|
||||
# - 'values'
|
||||
# - 'query'
|
||||
# Cake\Database\Query:
|
||||
# - 'connection'
|
||||
# - 'selectTypeMap'
|
||||
# - 'bufferResults' #() (now enableBufferedResults()/isBufferedResultsEnabled('
|
||||
# Cake\Database\Schema\CachedCollection:
|
||||
# - 'cacheMetadata'
|
||||
# Cake\Database\Schema\TableSchema:
|
||||
# - 'options'
|
||||
# - 'temporary' #() (now setTemporary()/isTemporary('
|
||||
# Cake\Database\TypeMap:
|
||||
# - 'defaults'
|
||||
# - 'types'
|
||||
# Cake\Database\TypeMapTrait:
|
||||
# - 'typeMap'
|
||||
# - 'defaultTypes'
|
||||
# Cake\ORM\Association:
|
||||
# - 'name'
|
||||
# - 'cascadeCallbacks'
|
||||
# - 'source'
|
||||
# - 'target'
|
||||
# - 'conditions'
|
||||
# - 'bindingKey'
|
||||
# - 'foreignKey'
|
||||
# - 'dependent'
|
||||
# - 'joinType'
|
||||
# - 'property'
|
||||
# - 'strategy'
|
||||
# - 'finder'
|
||||
# Cake\ORM\Association\BelongsToMany:
|
||||
# - 'targetForeignKey'
|
||||
# - 'saveStrategy'
|
||||
# - 'conditions'
|
||||
# Cake\ORM\Association\HasMany:
|
||||
# - 'saveStrategy'
|
||||
# - 'foreignKey'
|
||||
# - 'sort'
|
||||
# Cake\ORM\Association\HasOne:
|
||||
# - 'foreignKey'
|
||||
# Cake\ORM\EagerLoadable:
|
||||
# - 'config'
|
||||
# #- 'setter part of canBeJoined() (now setCanBeJoined('
|
||||
# Cake\ORM\EagerLoader:
|
||||
# - 'matching' #() (getMatching() will have to be called after setMatching() to keep the old behavio'
|
||||
# - 'autoFields' #() (now enableAutoFields()/isAutoFieldsEnabled('
|
||||
# Cake\ORM\Locator\TableLocator:
|
||||
# - 'config'
|
||||
# Cake\ORM\Query:
|
||||
# - 'eagerLoader'
|
||||
# - 'hydrate' #() (now enableHydration()/isHydrationEnabled('
|
||||
# - 'autoFields' #() (now enableAutoFields()/isAutoFieldsEnabled('
|
||||
# Cake\ORM\Table:
|
||||
# - 'table'
|
||||
# - 'alias'
|
||||
# - 'registryAlias'
|
||||
# - 'connection'
|
||||
# - 'schema'
|
||||
# - 'primaryKey'
|
||||
# - 'displayField'
|
||||
# - 'entityClass'
|
||||
# Cake\Mailer\Email:
|
||||
# - 'from'
|
||||
# - 'sender'
|
||||
# - 'replyTo'
|
||||
# - 'readReceipt'
|
||||
# - 'returnPath'
|
||||
# - 'to'
|
||||
# - 'cc'
|
||||
# - 'bcc'
|
||||
# - 'charset'
|
||||
# - 'headerCharset'
|
||||
# - 'emailPattern'
|
||||
# - 'subject'
|
||||
# - 'template() (now setTemplate()/getTemplate() and setLayout()/getLayout('
|
||||
# - 'viewRender() (now setViewRenderer()/getViewRenderer('
|
||||
# - 'viewVars'
|
||||
# - 'theme'
|
||||
# - 'helpers'
|
||||
# - 'emailFormat'
|
||||
# - 'transport'
|
||||
# - 'messageId'
|
||||
# - 'domain'
|
||||
# - 'attachments'
|
||||
# - 'configTransport'
|
||||
# - 'profile'
|
||||
# Cake\Validation\Validator:
|
||||
# - 'provider'
|
||||
# Cake\View\StringTemplateTrait:
|
||||
# - 'templates'
|
||||
# Cake\View\ViewBuilder:
|
||||
# - 'templatePath'
|
||||
# - 'layoutPath'
|
||||
# - 'plugin'
|
||||
# - 'helpers'
|
||||
# - 'theme'
|
||||
# - 'template'
|
||||
# - 'layout'
|
||||
# - 'options'
|
||||
# - 'name'
|
||||
# - 'className'
|
||||
# - 'autoLayout' #() (now enableAutoLayout()/isAutoLayoutEnabled('
|
||||
minimal_argument_count: 2
|
||||
first_argument_type_to_set: 'array'
|
||||
|
Loading…
x
Reference in New Issue
Block a user