Tokenizer/PHP: T_GOTO_LABEL
no longer contains colon
#1016
Merged
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.
Description
When support for the
goto
construct was introduced, it was elected to tokenize the "goto target label" as a separateT_GOTO_LABEL
token, including the colon following it.This is wrong as PHP does not enforce for the colon to be the next token and allows whitespace and comments between the goto label and the colon. In which case, the tokenization in PHPCS would be incorrect as the label would stay a
T_STRING
instead of becomingT_GOTO_LABEL
.This commit fixes this.
It also introduces a new
T_GOTO_COLON
token and re-tokenizes the colon (separate from the label) toT_GOTO_COLON
. This choice was made so as not to confuse the Tokenizer (nor sniffs) with yet another usage forT_COLON
, which is an ambiguous enough token as it is (alternative control structures, switch - case statements, return type statements, enum types, ternaries etc).This change is covered by the existing (updated) tests. Includes one minor update to a sniff to allow for this change.
Refs:
Suggested changelog entry
Changed:
T_GOTO_LABEL
tokens will no longer include the colon following it.T_GOTO_COLON
.Fixed:
T_STRING
if there was whitespace and/or comments between the label and colon.Related issues/external references
Fixes squizlabs/PHP_CodeSniffer#3161
Fixes #185