Repository navigation
[perf] Skip RemoveUselessVarTagRector for nodes without a docblock - #8624
Merged
Merged
Conversation
A useless @var tag can only live in a docblock. The rule subscribes to Property, ClassConst and Expression and built a PhpDocInfo for every one, including the many Expression nodes that carry no docblock. Guard with a cheap getDocComment() check so the phpdoc work runs only when a docblock exists; removeVarTagIfUseless already returns false without a @var tag, so behaviour is unchanged.
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.
Follow-up to the RenameClassRector phpdoc-guard optimization.
RemoveUselessVarTagRectorsubscribes toProperty,ClassConstandExpression, and calledcreateFromNodeOrEmpty()on every visited node. A useless@varcan only exist inside a docblock, so for the manyExpressionnodes without one the work was wasted -VarTagRemover::removeVarTagIfUseless()returnsfalsewhenever there is no@vartag.Guard the phpdoc path behind
getDocComment() !== null. Behaviour identical.Tests:
rules-tests/DeadCode/Rector/Property/RemoveUselessVarTagRector(19) green, ECS + PHPStan level 8 clean.