It provides a means for traversing the token stack, along with
other token related operations. If a PHP_CodeSniffer_Sniff finds and error or
warning within a PHP_CodeSniffer_File, you can raise an error using the
addError() or addWarning() methods.
Token Information
Each token within the stack contains information about itself:
array(
'code' => 301, // the token type code (see token_get_all())
'content' => 'if', // the token content
'type' => 'T_IF', // the token name
'line' => 56, // the line number when the token is located
'column' => 12, // the column in the line where this token
starts (starts from 1)
'level' => 2 // the depth a token is within the scopes open
'conditions' => array( // a list of scope condition token
positions => codes that
2 => 50, // opened the scopes that this token exists
9 => 353, // in (see conditional tokens section below)
),
);
Conditional Tokens
In addition to the standard token fields, conditions contain information to
determine where their scope begins and ends:
array(
'scope_condition' => 38, // the token position of the condition
'scope_opener' => 41, // the token position that started the scope
'scope_closer' => 70, // the token position that ended the scope
);
The condition, the scope opener and the scope closer each contain this
information.
Parenthesis Tokens
Each parenthesis token (T_OPEN_PARENTHESIS and T_CLOSE_PARENTHESIS) has a
reference to their opening and closing parenthesis, one being itself, the
other being its opposite.
array(
'parenthesis_opener' => 34,
'parenthesis_closer' => 40,
);
Some tokens can "own" a set of parenthesis. For example a T_FUNCTION token
has parenthesis around its argument list. These tokens also have the
parenthesis_opener and and parenthesis_closer indices. Not all parenthesis
have owners, for example parenthesis used for arithmetic operations and
function calls. The parenthesis tokens that have an owner have the following
auxiliary array indices.
array(
'parenthesis_opener' => 34,
'parenthesis_closer' => 40,
'parenthesis_owner' => 33,
);
Each token within a set of parenthesis also has an array index
'nested_parenthesis' which is an array of the
left parenthesis => right parenthesis token positions.
'nested_parenthesis' => array(
12 => 15
11 => 14
);
Extended Tokens
PHP_CodeSniffer extends and augments some of the tokens created by
token_get_all(). A full list of these tokens can be seen in the
Tokens.php file.