From 1c7d8dee6e1abc9f4e6c220fee8295d4d0bc5ed4 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 12 Dec 2024 23:06:41 +0700 Subject: [PATCH] Prepare to Rector next 2.0 with PHPStan 2 and PHPParser 5 (#302) * Prepare to Rector 2.0 with PHPStan 2 and PHPParser 5 * rector config * clean up upgrade process * Fix cs * try require php-parser 5 for phpunit conflict * bump to phpunit ^10.5.38 for latest phpunit 10 * try require preload * clean up composer.json * bump to rector 2 --- Makefile | 2 +- composer.json | 2 +- src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php | 2 +- .../Namespace_/AppUsesStaticCallToUseStatementRector.php | 4 ++-- .../Property/ChangeSnakedFixtureNameToPascalRector.php | 6 +++--- src/Rector/ValueObject/ArrayItemsAndFluentClass.php | 4 ++-- tests/bootstrap.php | 2 ++ 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 58341cab..d224b7fb 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) diff --git a/composer.json b/composer.json index ff67259a..5b749aaa 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": "~2.0.0", "symfony/string": "^6.0 || ^7.0" }, "autoload": { diff --git a/src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php b/src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php index 6f69669a..ee41b651 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 14df897b..9aa38185 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 UseUse(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 b162e546..a1c79044 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(PropertyProperty $propertyProperty): void + private function refactorPropertyWithArrayDefault(PropertyItem $propertyProperty): void { if (! $propertyProperty->default instanceof Array_) { return; diff --git a/src/Rector/ValueObject/ArrayItemsAndFluentClass.php b/src/Rector/ValueObject/ArrayItemsAndFluentClass.php index 73400fe3..1abdece8 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 { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3e5dfa9e..a600612b 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';