## BCTokens

BCTokens.php : 60

Token arrays related utility methods.

PHPCS provides a number of static token arrays in the \PHP_CodeSniffer\Util\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

### Table of Contents

__callStatic() : array
  Handle calls to (undeclared) methods for token arrays which haven't received any changes since PHPCS 2.6.0.
arithmeticTokens() : array
  Tokens that represent arithmetic operators.
assignmentTokens() : array
  Tokens that represent assignment operators.
blockOpeners() : array
booleanOperators() : array
bracketTokens() : array
castTokens() : array
commentTokens() : array
comparisonTokens() : array
  Tokens that represent comparison operators.
emptyTokens() : array
equalityTokens() : array
functionNameTokens() : array
  Tokens that represent the names of called functions.
heredocTokens() : array
includeTokens() : array
methodPrefixes() : array
ooScopeTokens() : array
  Tokens that open class and object scopes.
operators() : array
  Tokens that perform operations.
parenthesisOpeners() : array
  Token types that open parentheses.
phpcsCommentTokens() : array
  Tokens that are comments containing PHPCS instructions.
scopeModifiers() : array
scopeOpeners() : array
stringTokens() : array
textStringTokens() : array
  Tokens that represent text strings.

### Methods

#### __callStatic()

BCTokens.php : 122

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

`public static __callStatic(string $name, array $args) : array`

##### Parameters

$name : string

  The name of the method which has been called.

$args : array

  Any arguments passed to the method. Unused as none of the methods take arguments.

##### Tags

since
  1.0.0

##### Return values

array —

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

#### arithmeticTokens()

BCTokens.php : 215

Tokens that represent arithmetic operators.

`public static arithmeticTokens() : array`

Retrieve the PHPCS arithmetic tokens array in a cross-version compatible manner.

Changelog for the PHPCS native array:

- Introduced in PHPCS 0.5.0.
- PHPCS 2.9.0: The PHP 5.6 `T_POW` token was added to the array. The `T_POW` token was introduced in PHPCS 2.4.0.

##### Tags

see
  Tokens::$arithmeticTokens

  Original array.

since
  1.0.0

##### Return values

array —

<int|string> => <int|string> Token array or an empty array for PHPCS versions in which the PHPCS native comment tokens did not exist yet.

#### assignmentTokens()

BCTokens.php : 150

Tokens that represent assignment operators.

`public static assignmentTokens() : array`

Retrieve the PHPCS assignment tokens array in a cross-version compatible manner.

Changelog for the PHPCS native array:

- Introduced in PHPCS 0.0.5.
- PHPCS 2.9.0: The PHP 7.4 `T_COALESCE_EQUAL` token was added to the array. The `T_COALESCE_EQUAL` token was introduced in PHPCS 2.8.1.
- PHPCS 3.2.0: The JS `T_ZSR_EQUAL` token was added to the array. The `T_ZSR_EQUAL` token was introduced in PHPCS 2.8.0.

##### Tags

see
  Tokens::$assignmentTokens

  Original array.

since
  1.0.0

##### Return values

array —

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

#### blockOpeners()

BCTokens.php : 0
`public static blockOpeners() : array`

Tokens that open code blocks.

##### Return values

array —

#### booleanOperators()

BCTokens.php : 0
`public static booleanOperators() : array`

Tokens that perform boolean operations.

##### Return values

array —

#### bracketTokens()

BCTokens.php : 0
`public static bracketTokens() : array`

Tokens that represent brackets and parenthesis.

##### Return values

array —

#### castTokens()

BCTokens.php : 0
`public static castTokens() : array`

Tokens that represent type casting.

##### Return values

array —

#### commentTokens()

BCTokens.php : 0
`public static commentTokens() : array`

Tokens that are comments.

##### Return values

array —

#### comparisonTokens()

BCTokens.php : 187

Tokens that represent comparison operators.

`public static comparisonTokens() : array`

Retrieve the PHPCS comparison tokens array in a cross-version compatible manner.

Changelog for the PHPCS native array:

- Introduced in PHPCS 0.5.0.
- PHPCS 2.9.0: The PHP 7.0 `T_COALESCE` token was added to the array. The `T_COALESCE` token was introduced in PHPCS 2.6.1.
- PHPCS 2.9.0: The PHP 7.0 `T_SPACESHIP` token was added to the array. The `T_SPACESHIP` token was introduced in PHPCS 2.5.1.

##### Tags

see
  Tokens::$comparisonTokens

  Original array.

since
  1.0.0

##### Return values

array —

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

#### emptyTokens()

BCTokens.php : 0
`public static emptyTokens() : array`

Tokens that don't represent code.

##### Return values

array —

#### equalityTokens()

BCTokens.php : 0
`public static equalityTokens() : array`

Tokens that represent equality comparisons.

##### Return values

array —

#### functionNameTokens()

BCTokens.php : 367

Tokens that represent the names of called functions.

`public static functionNameTokens() : array`

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.1.0: `T_SELF` and `T_STATIC` added to the array.

##### Tags

see
  Tokens::$functionNameTokens

  Original array.

since
  1.0.0

##### Return values

array —

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

#### heredocTokens()

BCTokens.php : 0
`public static heredocTokens() : array`

Tokens that make up a heredoc string.

##### Return values

array —

#### includeTokens()

BCTokens.php : 0
`public static includeTokens() : array`

Tokens that include files.

##### Return values

array —

#### methodPrefixes()

BCTokens.php : 0
`public static methodPrefixes() : array`

Tokens that can prefix a method name.

##### Return values

array —

#### ooScopeTokens()

BCTokens.php : 390

Tokens that open class and object scopes.

`public static ooScopeTokens() : array`

Retrieve the OO scope tokens array in a cross-version compatible manner.

Changelog for the PHPCS native array:

- Introduced in PHPCS 3.1.0.

##### Tags

see
  Tokens::$ooScopeTokens

  Original array.

since
  1.0.0

##### Return values

array —

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

#### operators()

BCTokens.php : 238

Tokens that perform operations.

`public static operators() : array`

Retrieve the PHPCS operator tokens array in a cross-version compatible manner.

Changelog for the PHPCS native array:

- Introduced in PHPCS 0.0.5.
- PHPCS 2.6.1: The PHP 7.0 `T_COALESCE` token was backfilled and added to the array.
- PHPCS 2.8.1: The PHP 7.4 `T_COALESCE_EQUAL` token was backfilled and (incorrectly) added to the array.
- PHPCS 2.9.0: The `T_COALESCE_EQUAL` token was removed from the array.

##### Tags

see
  Tokens::$operators

  Original array.

since
  1.0.0

##### Return values

array —

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

#### parenthesisOpeners()

BCTokens.php : 281

Token types that open parentheses.

`public static parenthesisOpeners() : array`

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 3.5.0: `T_LIST` and `T_ANON_CLASS` added to the array.

Note: While `T_LIST` and `T_ANON_CLASS` will be included in the return value for this method, the associated parentheses will not have the `'parenthesis_owner'` index set until PHPCS 3.5.0. Use the \PHPCSUtils\Utils\Parentheses::getOwner() or \PHPCSUtils\Utils\Parentheses::hasOwner() methods if you need to check for a `T_LIST` or `T_ANON_CLASS` parentheses owner.

##### Tags

see
  Tokens::$parenthesisOpeners

  Original array.

see
  Parentheses

  Class holding utility methods for working with the `'parenthesis_...'` index keys in a token array.

since
  1.0.0

##### Return values

array —

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

#### phpcsCommentTokens()

BCTokens.php : 307

Tokens that are comments containing PHPCS instructions.

`public static phpcsCommentTokens() : array`

Retrieve the PHPCS comment tokens array in a cross-version compatible manner.

Changelog for the PHPCS native array:

- Introduced in PHPCS 3.2.3. The PHPCS comment tokens, however, were introduced in PHPCS 3.2.0.

##### Tags

see
  Tokens::$phpcsCommentTokens

  Original array.

since
  1.0.0

##### Return values

array —

<string> => <string> Token array or an empty array for PHPCS versions in which the PHPCS native annotation tokens did not exist yet.

#### scopeModifiers()

BCTokens.php : 0
`public static scopeModifiers() : array`

Tokens that represent scope modifiers.

##### Return values

array —

#### scopeOpeners()

BCTokens.php : 0
`public static scopeOpeners() : array`

Tokens that are allowed to open scopes.

##### Return values

array —

#### stringTokens()

BCTokens.php : 0
`public static stringTokens() : array`

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

##### Return values

array —

#### textStringTokens()

BCTokens.php : 343

Tokens that represent text strings.

`public static textStringTokens() : array`

Retrieve the PHPCS text string tokens array in a cross-version compatible manner.

Changelog for the PHPCS native array:

- Introduced in PHPCS 2.9.0.

##### Tags

see
  Tokens::$textStringTokens

  Original array.

since
  1.0.0

##### Return values

array —

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

## Search results