BCTokens
in package
Token arrays related utility methods.
PHPCS provides a number of static token arrays in the Tokens class. Some of these token arrays will not be available in older PHPCS versions. Some will not contain the same set of tokens across PHPCS versions.
This class is a compatibility layer to allow for retrieving these token arrays with a consistent token content across PHPCS versions. The one caveat is that the token constants do need to be available.
Recommended usage: Only use the methods in this class when needed. I.e. when your sniff unit tests indicate a PHPCS cross-version compatibility issue related to inconsistent token arrays.
All PHPCS token arrays are supported, though only a limited number of them are different across PHPCS versions.
The names of the PHPCS native token arrays translate one-on-one to the methods in this class:
PHP_CodeSniffer\Util\Tokens::$emptyTokens
=>PHPCSUtils\BackCompat\BCTokens::emptyTokens()
PHP_CodeSniffer\Util\Tokens::$operators
=>PHPCSUtils\BackCompat\BCTokens::operators()
- ... etc
The order of the tokens in the arrays may differ between the PHPCS native token arrays and the token arrays returned by this class.
Tags
Table of Contents
Methods
- __callStatic() : array<int|string, int|string>
- Handle calls to (undeclared) methods for token arrays which haven't received any changes since PHPCS 3.13.0.
- arithmeticTokens() : array<int|string, int|string>
- assignmentTokens() : array<int|string, int|string>
- Tokens that represent assignments.
- blockOpeners() : array<int|string, int|string>
- Tokens that open code blocks.
- booleanOperators() : array<int|string, int|string>
- bracketTokens() : array<int|string, int|string>
- castTokens() : array<int|string, int|string>
- commentTokens() : array<int|string, int|string>
- comparisonTokens() : array<int|string, int|string>
- contextSensitiveKeywords() : array<int|string, int|string>
- emptyTokens() : array<int|string, int|string>
- equalityTokens() : array<int|string, int|string>
- functionNameTokens() : array<int|string, int|string>
- Tokens that represent the names of called functions.
- heredocTokens() : array<int|string, int|string>
- includeTokens() : array<int|string, int|string>
- magicConstants() : array<int|string, int|string>
- methodPrefixes() : array<int|string, int|string>
- nameTokens() : array<int|string, int|string>
- Tokens used for "names", be it namespace, OO, function or constant names.
- ooScopeTokens() : array<int|string, int|string>
- operators() : array<int|string, int|string>
- parenthesisOpeners() : array<int|string, int|string>
- Token types that open parentheses.
- phpcsCommentTokens() : array<int|string, int|string>
- scopeModifiers() : array<int|string, int|string>
- scopeOpeners() : array<int|string, int|string>
- Tokens that are allowed to open scopes.
- stringTokens() : array<int|string, int|string>
- textStringTokens() : array<int|string, int|string>
Methods
__callStatic()
Handle calls to (undeclared) methods for token arrays which haven't received any changes since PHPCS 3.13.0.
public
static __callStatic(string $name, array<string|int, mixed> $args) : array<int|string, int|string>
Parameters
- $name : string
-
The name of the method which has been called.
- $args : array<string|int, mixed>
-
Any arguments passed to the method. Unused as none of the methods take arguments.
Tags
Return values
array<int|string, int|string> —Token array
arithmeticTokens()
public
static arithmeticTokens() : array<int|string, int|string>
Tokens that represent arithmetic operators.
Return values
array<int|string, int|string>assignmentTokens()
Tokens that represent assignments.
public
static assignmentTokens() : array<int|string, int|string>
Retrieve the PHPCS assignments tokens array in a cross-version compatible manner.
Changelog for the PHPCS native array:
- PHPCS 4.0.0: The JS specific
T_ZSR_EQUAL
token is no longer available and has been removed from the array.
Tags
Return values
array<int|string, int|string> —Token array.
blockOpeners()
Tokens that open code blocks.
public
static blockOpeners() : array<int|string, int|string>
Retrieve the PHPCS block opener tokens array in a cross-version compatible manner.
Changelog for the PHPCS native array:
- PHPCS 4.0.0: The JS specific
T_OBJECT
token is no longer available and has been removed from the array.
Tags
Return values
array<int|string, int|string> —Token array.
booleanOperators()
public
static booleanOperators() : array<int|string, int|string>
Tokens that perform boolean operations.
Return values
array<int|string, int|string>bracketTokens()
public
static bracketTokens() : array<int|string, int|string>
Tokens that represent brackets and parenthesis.
Return values
array<int|string, int|string>castTokens()
public
static castTokens() : array<int|string, int|string>
Tokens that represent type casting.
Return values
array<int|string, int|string>commentTokens()
public
static commentTokens() : array<int|string, int|string>
Tokens that are comments.
Return values
array<int|string, int|string>comparisonTokens()
public
static comparisonTokens() : array<int|string, int|string>
Tokens that represent comparison operator.
Return values
array<int|string, int|string>contextSensitiveKeywords()
public
static contextSensitiveKeywords() : array<int|string, int|string>
Tokens representing context sensitive keywords in PHP.
Return values
array<int|string, int|string>emptyTokens()
public
static emptyTokens() : array<int|string, int|string>
Tokens that don't represent code.
Return values
array<int|string, int|string>equalityTokens()
public
static equalityTokens() : array<int|string, int|string>
Tokens that represent equality comparisons.
Return values
array<int|string, int|string>functionNameTokens()
Tokens that represent the names of called functions.
public
static functionNameTokens() : array<int|string, int|string>
Retrieve the PHPCS function name tokens array in a cross-version compatible manner.
Changelog for the PHPCS native array:
- Introduced in PHPCS 2.3.3.
- PHPCS 4.0.0:
T_NAME_QUALIFIED
,T_NAME_FULLY_QUALIFIED
,T_NAME_RELATIVE
andT_ANON_CLASS
added to the array.
Tags
Return values
array<int|string, int|string> —Token array.
heredocTokens()
public
static heredocTokens() : array<int|string, int|string>
Tokens that make up a heredoc string.
Return values
array<int|string, int|string>includeTokens()
public
static includeTokens() : array<int|string, int|string>
Tokens that include files.
Return values
array<int|string, int|string>magicConstants()
public
static magicConstants() : array<int|string, int|string>
Tokens representing PHP magic constants.
Return values
array<int|string, int|string>methodPrefixes()
public
static methodPrefixes() : array<int|string, int|string>
Tokens that can prefix a method name.
Return values
array<int|string, int|string>nameTokens()
Tokens used for "names", be it namespace, OO, function or constant names.
public
static nameTokens() : array<int|string, int|string>
Retrieve the PHPCS name tokens array in a cross-version compatible manner.
Changelog for the PHPCS native array:
- Introduced in PHPCS 4.0.0.
Tags
Return values
array<int|string, int|string> —Token array.
ooScopeTokens()
public
static ooScopeTokens() : array<int|string, int|string>
Tokens that open class and object scopes.
Return values
array<int|string, int|string>operators()
public
static operators() : array<int|string, int|string>
Tokens that perform operations.
Return values
array<int|string, int|string>parenthesisOpeners()
Token types that open parentheses.
public
static parenthesisOpeners() : array<int|string, int|string>
Retrieve the PHPCS parenthesis openers tokens array in a cross-version compatible manner.
Changelog for the PHPCS native array:
- Introduced in PHPCS 0.0.5.
- PHPCS 4.0.0:
T_USE
(for closures),T_ISSET
,T_UNSET
,T_EMPTY
,T_EVAL
andT_EXIT
added to the array.
Important: While T_USE
, T_ISSET
, T_UNSET
, T_EMPTY
, T_EVAL
and T_EXIT
will be included
in the return value for this method, the associated parentheses will not have the 'parenthesis_owner'
index
set until PHPCS 4.0.0.
Use the Parentheses::getOwner() or Parentheses::hasOwner() methods
if you need to check for whether any of these tokens are a parentheses owner.
Tags
Return values
array<int|string, int|string> —Token array.
phpcsCommentTokens()
public
static phpcsCommentTokens() : array<int|string, int|string>
Tokens that are comments containing PHPCS instructions.
Return values
array<int|string, int|string>scopeModifiers()
public
static scopeModifiers() : array<int|string, int|string>
Tokens that represent scope modifiers.
Return values
array<int|string, int|string>scopeOpeners()
Tokens that are allowed to open scopes.
public
static scopeOpeners() : array<int|string, int|string>
Retrieve the PHPCS scope opener tokens array in a cross-version compatible manner.
Changelog for the PHPCS native array:
- PHPCS 4.0.0: The JS specific
T_PROPERTY
andT_OBJECT
tokens are no longer available and have been removed from the array.
Tags
Return values
array<int|string, int|string> —Token array.
stringTokens()
public
static stringTokens() : array<int|string, int|string>
Tokens that represent strings.
Note that T_STRING
s are NOT represented in this
list as this list is about text strings.
Return values
array<int|string, int|string>textStringTokens()
public
static textStringTokens() : array<int|string, int|string>
Tokens that represent text strings.