Fix incorrect result after using RemoveByType in PhpDocInfo #6301
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.
In the new
InlineVarDocTagToAssertRector
Rector rule we call the functionRemoveByType()
in thePhpDocInfo
class like this:If we apply this to this example code:
We will call it with
$variableName
= "expr"In the node visitor defined in line 266 of the
PhpDocInfo
class we would start by processing a node instance ofPhpDocTagNode
and its value would be an instance ofVarTagValueNode
so the first check would be true but the check in line 276 would be false because the variable name does not match the one we passed. Previously we would have returned null and the processing would have continued. We would then process the children of this node and one of them would be theVarTagValueNode
. Since it matches the type of node that we want to remove it would be removed, but then we would be left with an invalid parentPhpDocTagNode
node with valuenull
and this can create issues if another rule tries to process this same node later on.If the node value is a
VarTagValueNode
but the variable name does not match, the right solution is to stop processing the children of this node and this is what this PR implementsHope this makes sense 😅