From 2ed8be5c45a7c4bdc456081aabb04a6291722449 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 18 Dec 2024 06:16:38 +0000 Subject: [PATCH] Updated Rector to commit 4cafa91255c4137074b7ea9aa05754f934e99ab9 https://github.com/rectorphp/rector-src/commit/4cafa91255c4137074b7ea9aa05754f934e99ab9 Rollback reindex node attributes before refactor (#6603) --- src/Application/NodeAttributeReIndexer.php | 51 +++++++++++++++++++ src/Application/VersionResolver.php | 4 +- .../ReIndexNodeAttributeVisitor.php | 46 +---------------- src/Rector/AbstractRector.php | 2 + vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_static.php | 1 + 6 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 src/Application/NodeAttributeReIndexer.php diff --git a/src/Application/NodeAttributeReIndexer.php b/src/Application/NodeAttributeReIndexer.php new file mode 100644 index 00000000000..0e8eabc7177 --- /dev/null +++ b/src/Application/NodeAttributeReIndexer.php @@ -0,0 +1,51 @@ +params = \array_values($node->params); + if ($node instanceof Closure) { + $node->uses = \array_values($node->uses); + } + } + if ($node instanceof CallLike) { + /** @var FuncCall|MethodCall|New_|NullsafeMethodCall|StaticCall $node */ + $node->args = \array_values($node->args); + } + if ($node instanceof If_) { + $node->elseifs = \array_values($node->elseifs); + } + if ($node instanceof TryCatch) { + $node->catches = \array_values($node->catches); + } + if ($node instanceof Switch_) { + $node->cases = \array_values($node->cases); + } + if ($node instanceof MatchArm && \is_array($node->conds)) { + $node->conds = \array_values($node->conds); + return $node; + } + return null; + } +} diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index f36c157cb9a..dad88e245f9 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'bdb40258944adef73378fa5fc15cc26bded7431f'; + public const PACKAGE_VERSION = '4cafa91255c4137074b7ea9aa05754f934e99ab9'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-12-18 03:54:39'; + public const RELEASE_DATE = '2024-12-18 13:14:03'; /** * @var int */ diff --git a/src/PHPStan/NodeVisitor/ReIndexNodeAttributeVisitor.php b/src/PHPStan/NodeVisitor/ReIndexNodeAttributeVisitor.php index 592922616fc..15e48d2beed 100644 --- a/src/PHPStan/NodeVisitor/ReIndexNodeAttributeVisitor.php +++ b/src/PHPStan/NodeVisitor/ReIndexNodeAttributeVisitor.php @@ -4,54 +4,12 @@ declare (strict_types=1); namespace Rector\PHPStan\NodeVisitor; use PhpParser\Node; -use PhpParser\Node\Expr\CallLike; -use PhpParser\Node\Expr\Closure; -use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Expr\MethodCall; -use PhpParser\Node\Expr\New_; -use PhpParser\Node\Expr\NullsafeMethodCall; -use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\FunctionLike; -use PhpParser\Node\MatchArm; -use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Function_; -use PhpParser\Node\Stmt\If_; -use PhpParser\Node\Stmt\Switch_; -use PhpParser\Node\Stmt\TryCatch; use PhpParser\NodeVisitorAbstract; +use Rector\Application\NodeAttributeReIndexer; final class ReIndexNodeAttributeVisitor extends NodeVisitorAbstract { public function enterNode(Node $node) : ?Node { - if ($node instanceof CallLike) { - /** @var FuncCall|MethodCall|New_|NullsafeMethodCall|StaticCall $node */ - $node->args = \array_values($node->args); - return $node; - } - if ($node instanceof FunctionLike) { - /** @var ClassMethod|Function_|Closure $node */ - $node->params = \array_values($node->params); - if ($node instanceof Closure) { - $node->uses = \array_values($node->uses); - } - return $node; - } - if ($node instanceof If_) { - $node->elseifs = \array_values($node->elseifs); - return $node; - } - if ($node instanceof TryCatch) { - $node->catches = \array_values($node->catches); - return $node; - } - if ($node instanceof Switch_) { - $node->cases = \array_values($node->cases); - return $node; - } - if ($node instanceof MatchArm && \is_array($node->conds)) { - $node->conds = \array_values($node->conds); - return $node; - } - return null; + return NodeAttributeReIndexer::reIndexNodeAttributes($node); } } diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index 3ff1db9e851..4de7df70fa3 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -19,6 +19,7 @@ use PHPStan\Analyser\MutatingScope; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use Rector\Application\ChangedNodeScopeRefresher; +use Rector\Application\NodeAttributeReIndexer; use Rector\Application\Provider\CurrentFileProvider; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\ChangesReporting\ValueObject\RectorWithLineChange; @@ -107,6 +108,7 @@ CODE_SAMPLE; } // ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN $originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node; + NodeAttributeReIndexer::reIndexNodeAttributes($node); $refactoredNode = $this->refactor($node); // @see NodeTraverser::* codes, e.g. removal of node of stopping the traversing if ($refactoredNode === NodeVisitor::REMOVE_NODE) { diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index deb1bc3a89d..4409296b35e 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -996,6 +996,7 @@ return array( 'Rector\\Application\\ApplicationFileProcessor' => $baseDir . '/src/Application/ApplicationFileProcessor.php', 'Rector\\Application\\ChangedNodeScopeRefresher' => $baseDir . '/src/Application/ChangedNodeScopeRefresher.php', 'Rector\\Application\\FileProcessor' => $baseDir . '/src/Application/FileProcessor.php', + 'Rector\\Application\\NodeAttributeReIndexer' => $baseDir . '/src/Application/NodeAttributeReIndexer.php', 'Rector\\Application\\Provider\\CurrentFileProvider' => $baseDir . '/src/Application/Provider/CurrentFileProvider.php', 'Rector\\Application\\VersionResolver' => $baseDir . '/src/Application/VersionResolver.php', 'Rector\\Arguments\\ArgumentDefaultValueReplacer' => $baseDir . '/rules/Arguments/ArgumentDefaultValueReplacer.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 0fe7cca4084..c62881fed77 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -1215,6 +1215,7 @@ class ComposerStaticInite1459f150f08d0eee2804dfc37f818db 'Rector\\Application\\ApplicationFileProcessor' => __DIR__ . '/../..' . '/src/Application/ApplicationFileProcessor.php', 'Rector\\Application\\ChangedNodeScopeRefresher' => __DIR__ . '/../..' . '/src/Application/ChangedNodeScopeRefresher.php', 'Rector\\Application\\FileProcessor' => __DIR__ . '/../..' . '/src/Application/FileProcessor.php', + 'Rector\\Application\\NodeAttributeReIndexer' => __DIR__ . '/../..' . '/src/Application/NodeAttributeReIndexer.php', 'Rector\\Application\\Provider\\CurrentFileProvider' => __DIR__ . '/../..' . '/src/Application/Provider/CurrentFileProvider.php', 'Rector\\Application\\VersionResolver' => __DIR__ . '/../..' . '/src/Application/VersionResolver.php', 'Rector\\Arguments\\ArgumentDefaultValueReplacer' => __DIR__ . '/../..' . '/rules/Arguments/ArgumentDefaultValueReplacer.php',