Collections
Collections of related tokens as often used and needed for sniffs.
These are additional "token groups" to compliment the ones available through the PHPCS native \PHP_CodeSniffer\Util\Tokens class.
Tags
Table of Contents
- $alternativeControlStructureSyntaxCloserTokens : array
- Alternative control structure syntax closer keyword tokens.
- $alternativeControlStructureSyntaxTokens : array
- Control structures which can use the alternative control structure syntax.
- $arrayTokens : array
- Tokens which are used to create arrays.
- $arrayTokensBC : array
- Tokens which are used to create arrays.
- $classModifierKeywords : array
- Modifier keywords which can be used for a class declaration.
- $closedScopes : array
- List of tokens which represent "closed" scopes.
- $controlStructureTokens : array
- Control structure tokens.
- $incrementDecrementOperators : array
- Increment/decrement operator tokens.
- $listTokens : array
- Tokens which are used to create lists.
- $listTokensBC : array
- Tokens which are used to create lists.
- $magicConstants : array
- Tokens for the PHP magic constants.
- $namespaceDeclarationClosers : array
- List of tokens which can end a namespace declaration statement.
- $objectOperators : array
- Object operators.
- $OOCanExtend : array
- OO structures which can use the "extends" keyword.
- $OOCanImplement : array
- OO structures which can use the "implements" keyword.
- $OOConstantScopes : array
- OO scopes in which constants can be declared.
- $OOHierarchyKeywords : array
- Tokens types used for "forwarding" calls within OO structures.
- $OONameTokens : array
- Tokens types which can be encountered in the fully/partially qualified name of an OO structure.
- $OOPropertyScopes : array
- OO scopes in which properties can be declared.
- $parameterTypeTokens : array
- Token types which can be encountered in a parameter type declaration.
- $propertyModifierKeywords : array
- Modifier keywords which can be used for a property declaration.
- $propertyTypeTokens : array
- Token types which can be encountered in a property type declaration.
- $returnTypeTokens : array
- Token types which can be encountered in a return type declaration.
- $shortArrayTokens : array
- Tokens which are used for short arrays.
- $shortArrayTokensBC : array
- Tokens which are used for short arrays.
- $shortListTokens : array
- Tokens which are used for short lists.
- $shortListTokensBC : array
- Tokens which are used for short lists.
- $textStingStartTokens : array
- Tokens which can start a - potentially multi-line - text string.
- arrowFunctionTokensBC() : array
- Tokens which can represent the arrow function keyword.
- functionDeclarationTokens() : array
- Tokens which can represent a keyword which starts a function declaration.
- functionDeclarationTokensBC() : array
- Tokens which can represent a keyword which starts a function declaration.
- parameterTypeTokensBC() : array
- Token types which can be encountered in a parameter type declaration (cross-version).
- propertyTypeTokensBC() : array
- Token types which can be encountered in a property type declaration (cross-version).
- returnTypeTokensBC() : array
- Token types which can be encountered in a return type declaration (cross-version).
Properties
$alternativeControlStructureSyntaxCloserTokens
Alternative control structure syntax closer keyword tokens.
public
static array
$alternativeControlStructureSyntaxCloserTokens
= [T_ENDIF => T_ENDIF, T_ENDFOR => T_ENDFOR, T_ENDFOREACH => T_ENDFOREACH, T_ENDWHILE => T_ENDWHILE, T_ENDSWITCH => T_ENDSWITCH, T_ENDDECLARE => T_ENDDECLARE]
Tags
$alternativeControlStructureSyntaxTokens
Control structures which can use the alternative control structure syntax.
public
static array
$alternativeControlStructureSyntaxTokens
= [T_IF => T_IF, T_ELSEIF => T_ELSEIF, T_ELSE => T_ELSE, T_FOR => T_FOR, T_FOREACH => T_FOREACH, T_SWITCH => T_SWITCH, T_WHILE => T_WHILE, T_DECLARE => T_DECLARE]
Tags
$arrayTokens
Tokens which are used to create arrays.
public
static array
$arrayTokens
= [T_ARRAY => T_ARRAY, T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY]
Tags
$arrayTokensBC
Tokens which are used to create arrays.
public
static array
$arrayTokensBC
= [T_ARRAY => T_ARRAY, T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY, T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET, T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET]
List which is backward-compatible with PHPCS < 3.3.0. Should only be used selectively.
Tags
$classModifierKeywords
Modifier keywords which can be used for a class declaration.
public
static array
$classModifierKeywords
= [T_FINAL => T_FINAL, T_ABSTRACT => T_ABSTRACT]
Tags
$closedScopes
List of tokens which represent "closed" scopes.
public
static array
$closedScopes
= [T_CLASS => T_CLASS, T_ANON_CLASS => T_ANON_CLASS, T_INTERFACE => T_INTERFACE, T_TRAIT => T_TRAIT, T_FUNCTION => T_FUNCTION, T_CLOSURE => T_CLOSURE]
I.e. anything declared within that scope - except for other closed scopes - is outside of the global namespace.
This list doesn't contain the T_NAMESPACE
token on purpose as variables declared
within a namespace scope are still global and not limited to that namespace.
Tags
$controlStructureTokens
Control structure tokens.
public
static array
$controlStructureTokens
= [T_IF => T_IF, T_ELSEIF => T_ELSEIF, T_ELSE => T_ELSE, T_FOR => T_FOR, T_FOREACH => T_FOREACH, T_SWITCH => T_SWITCH, T_DO => T_DO, T_WHILE => T_WHILE, T_DECLARE => T_DECLARE]
Tags
$incrementDecrementOperators
Increment/decrement operator tokens.
public
static array
$incrementDecrementOperators
= [T_DEC => T_DEC, T_INC => T_INC]
Tags
$listTokens
Tokens which are used to create lists.
public
static array
$listTokens
= [T_LIST => T_LIST, T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY]
Tags
$listTokensBC
Tokens which are used to create lists.
public
static array
$listTokensBC
= [T_LIST => T_LIST, T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY, T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET, T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET]
List which is backward-compatible with PHPCS < 3.3.0. Should only be used selectively.
Tags
$magicConstants
Tokens for the PHP magic constants.
public
static array
$magicConstants
= [T_CLASS_C => T_CLASS_C, T_DIR => T_DIR, T_FILE => T_FILE, T_FUNC_C => T_FUNC_C, T_LINE => T_LINE, T_METHOD_C => T_METHOD_C, T_NS_C => T_NS_C, T_TRAIT_C => T_TRAIT_C]
Tags
$namespaceDeclarationClosers
List of tokens which can end a namespace declaration statement.
public
static array
$namespaceDeclarationClosers
= [T_SEMICOLON => T_SEMICOLON, T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, T_CLOSE_TAG => T_CLOSE_TAG]
Tags
$objectOperators
Object operators.
public
static array
$objectOperators
= [T_OBJECT_OPERATOR => T_OBJECT_OPERATOR, T_DOUBLE_COLON => T_DOUBLE_COLON]
Tags
$OOCanExtend
OO structures which can use the "extends" keyword.
public
static array
$OOCanExtend
= [T_CLASS => T_CLASS, T_ANON_CLASS => T_ANON_CLASS, T_INTERFACE => T_INTERFACE]
Tags
$OOCanImplement
OO structures which can use the "implements" keyword.
public
static array
$OOCanImplement
= [T_CLASS => T_CLASS, T_ANON_CLASS => T_ANON_CLASS]
Tags
$OOConstantScopes
OO scopes in which constants can be declared.
public
static array
$OOConstantScopes
= [T_CLASS => T_CLASS, T_ANON_CLASS => T_ANON_CLASS, T_INTERFACE => T_INTERFACE]
Note: traits can not declare constants.
Tags
$OOHierarchyKeywords
Tokens types used for "forwarding" calls within OO structures.
public
static array
$OOHierarchyKeywords
= [T_PARENT => T_PARENT, T_SELF => T_SELF, T_STATIC => T_STATIC]
Tags
$OONameTokens
Tokens types which can be encountered in the fully/partially qualified name of an OO structure.
public
static array
$OONameTokens
= [T_NS_SEPARATOR => T_NS_SEPARATOR, T_STRING => T_STRING, T_NAMESPACE => T_NAMESPACE]
Example:
echo namespace\Sub\ClassName::method();
Tags
$OOPropertyScopes
OO scopes in which properties can be declared.
public
static array
$OOPropertyScopes
= [T_CLASS => T_CLASS, T_ANON_CLASS => T_ANON_CLASS, T_TRAIT => T_TRAIT]
Note: interfaces can not declare properties.
Tags
$parameterTypeTokens
Token types which can be encountered in a parameter type declaration.
public
static array
$parameterTypeTokens
= [T_CALLABLE => T_CALLABLE, T_SELF => T_SELF, T_PARENT => T_PARENT, T_STRING => T_STRING, T_NS_SEPARATOR => T_NS_SEPARATOR]
Sister-property to the \PHPCSUtils\Tokens\Collections::parameterTypeTokensBC() method. The property supports PHPCS 3.3.0 and up. The method supports PHPCS 2.6.0 and up.
Notable difference:
- The method will include the
T_ARRAY_HINT
token when used with PHPCS 2.x and 3.x. This token constant will no longer exist in PHPCS 4.x.
It is recommended to use the property instead of the method if a standard supports does not need to support PHPCS < 3.3.0.
Tags
$propertyModifierKeywords
Modifier keywords which can be used for a property declaration.
public
static array
$propertyModifierKeywords
= [T_PUBLIC => T_PUBLIC, T_PRIVATE => T_PRIVATE, T_PROTECTED => T_PROTECTED, T_STATIC => T_STATIC, T_VAR => T_VAR]
Tags
$propertyTypeTokens
Token types which can be encountered in a property type declaration.
public
static array
$propertyTypeTokens
= [T_CALLABLE => T_CALLABLE, T_SELF => T_SELF, T_PARENT => T_PARENT, T_STRING => T_STRING, T_NS_SEPARATOR => T_NS_SEPARATOR]
Sister-property to the \PHPCSUtils\Tokens\Collections::propertyTypeTokensBC() method. The property supports PHPCS 3.3.0 and up. The method supports PHPCS 2.6.0 and up.
Notable difference:
- The method will include the
T_ARRAY_HINT
token when used with PHPCS 2.x and 3.x. This token constant will no longer exist in PHPCS 4.x.
It is recommended to use the property instead of the method if a standard supports does not need to support PHPCS < 3.3.0.
Tags
$returnTypeTokens
Token types which can be encountered in a return type declaration.
public
static array
$returnTypeTokens
= [T_STRING => T_STRING, T_CALLABLE => T_CALLABLE, T_SELF => T_SELF, T_PARENT => T_PARENT, T_STATIC => T_STATIC, T_NS_SEPARATOR => T_NS_SEPARATOR]
Sister-property to the \PHPCSUtils\Tokens\Collections::returnTypeTokensBC() method. The property supports PHPCS 3.5.4 and up. The method supports PHPCS 2.6.0 and up.
Notable differences:
- The method will include the
T_ARRAY_HINT
and theT_RETURN_TYPE
tokens when used with PHPCS 2.x and 3.x. These token constants will no longer exist in PHPCS 4.x. - The method will include the
T_ARRAY
token which is needed for select arrow functions in PHPCS < 3.5.4.
It is recommended to use the property instead of the method if a standard supports does not need to support PHPCS < 3.5.4.
Tags
$shortArrayTokens
Tokens which are used for short arrays.
public
static array
$shortArrayTokens
= [T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY]
Tags
$shortArrayTokensBC
Tokens which are used for short arrays.
public
static array
$shortArrayTokensBC
= [T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY, T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET, T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET]
List which is backward-compatible with PHPCS < 3.3.0. Should only be used selectively.
Tags
$shortListTokens
Tokens which are used for short lists.
public
static array
$shortListTokens
= [T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY]
Tags
$shortListTokensBC
Tokens which are used for short lists.
public
static array
$shortListTokensBC
= [T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY, T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET, T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET]
List which is backward-compatible with PHPCS < 3.3.0. Should only be used selectively.
Tags
$textStingStartTokens
Tokens which can start a - potentially multi-line - text string.
public
static array
$textStingStartTokens
= [T_START_HEREDOC => T_START_HEREDOC, T_START_NOWDOC => T_START_NOWDOC, T_CONSTANT_ENCAPSED_STRING => T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING => T_DOUBLE_QUOTED_STRING]
Tags
Methods
arrowFunctionTokensBC()
Tokens which can represent the arrow function keyword.
public
static arrowFunctionTokensBC() : array
Note: this is a method, not a property as the T_FN
token for arrow functions may not exist.
Tags
Return values
array —<int|string> => <int|string>
functionDeclarationTokens()
Tokens which can represent a keyword which starts a function declaration.
public
static functionDeclarationTokens() : array
Note: this is a method, not a property as the T_FN
token for arrow functions may not exist.
Sister-method to the \PHPCSUtils\Tokens\Collections::functionDeclarationTokensBC() method. This method supports PHPCS 3.5.3 and up. The \PHPCSUtils\Tokens\Collections::functionDeclarationTokensBC() method supports PHPCS 2.6.0 and up.
Tags
Return values
array —<int|string> => <int|string>
functionDeclarationTokensBC()
Tokens which can represent a keyword which starts a function declaration.
public
static functionDeclarationTokensBC() : array
Note: this is a method, not a property as the T_FN
token for arrow functions may not exist.
Sister-method to the \PHPCSUtils\Tokens\Collections::functionDeclarationTokens() method. The \PHPCSUtils\Tokens\Collections::functionDeclarationTokens() method supports PHPCS 3.5.3 and up. This method supports PHPCS 2.6.0 and up.
Notable difference:
- This method accounts for when the
T_FN
token doesn't exist.
Note: if this method is used, the \PHPCSUtils\Utils\FunctionDeclarations::isArrowFunction() method needs to be used on arrow function tokens to verify whether it really is an arrow function declaration or not.
It is recommended to use the \PHPCSUtils\Tokens\Collections::functionDeclarationTokens() method instead of this method if a standard supports does not need to support PHPCS < 3.5.3.
Tags
Return values
array —<int|string> => <int|string>
parameterTypeTokensBC()
Token types which can be encountered in a parameter type declaration (cross-version).
public
static parameterTypeTokensBC() : array
Sister-method to the \PHPCSUtils\Tokens\Collections::$parameterTypeTokens property. The property supports PHPCS 3.3.0 and up. The method supports PHPCS 2.6.0 and up.
Notable difference:
- The method will include the
T_ARRAY_HINT
token when used with PHPCS 2.x and 3.x. This token constant will no longer exist in PHPCS 4.x.
It is recommended to use the property instead of the method if a standard supports does not need to support PHPCS < 3.3.0.
Tags
Return values
array —<int|string> => <int|string>
propertyTypeTokensBC()
Token types which can be encountered in a property type declaration (cross-version).
public
static propertyTypeTokensBC() : array
Sister-method to the \PHPCSUtils\Tokens\Collections::$propertyTypeTokens property. The property supports PHPCS 3.3.0 and up. The method supports PHPCS 2.6.0 and up.
Notable difference:
- The method will include the
T_ARRAY_HINT
token when used with PHPCS 2.x and 3.x. This token constant will no longer exist in PHPCS 4.x.
It is recommended to use the property instead of the method if a standard supports does not need to support PHPCS < 3.3.0.
Tags
Return values
array —<int|string> => <int|string>
returnTypeTokensBC()
Token types which can be encountered in a return type declaration (cross-version).
public
static returnTypeTokensBC() : array
Sister-property to the \PHPCSUtils\Tokens\Collections::returnTypeTokensBC() method. The property supports PHPCS 3.5.4 and up. The method supports PHPCS 2.6.0 and up.
Notable differences:
- The method will include the
T_ARRAY_HINT
and theT_RETURN_TYPE
tokens when used with PHPCS 2.x and 3.x. These token constants will no longer exist in PHPCS 4.x. - The method will include the
T_ARRAY
token which is needed for select arrow functions in PHPCS < 3.5.4.
It is recommended to use the property instead of the method if a standard supports does not need to support PHPCS < 3.5.4.
Tags
Return values
array —<int|string> => <int|string>