Move is_use_of_global_constant() utility method to dedicated ConstantsHelper
#2248
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.
Move is_use_of_global_constant() utility method to dedicated
ConstantsHelper
The
is_use_of_global_constant()
utility method is only used by a small set of sniffs, so is better placed in a dedicated class.This commit moves the
is_use_of_global_constant()
method to the newWordPressCS\WordPress\Helpers\ConstantsHelper
class and starts using that class in the relevant sniff.Related to #1465
The functionality in this new class will very likely be replaced at some point in the future by functions from PHPCSUtils.
This method will be tested via the
WordPress.Security.EscapeOutput
sniff (via pre-existing tests).ConstantsHelper::is_use_of_global_constant(): simplify/implement PHPCSUtils
The
$tokens_to_ignore
array was set up using token types (strings) instead of token constants as some of the tokens would not always be available in all supported PHP/PHPCS combinations.This is no longer needed now PHPCS 3.7.1 is the minimum supported PHPCS version.
This commit:
T_CLASS
,T_TRAIT
andT_INTERFACE
are replaced byTokens::$ooScopeTokens
, which also includes the PHP 8.1T_ENUM
token.T_DOUBLE_COLON
andT_OBJECT_OPERATOR
are replaced byCollections::objectOperators()
, which also includes the PHP 8.0T_NULLSAFE_OBJECT_OPERATOR
token.T_PUBLIC
,T_PROTECTED
andT_PRIVATE
are replaced byTokens::$scopeModifiers
.The PHPCompatibility standard has the same method and the method is expected to be moved at some point to PHPCSUtils.
PHPCompatibility also has dedicated tests for this method, so I'm not adding tests at this time for
T_ENUM
andT_NULLSAFE_OBJECT_OPERATOR
support.See: PHPCompatibility/PHPCompatibility#1439
ConstantsHelper::is_use_of_global_constant(): minor simplification
A non-inline HTML token will always have another non-empty token before it, if nothing else, the PHP open tag, so checking if
$prev
isfalse
is redundant.