Token
in package
Representation of single token.
As a token prototype you should understand a single element generated by token_get_all. Also, this class exposes PHPStan types. (hint: string in those types shall ideally not be empty - yet we are not there yet).
Tags
Table of Contents
Methods
- __construct() : mixed
- equals() : bool
- Check if token is equal to given one.
- equalsAny() : bool
- Check if token is equal to one of given.
- getCastTokenKinds() : array<int, int>
- getClassyTokenKinds() : array<int, int>
- Get classy tokens kinds: T_ENUM, T_CLASS, T_INTERFACE and T_TRAIT.
- getContent() : string
- Get token's content.
- getId() : int|null
- Get token's id.
- getKeywords() : array<int, int>
- Generate array containing all keywords that exists in PHP version in use.
- getMagicConstants() : array<string|int, mixed>
- Generate array containing all predefined constants that exists in PHP version in use.
- getName() : null|non-empty-string
- Get token's name.
- getNameForId() : null|non-empty-string
- Get token's name.
- getObjectOperatorKinds() : array<int, int>
- Get object operator tokens kinds: T_OBJECT_OPERATOR and (if available) T_NULLSAFE_OBJECT_OPERATOR.
- getPrototype() : array{: int, : non-empty-string}|string
- isArray() : bool
- Check if token prototype is an array.
- isCast() : bool
- Check if token is one of type cast tokens.
- isClassy() : bool
- Check if token is one of classy tokens: T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM.
- isComment() : bool
- Check if token is one of comment tokens: T_COMMENT or T_DOC_COMMENT.
- isGivenKind() : bool
- Check if token is one of given kind.
- isKeyCaseSensitive() : bool
- A helper method used to find out whether a certain input token has to be case-sensitively matched.
- isKeyword() : bool
- Check if token is a keyword.
- isMagicConstant() : bool
- Returns if the token is of a Magic constants type.
- isNativeConstant() : bool
- Check if token is a native PHP constant: true, false or null.
- isObjectOperator() : bool
- Check if token is one of object operator tokens: T_OBJECT_OPERATOR or T_NULLSAFE_OBJECT_OPERATOR.
- isWhitespace() : bool
- Check if token is whitespace.
- toArray() : array{id: null|int, name: null|non-empty-string, content: string, isArray: bool, changed: bool}
- toJson() : non-empty-string
Methods
__construct()
public
__construct(_PhpTokenPrototype $token) : mixed
Parameters
- $token : _PhpTokenPrototype
-
token prototype
equals()
Check if token is equal to given one.
public
equals(_PhpTokenPrototypePartial|Token $other[, bool $caseSensitive = true ]) : bool
If tokens are arrays, then only keys defined in parameter token are checked.
Parameters
- $other : _PhpTokenPrototypePartial|Token
-
token or its prototype
- $caseSensitive : bool = true
-
perform a case sensitive comparison
Return values
boolequalsAny()
Check if token is equal to one of given.
public
equalsAny(array<int, _PhpTokenPrototypePartial|Token> $others[, bool $caseSensitive = true ]) : bool
Parameters
- $others : array<int, _PhpTokenPrototypePartial|Token>
-
array of tokens or token prototypes
- $caseSensitive : bool = true
-
perform a case sensitive comparison
Return values
boolgetCastTokenKinds()
public
static getCastTokenKinds() : array<int, int>
Return values
array<int, int>getClassyTokenKinds()
Get classy tokens kinds: T_ENUM, T_CLASS, T_INTERFACE and T_TRAIT.
public
static getClassyTokenKinds() : array<int, int>
Return values
array<int, int>getContent()
Get token's content.
public
getContent() : string
It shall be used only for getting the content of token, not for checking it against excepted value.
Return values
stringgetId()
Get token's id.
public
getId() : int|null
It shall be used only for getting the internal id of token, not for checking it against excepted value.
Return values
int|nullgetKeywords()
Generate array containing all keywords that exists in PHP version in use.
public
static getKeywords() : array<int, int>
Return values
array<int, int>getMagicConstants()
Generate array containing all predefined constants that exists in PHP version in use.
public
static getMagicConstants() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getName()
Get token's name.
public
getName() : null|non-empty-string
It shall be used only for getting the name of token, not for checking it against excepted value.
Return values
null|non-empty-string —token name
getNameForId()
Get token's name.
public
static getNameForId(int $id) : null|non-empty-string
It shall be used only for getting the name of token, not for checking it against excepted value.
Parameters
- $id : int
Return values
null|non-empty-string —token name
getObjectOperatorKinds()
Get object operator tokens kinds: T_OBJECT_OPERATOR and (if available) T_NULLSAFE_OBJECT_OPERATOR.
public
static getObjectOperatorKinds() : array<int, int>
Return values
array<int, int>getPrototype()
public
getPrototype() : array{: int, : non-empty-string}|string
Return values
array{: int, : non-empty-string}|stringisArray()
Check if token prototype is an array.
public
isArray() : bool
Tags
Return values
bool —is array
isCast()
Check if token is one of type cast tokens.
public
isCast() : bool
Tags
Return values
boolisClassy()
Check if token is one of classy tokens: T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM.
public
isClassy() : bool
Tags
Return values
boolisComment()
Check if token is one of comment tokens: T_COMMENT or T_DOC_COMMENT.
public
isComment() : bool
Tags
Return values
boolisGivenKind()
Check if token is one of given kind.
public
isGivenKind(int|array<int, int> $possibleKind) : bool
Parameters
- $possibleKind : int|array<int, int>
-
kind or array of kinds
Tags
Return values
boolisKeyCaseSensitive()
A helper method used to find out whether a certain input token has to be case-sensitively matched.
public
static isKeyCaseSensitive(array<int, bool>|bool $caseSensitive, int $key) : bool
Parameters
- $caseSensitive : array<int, bool>|bool
-
global case sensitiveness or an array of booleans, whose keys should match the ones used in $sequence. If any is missing, the default case-sensitive comparison is used
- $key : int
-
the key of the token that has to be looked up
Return values
boolisKeyword()
Check if token is a keyword.
public
isKeyword() : bool
Tags
Return values
boolisMagicConstant()
Returns if the token is of a Magic constants type.
public
isMagicConstant() : bool
Tags
Return values
boolisNativeConstant()
Check if token is a native PHP constant: true, false or null.
public
isNativeConstant() : bool
Tags
Return values
boolisObjectOperator()
Check if token is one of object operator tokens: T_OBJECT_OPERATOR or T_NULLSAFE_OBJECT_OPERATOR.
public
isObjectOperator() : bool
Tags
Return values
boolisWhitespace()
Check if token is whitespace.
public
isWhitespace([null|string $whitespaces = "
" ]) : bool
Parameters
- $whitespaces : null|string = " "
-
whitespace characters, default is " \t\n\r\0\x0B"
Return values
booltoArray()
public
toArray() : array{id: null|int, name: null|non-empty-string, content: string, isArray: bool, changed: bool}
Return values
array{id: null|int, name: null|non-empty-string, content: string, isArray: bool, changed: bool}toJson()
public
toJson() : non-empty-string