Skip to content

[traversing] Decouple Rector rules from PhpParser NodeVisitor - #8541

Merged
TomasVotruba merged 1 commit into
mainfrom
remove-nodevisitor-from-rector-interface
Oct 8, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
remove-nodevisitor-from-rector-interface

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

What

RectorInterface no longer extends PhpParser\NodeVisitor, and AbstractRector no longer extends NodeVisitorAbstract.

Why

Rules are run only through the custom RectorNodeTraverser, which calls enterNode() and getNodeTypes(). The beforeTraverse(), afterTraverse() and leaveNode() hooks from the NodeVisitor contract were never invoked on rules - dead surface kept alive only by the inheritance.

Changes

  • RectorInterface extends only DocumentedRuleInterface; enterNode() is now declared explicitly on the contract (the engine calls it).
  • AbstractRector drops extends NodeVisitorAbstract and the dead, already-deprecated leaveNode().
  • DeprecatedRulesReporter guards its beforeTraverse reflection with hasMethod(), since rules no longer carry that method by default.

Follows up #8540, which removed the matching no-op beforeTraverse()/afterTraverse() loops in RectorNodeTraverser.

Local composer complete-check passes.

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.
@TomasVotruba
TomasVotruba force-pushed the remove-nodevisitor-from-rector-interface branch from 7937fc1 to 68891fe Compare October 8, 2026 17:00
@TomasVotruba TomasVotruba changed the title [Core] Decouple Rector rules from PhpParser NodeVisitor [traversing] Decouple Rector rules from PhpParser NodeVisitor Oct 8, 2026
@TomasVotruba
TomasVotruba merged commit 1654cef into main Oct 8, 2026
50 checks passed
@TomasVotruba
TomasVotruba deleted the remove-nodevisitor-from-rector-interface branch October 8, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant