Tokenizer/PHP: improved tokenization of fully qualified exit/die/true/false/null #1206
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
This PR actions proposal #1201 and, for the sniffs, largely backports the tests previously added in the 4.x branch via #1042, though with different sniff changes.
Note: the previously made sniff changes for #1042 in the 4.x branch will for the most part be reverted when this PR is merged up into 4.x, as they will no longer be needed.
Additionally when this PR will be merged up into the 4.x branch:
Commits
Tokenizer/PHP: improved tokenization of fully qualified exit/die/true/false/null
As described in more detail in #1201, if the
exit
/die
/true
/false
/null
keywords were used in their fully qualified form, this was previously tokenized asT_NS_SEPARATOR
+T_STRING
, which was rarely, if ever, handled correctly by sniffs.This commit now changes the tokenization of fully qualified
exit
/die
/true
/false
/null
to beT_NS_SEPARATOR
+ the relevant dedicated token, i.eT_EXIT
/T_TRUE
/T_FALSE
orT_NULL
.Includes plenty of tests, including tests to safeguard against regressions which could be caused by this change in the "context sensitive keywords" layer and the "undo PHP 8.0+ namespaced names" layer.
Fixes #1201 (for PHPCS 3.x).
Related to #734
Generic/UnconditionalIfStatement: handle FQN true/false/null
This sniff checks for
if
/elseif
which only contain "true" or "false", i.e. don't actually compare to anything.This commit fixes the sniff to still function correctly when it encounters "fully qualified true/false".
Includes tests.
Generic/DisallowYodaConditions: handle FQN true/false/null
This commit fixes the sniff to handle "fully qualified true/false" the same as unqualified true/false.
Includes tests.
Generic/[Lower|Upper]CaseConstant: add tests with FQN true/false/
null
These are the only two sniffs explicitly targetting
true
,false
andnull
.This commit adds some tests to safeguard these sniffs function correctly on "fully qualified true/false/null".
PEAR/ValidDefaultValue: handle FQN null
This commit fixes the sniff to handle "fully qualified null" as a default value, the same as unqualified null.
Includes tests.
Squiz/ComparisonOperatorUsage: adds tests with FQN true/false/null
Squiz/NonExecutableCode: handle FQN exit/die
This commit fixes the sniff to handle "fully qualified exit/die" the same as unqualified exit/die.
Includes tests.
Related to #734
Suggested changelog entry
Added:
exit
/die
can now be used as fully qualified "function calls".Fixed:
true
/false
/null
was incorrectly tokenized asT_NS_SEPARATOR
+T_STRING
instead of asT_NS_SEPARATOR
+T_TRUE
/T_FALSE
/T_NULL
.true
/false
/null
correctly:Related issues/external references
Fixes #1201