Tokenizer: assign a parenthesis_owner for anonymous classes with parentheses #2595
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.
Code:
As anonymous classes have a distinct token, it makes sense to me to assign that token as the parenthesis owner, along the same lines as is done for anonymous functions.
The main difference is that for anonymous classes, the parenthesis are optional.
Assigning an owner for them can not be done from within the
Tokenizer::createTokenMap()as at that point in time thePHP::processAdditional()method hasn't run yet, so the token is still aT_CLASS.It can however be adjusted from within the
PHP::processAdditional()method when theT_CLASStoken is changed to aT_ANON_CLASStoken.This commit implements this.
This means that for the
classtoken in the above code snippet will now have aparenthesis_owner,parenthesis_openerandparenthesis_closerin the$tokensarray.The parenthesis opener and closer will both now also have the
parenthesis_ownerkey, in addition to theparenthesis_openerandparenthesis_closerkeys which they already had.Instead of testing this via existing sniffs, I have chosen to add a new set of
Coretests for specific tokenizer issues, with the tests for this change being the first set of tests added.Includes:
T_ANON_CLASStoken to theTokens::$parenthesisOpenersarray.T_ANON_CLASSfrom the "additional tokens indicating that parenthesis are not arbitrary" list in theGeneric.WhiteSpace.ArbitraryParenthesesSpacingsniff.