PSR12/ClassInstantiation: bug fix for attributes with anonymous classes #3457
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.
The
class
keyword was correctly tokenized asT_ANON_CLASS
, even when there is an attribute between thenew
and theclass
keyword, however, thePSR12.Classes.ClassInstantiation
sniff did not take that possibility into account, leading to false positives.This commit:
Note: I've elected to skip over attributes, but as these attributes AFAICS can only be added in combination with an anonymous class and anonymous classes are ignored by this sniff, it would also be a valid option to bow out of the sniff when an attribute is encountered. As this would be inconsistent with how the
T_ANON_CLASS
token was handled so far, I've not gone with that option.Includes unit test.
Fixes #3456