From ce99063f5a9b1b66da4fb366bceeb0edffcc7f4b Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Mon, 17 Nov 2025 22:17:45 +0100 Subject: [PATCH] refactor custom rector rule namespaces to be major cake version specific --- config/bootstrap.php | 2 +- config/rector/cakephp3.php | 11 +- config/rector/cakephp40.php | 2 +- config/rector/cakephp41.php | 2 +- config/rector/cakephp42.php | 2 +- config/rector/cakephp43.php | 2 +- config/rector/cakephp44.php | 2 +- config/rector/cakephp45.php | 2 +- config/rector/cakephp50.php | 2 +- config/rector/cakephp51.php | 2 +- config/rector/cakephp52.php | 2 +- config/rector/cakephp53.php | 2 +- config/rector/cakephp60.php | 2 +- config/rector/chronos3.php | 2 +- config/rector/migrations45.php | 2 +- config/rector/sets/cakephp-fluent-options.php | 6 +- config/rector/sets/cakephp30.php | 2 +- config/rector/sets/cakephp34.php | 12 +- config/rector/sets/cakephp35.php | 4 +- config/rector/sets/cakephp37.php | 8 +- config/rector/sets/cakephp38.php | 2 +- config/rector/sets/cakephp40.php | 14 +-- config/rector/sets/cakephp41.php | 6 +- config/rector/sets/cakephp42.php | 2 +- config/rector/sets/cakephp43.php | 10 +- config/rector/sets/cakephp45.php | 5 +- config/rector/sets/cakephp50.php | 18 +-- config/rector/sets/cakephp51.php | 2 +- config/rector/sets/cakephp52.php | 2 +- config/rector/sets/cakephp53.php | 10 +- config/rector/sets/cakephp60.php | 4 +- config/rector/sets/chronos3.php | 4 +- phpcs.xml | 1 + .../AppUsesStaticCallToUseStatementRector.php | 3 +- .../ArrayItemsAndFluentClass.php | 2 +- .../ArrayToFluentCall}/ArrayToFluentCall.php | 2 +- .../ArrayToFluentCallRector.php | 9 +- .../ArrayToFluentCall}/FactoryMethod.php | 2 +- .../ChangeSnakedFixtureNameToPascalRector.php | 2 +- .../ModalToGetSet}/ModalToGetSet.php | 2 +- .../ModalToGetSet}/ModalToGetSetRector.php | 5 +- .../{ => Cake3}/ShortClassNameResolver.php | 2 +- .../FluentChainMethodCallNodeAnalyzer.php | 2 +- .../FormBuildValidatorRector.php | 2 +- .../NewEntityToNewEmptyEntityRector.php | 2 +- .../PaginatorCounterFormatRector.php | 2 +- .../RemoveIntermediaryMethod.php | 2 +- .../RemoveIntermediaryMethodRector.php | 10 +- .../RenameMethodCallBasedOnParameter.php | 2 +- ...RenameMethodCallBasedOnParameterRector.php | 5 +- .../AddMethodCallArgs}/AddMethodCallArgs.php | 2 +- .../AddMethodCallArgsRector.php | 5 +- ...ChangeEntityTraitSetArrayToPatchRector.php | 2 +- .../EntityIsEmptyRector.php | 2 +- .../EntityPatchRector.php | 2 +- .../FormExecuteToProcessRector.php | 2 +- .../NewExprToFuncRector.php | 2 +- .../OptionsArrayToNamedParameters.php | 2 +- .../OptionsArrayToNamedParametersRector.php | 5 +- .../QueryParamAccessRector.php | 2 +- .../RemoveMethodCall}/RemoveMethodCall.php | 2 +- .../RemoveMethodCallRector.php | 4 +- .../SetSerializeToView.php | 2 +- .../SetSerializeToViewBuilderRector.php | 2 +- .../StaticConnectionHelperRector.php | 2 +- .../TableRegistryLocatorRector.php | 2 +- .../EventManagerOnRector.php | 2 +- ...placeCommandArgsIoWithPropertiesRector.php | 2 +- src/Rector/CakePHPSetList.php | 107 ++++++++++++++++++ src/Rector/Set/CakePHPLevelSetList.php | 57 ---------- src/Rector/Set/CakePHPSetList.php | 107 ------------------ .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 4 +- .../config/configured_rule.php | 6 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 4 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 4 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 4 +- .../config/configured_rule.php | 4 +- .../config/configured_rule.php | 4 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 2 +- .../config/configured_rule.php | 2 +- 90 files changed, 256 insertions(+), 320 deletions(-) rename src/Rector/{Rector/Namespace_ => Cake3}/AppUsesStaticCallToUseStatementRector.php (98%) rename src/Rector/{ValueObject => Cake3/ArrayToFluentCall}/ArrayItemsAndFluentClass.php (92%) rename src/Rector/{ValueObject => Cake3/ArrayToFluentCall}/ArrayToFluentCall.php (90%) rename src/Rector/{Rector/MethodCall => Cake3/ArrayToFluentCall}/ArrayToFluentCallRector.php (94%) rename src/Rector/{ValueObject => Cake3/ArrayToFluentCall}/FactoryMethod.php (91%) rename src/Rector/{Rector/Property => Cake3}/ChangeSnakedFixtureNameToPascalRector.php (98%) rename src/Rector/{ValueObject => Cake3/ModalToGetSet}/ModalToGetSet.php (96%) rename src/Rector/{Rector/MethodCall => Cake3/ModalToGetSet}/ModalToGetSetRector.php (96%) rename src/Rector/{ => Cake3}/ShortClassNameResolver.php (99%) rename src/Rector/{NodeAnalyzer => Cake4}/FluentChainMethodCallNodeAnalyzer.php (96%) rename src/Rector/{Rector/ClassMethod => Cake4}/FormBuildValidatorRector.php (98%) rename src/Rector/{Rector/MethodCall => Cake4}/NewEntityToNewEmptyEntityRector.php (97%) rename src/Rector/{Rector/MethodCall => Cake4}/PaginatorCounterFormatRector.php (98%) rename src/Rector/{ValueObject => Cake4/RemoveIntermediaryMethod}/RemoveIntermediaryMethod.php (89%) rename src/Rector/{Rector/MethodCall => Cake4/RemoveIntermediaryMethod}/RemoveIntermediaryMethodRector.php (88%) rename src/Rector/{ValueObject => Cake4/RenameMethodCallBasedOnParameter}/RenameMethodCallBasedOnParameter.php (90%) rename src/Rector/{Rector/MethodCall => Cake4/RenameMethodCallBasedOnParameter}/RenameMethodCallBasedOnParameterRector.php (95%) rename src/Rector/{ValueObject => Cake5/AddMethodCallArgs}/AddMethodCallArgs.php (92%) rename src/Rector/{Rector/MethodCall => Cake5/AddMethodCallArgs}/AddMethodCallArgsRector.php (94%) rename src/Rector/{Rector/MethodCall => Cake5}/ChangeEntityTraitSetArrayToPatchRector.php (97%) rename src/Rector/{Rector/MethodCall => Cake5}/EntityIsEmptyRector.php (97%) rename src/Rector/{Rector/MethodCall => Cake5}/EntityPatchRector.php (97%) rename src/Rector/{Rector/ClassMethod => Cake5}/FormExecuteToProcessRector.php (98%) rename src/Rector/{Rector/MethodCall => Cake5}/NewExprToFuncRector.php (98%) rename src/Rector/{ValueObject => Cake5/OptionsArrayToNamedParameters}/OptionsArrayToNamedParameters.php (92%) rename src/Rector/{Rector/MethodCall => Cake5/OptionsArrayToNamedParameters}/OptionsArrayToNamedParametersRector.php (95%) rename src/Rector/{Rector/MethodCall => Cake5}/QueryParamAccessRector.php (98%) rename src/Rector/{ValueObject => Cake5/RemoveMethodCall}/RemoveMethodCall.php (90%) rename src/Rector/{Rector/MethodCall => Cake5/RemoveMethodCall}/RemoveMethodCallRector.php (94%) rename src/Rector/{ValueObject => Cake5/SetSerializeToViewBuilder}/SetSerializeToView.php (85%) rename src/Rector/{Rector/MethodCall => Cake5/SetSerializeToViewBuilder}/SetSerializeToViewBuilderRector.php (97%) rename src/Rector/{Rector/MethodCall => Cake5}/StaticConnectionHelperRector.php (97%) rename src/Rector/{Rector/MethodCall => Cake5}/TableRegistryLocatorRector.php (97%) rename src/Rector/{Rector/MethodCall => Cake6}/EventManagerOnRector.php (97%) rename src/Rector/{Rector/MethodCall => Cake6}/ReplaceCommandArgsIoWithPropertiesRector.php (98%) create mode 100644 src/Rector/CakePHPSetList.php delete mode 100644 src/Rector/Set/CakePHPLevelSetList.php delete mode 100644 src/Rector/Set/CakePHPSetList.php diff --git a/config/bootstrap.php b/config/bootstrap.php index 8e8e34f0..105ccddd 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -38,7 +38,7 @@ try { Configure::config('default', new PhpConfig()); Configure::load('app', 'default', false); -} catch (\Exception $e) { +} catch (Exception $e) { exit($e->getMessage() . "\n"); } diff --git a/config/rector/cakephp3.php b/config/rector/cakephp3.php index e9fe80b2..7cca068f 100644 --- a/config/rector/cakephp3.php +++ b/config/rector/cakephp3.php @@ -1,9 +1,16 @@ sets([CakePHPSetList::CAKEPHP_30, CakePHPSetList::CAKEPHP_34, CakePHPSetList::CAKEPHP_35, CakePHPSetList::CAKEPHP_36, CakePHPSetList::CAKEPHP_37, CakePHPSetList::CAKEPHP_38]); + $rectorConfig->sets([ + CakePHPSetList::CAKEPHP_30, + CakePHPSetList::CAKEPHP_34, + CakePHPSetList::CAKEPHP_35, + CakePHPSetList::CAKEPHP_36, + CakePHPSetList::CAKEPHP_37, + CakePHPSetList::CAKEPHP_38, + ]); }; diff --git a/config/rector/cakephp40.php b/config/rector/cakephp40.php index 6032bf63..a3ace5ce 100644 --- a/config/rector/cakephp40.php +++ b/config/rector/cakephp40.php @@ -1,7 +1,7 @@ ruleWithConfiguration( RenamePropertyRector::class, - [new RenameProperty('Cake\Network\Request', '_session', 'session')] + [new RenameProperty('Cake\Network\Request', '_session', 'session')], ); $rectorConfig->ruleWithConfiguration(ModalToGetSetRector::class, [ @@ -47,7 +47,7 @@ 'Cake\Database\Expression\QueryExpression', 'tieWith', 'getConjunction', - 'setConjunction' + 'setConjunction', ), new ModalToGetSet('Cake\Database\Expression\ValuesExpression', 'columns'), new ModalToGetSet('Cake\Database\Expression\ValuesExpression', 'values'), @@ -58,7 +58,7 @@ 'Cake\Database\Query', 'bufferResults', 'isBufferedResultsEnabled', - 'enableBufferedResults' + 'enableBufferedResults', ), new ModalToGetSet('Cake\Database\Schema\CachedCollection', 'cacheMetadata'), new ModalToGetSet('Cake\Database\Schema\TableSchema', 'options'), diff --git a/config/rector/sets/cakephp35.php b/config/rector/sets/cakephp35.php index 44c1fd13..b011388a 100644 --- a/config/rector/sets/cakephp35.php +++ b/config/rector/sets/cakephp35.php @@ -1,8 +1,8 @@ ruleWithConfiguration( RenameMethodRector::class, - [new MethodCallRename('Cake\ORM\Entity', 'visibleProperties', 'getVisible')] + [new MethodCallRename('Cake\ORM\Entity', 'visibleProperties', 'getVisible')], ); }; diff --git a/config/rector/sets/cakephp40.php b/config/rector/sets/cakephp40.php index f5e31eaf..ddbb742f 100644 --- a/config/rector/sets/cakephp40.php +++ b/config/rector/sets/cakephp40.php @@ -1,13 +1,13 @@ ruleWithConfiguration( RenameMethodRector::class, - [new MethodCallRename('Cake\ORM\Behavior', 'getTable', 'table')] + [new MethodCallRename('Cake\ORM\Behavior', 'getTable', 'table')], ); }; diff --git a/config/rector/sets/cakephp43.php b/config/rector/sets/cakephp43.php index feb5d6c5..515e47e8 100644 --- a/config/rector/sets/cakephp43.php +++ b/config/rector/sets/cakephp43.php @@ -1,21 +1,19 @@ ruleWithConfiguration( RenameMethodRector::class, - [new MethodCallRename('Cake\Controller\Component', 'shutdown', 'afterFilter')] + [new MethodCallRename('Cake\Controller\Component', 'shutdown', 'afterFilter')], ); $rectorConfig->ruleWithConfiguration(PropertyFetchToMethodCallRector::class, [ @@ -26,7 +24,7 @@ $rectorConfig->ruleWithConfiguration( RemoveIntermediaryMethodRector::class, - [new RemoveIntermediaryMethod('getTableLocator', 'get', 'fetchTable')] + [new RemoveIntermediaryMethod('getTableLocator', 'get', 'fetchTable')], ); // These rector rules were removed in rector 0.17 - see https://github.com/rectorphp/rector-src/pull/3777 diff --git a/config/rector/sets/cakephp45.php b/config/rector/sets/cakephp45.php index 81b52a86..610d1ac3 100644 --- a/config/rector/sets/cakephp45.php +++ b/config/rector/sets/cakephp45.php @@ -11,7 +11,7 @@ $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ 'Cake\Datasource\Paging\Paginator' => 'Cake\Datasource\Paging\NumericPaginator', 'Cake\TestSuite\ContainerStubTrait' => 'Cake\Core\TestSuite\ContainerStubTrait', - 'Cake\TestSuite\HttpClientTrait' => 'Cake\Http\TestSuite\HttpClientTrait', + 'Cake\TestSuite\HttpClientTrait' => 'Cake\Http\TestSuite\HttpClientTrait', 'Cake\Cache\InvalidArgumentException' => 'Cake\Cache\Exception\InvalidArgumentException', ]); @@ -20,7 +20,6 @@ [ new MethodCallRename('Cake\View\View', 'loadHelper', 'addHelper'), new MethodCallRename('Cake\Validation\Validator', 'isArray', 'array'), - ] + ], ); - }; diff --git a/config/rector/sets/cakephp50.php b/config/rector/sets/cakephp50.php index c0523f65..91fbbb23 100644 --- a/config/rector/sets/cakephp50.php +++ b/config/rector/sets/cakephp50.php @@ -1,13 +1,13 @@ ['key' => 'cacheKey']]), - ] + ], ); $arrayType = new ArrayType(new MixedType(), new MixedType()); @@ -96,7 +96,7 @@ // Mailer new AddPropertyTypeDeclaration('Cake\Mailer\Mailer', 'name', $stringType), - ] + ], ); $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ diff --git a/config/rector/sets/cakephp51.php b/config/rector/sets/cakephp51.php index e520e2c2..8043fd86 100644 --- a/config/rector/sets/cakephp51.php +++ b/config/rector/sets/cakephp51.php @@ -1,7 +1,7 @@ + config/ src/ tests/ diff --git a/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php b/src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php similarity index 98% rename from src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php rename to src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php index f571d0d6..af1db4b8 100644 --- a/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php +++ b/src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php @@ -1,9 +1,8 @@ + * @var array<\Cake\Upgrade\Rector\Cake3\ArrayToFluentCall\ArrayToFluentCall> */ private array $arraysToFluentCalls = []; /** - * @var array<\Cake\Upgrade\Rector\ValueObject\FactoryMethod> + * @var array<\Cake\Upgrade\Rector\Cake3\ArrayToFluentCall\FactoryMethod> */ private array $factoryMethods = []; diff --git a/src/Rector/ValueObject/FactoryMethod.php b/src/Rector/Cake3/ArrayToFluentCall/FactoryMethod.php similarity index 91% rename from src/Rector/ValueObject/FactoryMethod.php rename to src/Rector/Cake3/ArrayToFluentCall/FactoryMethod.php index 4011b06e..b714fb33 100644 --- a/src/Rector/ValueObject/FactoryMethod.php +++ b/src/Rector/Cake3/ArrayToFluentCall/FactoryMethod.php @@ -1,7 +1,7 @@ + * @var array<\Cake\Upgrade\Rector\Cake3\ModalToGetSet\ModalToGetSet> */ private array $unprefixedMethodsToGetSet = []; diff --git a/src/Rector/ShortClassNameResolver.php b/src/Rector/Cake3/ShortClassNameResolver.php similarity index 99% rename from src/Rector/ShortClassNameResolver.php rename to src/Rector/Cake3/ShortClassNameResolver.php index fbb35c59..f401688a 100644 --- a/src/Rector/ShortClassNameResolver.php +++ b/src/Rector/Cake3/ShortClassNameResolver.php @@ -1,7 +1,7 @@ + * @var array<\Cake\Upgrade\Rector\Cake4\RemoveIntermediaryMethod\RemoveIntermediaryMethod> */ private array $removeIntermediaryMethod = []; diff --git a/src/Rector/ValueObject/RenameMethodCallBasedOnParameter.php b/src/Rector/Cake4/RenameMethodCallBasedOnParameter/RenameMethodCallBasedOnParameter.php similarity index 90% rename from src/Rector/ValueObject/RenameMethodCallBasedOnParameter.php rename to src/Rector/Cake4/RenameMethodCallBasedOnParameter/RenameMethodCallBasedOnParameter.php index 6f0b5c53..1f8e7746 100644 --- a/src/Rector/ValueObject/RenameMethodCallBasedOnParameter.php +++ b/src/Rector/Cake4/RenameMethodCallBasedOnParameter/RenameMethodCallBasedOnParameter.php @@ -1,7 +1,7 @@ + * @var array<\Cake\Upgrade\Rector\Cake4\RenameMethodCallBasedOnParameter\RenameMethodCallBasedOnParameter> */ private array $callsWithParamRenames = []; diff --git a/src/Rector/ValueObject/AddMethodCallArgs.php b/src/Rector/Cake5/AddMethodCallArgs/AddMethodCallArgs.php similarity index 92% rename from src/Rector/ValueObject/AddMethodCallArgs.php rename to src/Rector/Cake5/AddMethodCallArgs/AddMethodCallArgs.php index 04a3a11e..8912cb9a 100644 --- a/src/Rector/ValueObject/AddMethodCallArgs.php +++ b/src/Rector/Cake5/AddMethodCallArgs/AddMethodCallArgs.php @@ -1,7 +1,7 @@ + * @var array<\Cake\Upgrade\Rector\Cake5\AddMethodCallArgs\AddMethodCallArgs> */ private array $callsWithAddMethodCallArgs = []; diff --git a/src/Rector/Rector/MethodCall/ChangeEntityTraitSetArrayToPatchRector.php b/src/Rector/Cake5/ChangeEntityTraitSetArrayToPatchRector.php similarity index 97% rename from src/Rector/Rector/MethodCall/ChangeEntityTraitSetArrayToPatchRector.php rename to src/Rector/Cake5/ChangeEntityTraitSetArrayToPatchRector.php index 1d24fe7b..c2483adc 100644 --- a/src/Rector/Rector/MethodCall/ChangeEntityTraitSetArrayToPatchRector.php +++ b/src/Rector/Cake5/ChangeEntityTraitSetArrayToPatchRector.php @@ -1,7 +1,7 @@ + * @var array<\Cake\Upgrade\Rector\Cake5\OptionsArrayToNamedParameters\OptionsArrayToNamedParameters> */ private array $optionsToNamed = []; diff --git a/src/Rector/Rector/MethodCall/QueryParamAccessRector.php b/src/Rector/Cake5/QueryParamAccessRector.php similarity index 98% rename from src/Rector/Rector/MethodCall/QueryParamAccessRector.php rename to src/Rector/Cake5/QueryParamAccessRector.php index b6846854..645aeba4 100644 --- a/src/Rector/Rector/MethodCall/QueryParamAccessRector.php +++ b/src/Rector/Cake5/QueryParamAccessRector.php @@ -1,7 +1,7 @@ + * @var array<\Cake\Upgrade\Rector\Cake5\RemoveMethodCall\RemoveMethodCall> */ private array $callsWithRemoveMethodCallArgs = []; diff --git a/src/Rector/ValueObject/SetSerializeToView.php b/src/Rector/Cake5/SetSerializeToViewBuilder/SetSerializeToView.php similarity index 85% rename from src/Rector/ValueObject/SetSerializeToView.php rename to src/Rector/Cake5/SetSerializeToViewBuilder/SetSerializeToView.php index 898e19cf..ec847d46 100644 --- a/src/Rector/ValueObject/SetSerializeToView.php +++ b/src/Rector/Cake5/SetSerializeToViewBuilder/SetSerializeToView.php @@ -1,7 +1,7 @@