From 4eb09d24a22264b58db9fd67da3192358f0fa8b1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 14:47:08 +0700 Subject: [PATCH 1/9] Prepare to Rector 2.0 with PHPStan 2 and PHPParser 5 --- composer.json | 5 ++++- src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php | 2 +- .../Namespace_/AppUsesStaticCallToUseStatementRector.php | 2 +- .../Property/ChangeSnakedFixtureNameToPascalRector.php | 4 ++-- src/Rector/ValueObject/ArrayItemsAndFluentClass.php | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index ff67259..53a00e8 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "php": "^8.1", "cakephp/console": "^5.0", "nette/utils": "^4.0", - "rector/rector": "~1.2.0", + "rector/rector": "dev-main as 1.2.10", "symfony/string": "^6.0 || ^7.0" }, "autoload": { @@ -37,5 +37,8 @@ }, "support": { "source": "https://github.com/cakephp/upgrade" + }, + "require-dev": { + "rector/rector-php-parser": "dev-main" } } diff --git a/src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php b/src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php index 6f69669..ee41b65 100644 --- a/src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php +++ b/src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php @@ -181,7 +181,7 @@ private function replaceArrayToFluentMethodCalls( } /** - * @param array<(\PhpParser\Node\Expr\ArrayItem|null)> $originalArrayItems + * @param array<(\PhpParser\Node\ArrayItem | null)> $originalArrayItems * @param array $arrayMap */ private function extractFluentMethods(array $originalArrayItems, array $arrayMap): ArrayItemsAndFluentClass diff --git a/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php b/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php index 14df897..982767b 100644 --- a/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php +++ b/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php @@ -82,7 +82,7 @@ public function refactor(Node $node): ?Node $names = $this->resolveNamesFromStaticCalls($appUsesStaticCalls); $uses = []; foreach ($names as $name) { - $useUse = new UseUse(new Name($name)); + $useUse = new \PhpParser\Node\UseItem(new Name($name)); $uses[] = new Use_([$useUse]); } diff --git a/src/Rector/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php b/src/Rector/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php index b162e54..a09f640 100644 --- a/src/Rector/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php +++ b/src/Rector/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php @@ -76,7 +76,7 @@ public function refactor(Node $node): ?Node return $node; } - private function refactorPropertyWithArrayDefault(PropertyProperty $propertyProperty): void + private function refactorPropertyWithArrayDefault(\PhpParser\Node\PropertyItem $propertyProperty): void { if (! $propertyProperty->default instanceof Array_) { return; @@ -84,7 +84,7 @@ private function refactorPropertyWithArrayDefault(PropertyProperty $propertyProp $array = $propertyProperty->default; foreach ($array->items as $arrayItem) { - if (! $arrayItem instanceof ArrayItem) { + if (! $arrayItem instanceof \PhpParser\Node\ArrayItem) { continue; } diff --git a/src/Rector/ValueObject/ArrayItemsAndFluentClass.php b/src/Rector/ValueObject/ArrayItemsAndFluentClass.php index 73400fe..1abdece 100644 --- a/src/Rector/ValueObject/ArrayItemsAndFluentClass.php +++ b/src/Rector/ValueObject/ArrayItemsAndFluentClass.php @@ -6,7 +6,7 @@ final class ArrayItemsAndFluentClass { /** - * @param array<\PhpParser\Node\Expr\ArrayItem> $arrayItems + * @param array<\PhpParser\Node\ArrayItem> $arrayItems * @param array $fluentCalls */ public function __construct( @@ -16,7 +16,7 @@ public function __construct( } /** - * @return array<\PhpParser\Node\Expr\ArrayItem> + * @return array<\PhpParser\Node\ArrayItem> */ public function getArrayItems(): array { From 4229d03062c66f906bbc0cc3b3800c3f6e82f6ad Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 14:47:15 +0700 Subject: [PATCH 2/9] rector config --- rector.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 rector.php diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..2627cfa --- /dev/null +++ b/rector.php @@ -0,0 +1,15 @@ +withPaths([ + __DIR__ . '/config', + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withSets([ + \Rector\PhpParser\Set\PhpParserSetList::PHP_PARSER_50 + ]); From 14ddbc4e78eb228b88a4d1ca7139090d9b9ec2dd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 14:50:26 +0700 Subject: [PATCH 3/9] clean up upgrade process --- composer.json | 3 --- rector.php | 15 --------------- 2 files changed, 18 deletions(-) delete mode 100644 rector.php diff --git a/composer.json b/composer.json index 53a00e8..56d3acd 100644 --- a/composer.json +++ b/composer.json @@ -37,8 +37,5 @@ }, "support": { "source": "https://github.com/cakephp/upgrade" - }, - "require-dev": { - "rector/rector-php-parser": "dev-main" } } diff --git a/rector.php b/rector.php deleted file mode 100644 index 2627cfa..0000000 --- a/rector.php +++ /dev/null @@ -1,15 +0,0 @@ -withPaths([ - __DIR__ . '/config', - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - ->withSets([ - \Rector\PhpParser\Set\PhpParserSetList::PHP_PARSER_50 - ]); From bb9fb64c692a328c8ae98c7af2f69530f84c43fe Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 14:55:53 +0700 Subject: [PATCH 4/9] Fix cs --- .../Namespace_/AppUsesStaticCallToUseStatementRector.php | 4 ++-- .../Property/ChangeSnakedFixtureNameToPascalRector.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php b/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php index 982767b..9aa3818 100644 --- a/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php +++ b/src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Stmt\Declare_; use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Use_; -use PhpParser\Node\Stmt\UseUse; +use PhpParser\Node\UseItem; use PhpParser\NodeTraverser; use PHPStan\Type\ObjectType; use Rector\Contract\PhpParser\Node\StmtsAwareInterface; @@ -82,7 +82,7 @@ public function refactor(Node $node): ?Node $names = $this->resolveNamesFromStaticCalls($appUsesStaticCalls); $uses = []; foreach ($names as $name) { - $useUse = new \PhpParser\Node\UseItem(new Name($name)); + $useUse = new UseItem(new Name($name)); $uses[] = new Use_([$useUse]); } diff --git a/src/Rector/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php b/src/Rector/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php index a09f640..a1c7904 100644 --- a/src/Rector/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php +++ b/src/Rector/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php @@ -5,11 +5,11 @@ use Cake\Utility\Inflector; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; +use PhpParser\Node\PropertyItem; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Property; -use PhpParser\Node\Stmt\PropertyProperty; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -76,7 +76,7 @@ public function refactor(Node $node): ?Node return $node; } - private function refactorPropertyWithArrayDefault(\PhpParser\Node\PropertyItem $propertyProperty): void + private function refactorPropertyWithArrayDefault(PropertyItem $propertyProperty): void { if (! $propertyProperty->default instanceof Array_) { return; @@ -84,7 +84,7 @@ private function refactorPropertyWithArrayDefault(\PhpParser\Node\PropertyItem $ $array = $propertyProperty->default; foreach ($array->items as $arrayItem) { - if (! $arrayItem instanceof \PhpParser\Node\ArrayItem) { + if (! $arrayItem instanceof ArrayItem) { continue; } From 4aa8f836712d775bdef2b12fd74b6c9056a6ca05 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 14:58:17 +0700 Subject: [PATCH 5/9] try require php-parser 5 for phpunit conflict --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 56d3acd..7f25485 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "php": "^8.1", "cakephp/console": "^5.0", "nette/utils": "^4.0", + "nikic/php-parser": "^5.0", "rector/rector": "dev-main as 1.2.10", "symfony/string": "^6.0 || ^7.0" }, From 88174ac35c0c908bacf8f6244b6737dd83c250f0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 15:03:30 +0700 Subject: [PATCH 6/9] bump to phpunit ^10.5.38 for latest phpunit 10 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 58341ca..d224b7f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ DEV_DEPENDENCIES = cakephp/cakephp:5.x-dev \ cakephp/cakephp-codesniffer:^5.0 \ mikey179/vfsstream:^1.6.8 \ - phpunit/phpunit:^10.1 + phpunit/phpunit:^10.5.38 install-dev: composer require --dev $(DEV_DEPENDENCIES) From 5b896c166cfc90a8c54e35d752297e11bd4d09f6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 15:05:55 +0700 Subject: [PATCH 7/9] try require preload --- composer.json | 7 ++++++- tests/bootstrap.php | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7f25485..e355eb2 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,6 @@ "php": "^8.1", "cakephp/console": "^5.0", "nette/utils": "^4.0", - "nikic/php-parser": "^5.0", "rector/rector": "dev-main as 1.2.10", "symfony/string": "^6.0 || ^7.0" }, @@ -38,5 +37,11 @@ }, "support": { "source": "https://github.com/cakephp/upgrade" + }, + "require-dev": { + "cakephp/cakephp": "5.x-dev", + "cakephp/cakephp-codesniffer": "^5.0", + "mikey179/vfsstream": "^1.6.8", + "phpunit/phpunit": "^10.1" } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3e5dfa9..a600612 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,6 +11,8 @@ error_reporting(-1); date_default_timezone_set('UTC'); +require dirname(__DIR__) . '/vendor/rector/rector/preload.php'; + require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/config/bootstrap.php'; From 327df5cd3560453f231e459009107fbf8a7419b7 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 15:06:39 +0700 Subject: [PATCH 8/9] clean up composer.json --- composer.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/composer.json b/composer.json index e355eb2..56d3acd 100644 --- a/composer.json +++ b/composer.json @@ -37,11 +37,5 @@ }, "support": { "source": "https://github.com/cakephp/upgrade" - }, - "require-dev": { - "cakephp/cakephp": "5.x-dev", - "cakephp/cakephp-codesniffer": "^5.0", - "mikey179/vfsstream": "^1.6.8", - "phpunit/phpunit": "^10.1" } } From 4f4b2d88311d81511c78c0f6c5d8dcc5cca58fb7 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 12 Dec 2024 17:04:51 +0700 Subject: [PATCH 9/9] bump to rector 2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 56d3acd..5b749aa 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "php": "^8.1", "cakephp/console": "^5.0", "nette/utils": "^4.0", - "rector/rector": "dev-main as 1.2.10", + "rector/rector": "~2.0.0", "symfony/string": "^6.0 || ^7.0" }, "autoload": {