PHPCS 4.x | Tokenizer: fix stray "parenthesis_..." indexes being set for non-closure use #3104
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.
Commit 08824f3 (issue #2593) added support for
T_USE
tokens for closures being parentheses owners.However, the net effect was that every
T_USE
token - including import/trait use statementT_USE
tokens, would have theparenthesis_owner
,parenthesis_opener
andparenthesis_closer
indexes set.For closure
use
statements, those were set correctly.However, for import/trait
use
statements, theparenthesis_owner
would point to theT_USE
keyword which doesn't have parentheses and theparenthesis_opener
andparenthesis_closer
indexes would benull
in most cases, but they would still be set.Also, in some cases, the
parenthesis_opener
andparenthesis_closer
indexes for import/traituse
statements would incorrectly be set if to arbitrary, unrelated parenthesis, if no open curly or open square bracket was encountered between theuse
statement and the next set of parenthesis.That makes the
parenthesis_...
indexes harder and less intuitive to work with as any of theparenthesis_...
indexes could be set, even when the token has no parenthesis.I've fixed this now by:
$openOwner
variable when we know there won't be any parenthesis, but by also resetting theparenthesis_...
indexes of the incorrectly set owner.T_OPEN_USE_GROUP
token, as thetokenize()
method has already run, so group use tokens have already been retokenized to their dedicated token.Note: There may be some more tokens which can be added to this list, but this should be a reasonable start.
I've also added a few
continue
statements to skip the rest of the code within the loop when we know in advance none of the other conditions would match anyway.Includes adding dedicated unit tests verifying the correct setting of the
parenthesis_...
indexes.