NewKeywords: fix too aggressive accounting for PHPCS cross-compat #627
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.
A number of tokens are not correctly back-filled across PHP versions by various PHPCS versions.
To that end, a token translation table is used to recognize tokens tokenized as
T_STRING
as the keyword anyway.At the same time, PHPCS sometimes retokenizes too aggressively, changing
T_STRING
tokens to a keyword token when it shouldn't.Most PHP keywords can be safely used as variable (and property) names and as of PHP 7, as the name of class constants.
Ref: http://php.net/manual/en/reserved.keywords.php
As property names when referenced and class constant names, both when referenced as well as when declared, are tokenized as
T_STRING
, this leads to false positives from this sniff.At the same time, keywords in PHP are case-insensitive, so the cross-compat layer should allow for mixed case / uppercase use of the (non magic-constant) keywords as well.
This commit fixes both.
Includes unit tests.