From 68891fe20fec0f51080a0e8576a6a5c77fae802b Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 8 Oct 2026 18:51:55 +0200 Subject: [PATCH] [Core] Decouple Rector rules from PhpParser NodeVisitor RectorInterface no longer extends NodeVisitor and AbstractRector no longer extends NodeVisitorAbstract. Rules are run only through the custom RectorNodeTraverser, which uses enterNode() and getNodeTypes(), so the beforeTraverse()/afterTraverse()/leaveNode() hooks were dead. --- src/Contract/Rector/RectorInterface.php | 7 +++++- src/Rector/AbstractRector.php | 30 +------------------------ 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/Contract/Rector/RectorInterface.php b/src/Contract/Rector/RectorInterface.php index 2602bd2a67e..89553c6c804 100644 --- a/src/Contract/Rector/RectorInterface.php +++ b/src/Contract/Rector/RectorInterface.php @@ -8,7 +8,7 @@ use PhpParser\NodeVisitor; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; -interface RectorInterface extends NodeVisitor, DocumentedRuleInterface +interface RectorInterface extends DocumentedRuleInterface { /** * List of nodes this class checks, classes that implements \PhpParser\Node @@ -18,6 +18,11 @@ interface RectorInterface extends NodeVisitor, DocumentedRuleInterface */ public function getNodeTypes(): array; + /** + * @return int|Node|Node[]|null + */ + public function enterNode(Node $node): int|Node|array|null; + /** * Process Node of matched type * @return Node|Node[]|null|NodeVisitor::REMOVE_NODE diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index db40c8f2140..ae927e9b818 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -4,7 +4,6 @@ namespace Rector\Rector; -use Deprecated; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Name; @@ -17,7 +16,6 @@ use PhpParser\NodeTraverser; use PhpParser\NodeVisitor; use PhpParser\NodeVisitor\CloningVisitor; -use PhpParser\NodeVisitorAbstract; use PHPStan\Analyser\MutatingScope; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -40,7 +38,7 @@ use Rector\Skipper\ValueObject\SkipMatch; use Rector\ValueObject\Application\File; -abstract class AbstractRector extends NodeVisitorAbstract implements RectorInterface +abstract class AbstractRector implements RectorInterface { private const string EMPTY_NODE_ARRAY_MESSAGE = <<refactor()" returns non-empty array for Nodes. @@ -103,26 +101,6 @@ public function autowire( $this->commentsMerger = $commentsMerger; } - /** - * @return Node[]|null - * - * @internal - */ - final public function beforeTraverse(array $nodes): ?array - { - return null; - } - - /** - * @return Node[]|null - * - * @internal - */ - final public function afterTraverse(array $nodes) - { - return null; - } - /** * @return NodeVisitor::REMOVE_NODE|Node|null|Node[] */ @@ -190,12 +168,6 @@ final public function enterNode(Node $node): int|Node|null|array return $this->postRefactorProcess($originalNode, $node, $refactoredNodeOrState, $filePath); } - #[Deprecated(message: 'no longer used')] - final public function leaveNode(Node $node): array|int|Node|null - { - return null; - } - protected function getFile(): File { $file = $this->currentFileProvider->getFile();