PHPCSUtils

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
since
1.0.0
since
1.0.0-alpha4

Dropped support for PHPCS < 3.7.1.

Table of Contents

__callStatic()  : array<string|int, mixed>
Handle calls to (undeclared) methods for token arrays which haven't received any changes since PHPCS 3.7.1.
arithmeticTokens()  : array<string|int, mixed>
assignmentTokens()  : array<string|int, mixed>
blockOpeners()  : array<string|int, mixed>
booleanOperators()  : array<string|int, mixed>
bracketTokens()  : array<string|int, mixed>
castTokens()  : array<string|int, mixed>
commentTokens()  : array<string|int, mixed>
comparisonTokens()  : array<string|int, mixed>
contextSensitiveKeywords()  : array<string|int, mixed>
emptyTokens()  : array<string|int, mixed>
equalityTokens()  : array<string|int, mixed>
functionNameTokens()  : array<string|int, mixed>
Tokens that represent the names of called functions.
heredocTokens()  : array<string|int, mixed>
includeTokens()  : array<string|int, mixed>
magicConstants()  : array<string|int, mixed>
methodPrefixes()  : array<string|int, mixed>
ooScopeTokens()  : array<string|int, mixed>
operators()  : array<string|int, mixed>
parenthesisOpeners()  : array<string|int, mixed>
phpcsCommentTokens()  : array<string|int, mixed>
scopeModifiers()  : array<string|int, mixed>
scopeOpeners()  : array<string|int, mixed>
stringTokens()  : array<string|int, mixed>
textStringTokens()  : array<string|int, mixed>

Methods

__callStatic()

Handle calls to (undeclared) methods for token arrays which haven't received any changes since PHPCS 3.7.1.

public static __callStatic(string $name, array<string|int, mixed> $args) : array<string|int, mixed>
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
since
1.0.0
throws
InvalidTokenArray

When an invalid token array is requested.

Return values
array<string|int, mixed>

<int|string> => <int|string> Token array

arithmeticTokens()

public static arithmeticTokens() : array<string|int, mixed>

Tokens that represent arithmetic operators.

Return values
array<string|int, mixed>

assignmentTokens()

public static assignmentTokens() : array<string|int, mixed>

Tokens that represent assignments.

Return values
array<string|int, mixed>

blockOpeners()

public static blockOpeners() : array<string|int, mixed>

Tokens that open code blocks.

Return values
array<string|int, mixed>

booleanOperators()

public static booleanOperators() : array<string|int, mixed>

Tokens that perform boolean operations.

Return values
array<string|int, mixed>

bracketTokens()

public static bracketTokens() : array<string|int, mixed>

Tokens that represent brackets and parenthesis.

Return values
array<string|int, mixed>

castTokens()

public static castTokens() : array<string|int, mixed>

Tokens that represent type casting.

Return values
array<string|int, mixed>

commentTokens()

public static commentTokens() : array<string|int, mixed>

Tokens that are comments.

Return values
array<string|int, mixed>

comparisonTokens()

public static comparisonTokens() : array<string|int, mixed>

Tokens that represent comparison operator.

Return values
array<string|int, mixed>

contextSensitiveKeywords()

public static contextSensitiveKeywords() : array<string|int, mixed>

Tokens representing context sensitive keywords in PHP.

Return values
array<string|int, mixed>

emptyTokens()

public static emptyTokens() : array<string|int, mixed>

Tokens that don't represent code.

Return values
array<string|int, mixed>

equalityTokens()

public static equalityTokens() : array<string|int, mixed>

Tokens that represent equality comparisons.

Return values
array<string|int, mixed>

functionNameTokens()

Tokens that represent the names of called functions.

public static functionNameTokens() : array<string|int, mixed>

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 3.7.2: T_PARENT added to the array.
  • PHPCS 4.0.0: T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED and T_NAME_RELATIVE added to the array.
Tags
see
Tokens::$functionNameTokens

Original array.

since
1.0.0
Return values
array<string|int, mixed>

<int|string> => <int|string> Token array.

heredocTokens()

public static heredocTokens() : array<string|int, mixed>

Tokens that make up a heredoc string.

Return values
array<string|int, mixed>

includeTokens()

public static includeTokens() : array<string|int, mixed>

Tokens that include files.

Return values
array<string|int, mixed>

magicConstants()

public static magicConstants() : array<string|int, mixed>

Tokens representing PHP magic constants.

Return values
array<string|int, mixed>

methodPrefixes()

public static methodPrefixes() : array<string|int, mixed>

Tokens that can prefix a method name.

Return values
array<string|int, mixed>

ooScopeTokens()

public static ooScopeTokens() : array<string|int, mixed>

Tokens that open class and object scopes.

Return values
array<string|int, mixed>

operators()

public static operators() : array<string|int, mixed>

Tokens that perform operations.

Return values
array<string|int, mixed>

parenthesisOpeners()

public static parenthesisOpeners() : array<string|int, mixed>

Token types that open parenthesis.

Return values
array<string|int, mixed>

phpcsCommentTokens()

public static phpcsCommentTokens() : array<string|int, mixed>

Tokens that are comments containing PHPCS instructions.

Return values
array<string|int, mixed>

scopeModifiers()

public static scopeModifiers() : array<string|int, mixed>

Tokens that represent scope modifiers.

Return values
array<string|int, mixed>

scopeOpeners()

public static scopeOpeners() : array<string|int, mixed>

Tokens that are allowed to open scopes.

Return values
array<string|int, mixed>

stringTokens()

public static stringTokens() : array<string|int, mixed>

Tokens that represent strings. Note that T_STRINGs are NOT represented in this list as this list is about text strings.

Return values
array<string|int, mixed>

textStringTokens()

public static textStringTokens() : array<string|int, mixed>

Tokens that represent text strings.

Return values
array<string|int, mixed>

Search results