Repository navigation
Use NodeTraverser from phpstan/phpdoc-parser - #8855
Merged
TomasVotruba merged 1 commit intoOct 26, 2026
Merged
Conversation
Remove PhpDocNodeTraverser, AbstractPhpDocNodeVisitor, PhpDocNodeVisitorInterface and InvalidTraverseException. Use NodeTraverser, AbstractNodeVisitor and NodeVisitor from phpstan/phpdoc-parser. Replace traverseWithCallable() with CallablePhpDocNodeVisitor. Amp-Thread-ID: https://ampcode.com/threads/T-01a17930-0285-73c5-a957-4325c77aa1b2
Member
|
Very nice, thanks for addition Ondra 👏 Great to have this right from the core library. Lets ship it 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR removes the copy of the node traverser. Rector now uses the traverser from phpstan/phpdoc-parser.
This also fixes a slowdown. 3 decorators used the same
PhpDocNodeTraverserservice. EachtraverseWithCallable()call added one more visitor to it, so each docblock was slower to parse than the one before it. Now each call creates a new traverser. Measurement: parsing 2,000 docblocks took 18.6 s before this change and 0.2 s after it.Removed:
PhpDocNodeTraverserAbstractPhpDocNodeVisitorPhpDocNodeVisitorInterfaceInvalidTraverseExceptiontraverseWithCallable()is nownew NodeTraverser([new CallablePhpDocNodeVisitor(...)]).The visitors from rector-doctrine, rector-symfony, rector-phpunit and rector-downgrade-php do not use the removed classes.
Changes in behavior
IntersectionTypeMappernow skips the root node, so it continues to visit the child nodes.PhpDocInfo::removeByType()does not go into@psalm-*and@phpstan-*tags. Before this change, it returnedtruefor these tags, but it did not remove them.leaveNode()returnsREMOVE_NODEfor a node in an array, the node is now removed. The old traverser did not do this.