Class: PHP_CodeSniffer_File
Source Location: /PHP_CodeSniffer-0.1.0/CodeSniffer/File.php
A PHP_CodeSniffer_File object represents a PHP source file and the tokens associated with it.
Author(s):
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
[line 130]
A PHP_CodeSniffer_File object represents a PHP source file and the tokens associated with it. 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, // openened 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 oposite. array(
'parenthesis_opener' => 34,
'parenthesis_closer' => 40,
);
Some tokens can "own" a set of parethesis. For example a T_FUNCTION token has parenthesis around its argument list. These tokens also have the parenthesis_opener and and parenthesis_closer indicies. Not all parethesis have owners, for example parenthesis used for arithmetic operations and function calls. The parenthesis tokens that have an owner have the following auxilery array indicies. array(
'parenthesis_opener' => 34,
'parenthesis_closer' => 40,
'parenthesis_owner' => 33,
);
Each token within a set of parenthesis also has an array indicy 'nested_parenthesis' which is an array of the left parenthesis => right parenthesis token positions. 'nested_parentheisis' => 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.
Method Detail
__construct (Constructor) [line 304]
PHP_CodeSniffer_File __construct(
string
$file, array
$listeners)
|
|
Constructs a PHP_CodeSniffer_File.
Parameters:
addError [line 549]
void addError(
string
$error, int
$stackPtr)
|
|
Adds an error to the error stack.
Parameters:
addTokenListener [line 326]
Adds a listener to the token stack that listens to the specific tokens. When PHP_CodeSniffer encounters on the the tokens specified in $tokens, it invokes the process method of the sniff.
Parameters:
addWarning [line 576]
void addWarning(
string
$warning, int
$stackPtr)
|
|
Adds an warning to the warning stack.
Parameters:
findNext [line 1413]
int findNext(
int|array
$types, int
$start, [int
$end = null], [boolean
$exclude = false], [string
$value = null])
|
|
Returns the position of the next specified token(s). If a value is specified, the next token of the specified type(s) containing the specified value will be returned. Returns false if no token can be found.
Parameters:
findPrevious [line 1349]
int findPrevious(
int|array
$types, int
$start, [int
$end = null], [boolean
$exclude = false], [string
$value = null])
|
|
Returns the position of the next specified token(s). If a value is specified, the next token of the specified type(s) containing the specified value will be returned. Returns false if no token can be found.
Parameters:
getDeclarationName [line 992]
string getDeclarationName(
int
$stackPtr)
|
|
Returns the declaration names for T_CLASS, T_INTERFACE and T_FUNCTION tokens.
Parameters:
getErrorCount [line 598]
Returns the number of errors raised.
getErrors [line 622]
Returns the errors raised from processing this file.
getFilename [line 646]
Returns the absolute filename of this file.
getMemberProperties [line 1213]
array getMemberProperties(
int
$stackPtr)
|
|
Returns the visibility and implementation properies of the class member variable found at the specified position in the stack. The format of the array is: array(
'scope' => 'public', // public private or protected
'is_static' => false, // true if the static keyword was found.
);
Parameters:
getMethodParameters [line 1028]
array() getMethodParameters(
int
$stackPtr)
|
|
Returns the method parameters for the specified T_FUNCTION token. Each parameter is in the following format: 0 => array(
'name' => '$var', // The variable name.
'is_array' => false, // An array hint was used.
'pass_by_reference' => false, // Passed by reference.
)
Parameters with default values have and additional array indice of 'default' with the value of the default as a string.
Parameters:
getMethodProperties [line 1126]
array getMethodProperties(
int
$stackPtr)
|
|
Returns the visibility and implementation properies of the method found at the specified position in the stack. The format of the array is: array(
'scope' => 'public', // public private or protected
'scope_specified' => true, // true is scope keyword was found.
'is_abstract' => false, // true if the abstract keyword was found.
'is_final' => false, // true if the final keyword was found.
'is_static' => false, // true if the static keyword was found.
);
Parameters:
getTokens [line 375]
Returns the token stack for this file.
getTokensAsString [line 1313]
string getTokensAsString(
int
$start, int
$length)
|
|
Returns the content of the tokens from the specified start position in the token stack for the specified legnth.
Parameters:
getValidScopeOpeners [line 975]
array(int) getValidScopeOpeners(
)
|
|
Returns the token types that are allowed to open scopes.
getWarningCount [line 610]
Returns the number of warnings raised.
getWarnings [line 634]
Returns the warnings raised from processing this file.
hasCondition [line 1462]
boolean hasCondition(
int
$stackPtr, int|array
$types)
|
|
Determine if the passed token has a condition of one of the passed types.
Parameters:
isReference [line 1280]
boolean isReference(
int
$stackPtr)
|
|
Determine if the passed token is a reference operator. Returns true if the specified token position represents a reference. Returns false if the token represents a bitwise operator.
Parameters:
removeTokenListener [line 351]
Removes a listener from listening from the specified toekns.
Parameters:
start [line 388]
Starts the stack traversal, alerting PHP_CodeSniffer_Sniff listeners when their listening tokens are encountered.
Documentation generated on Mon, 11 Mar 2019 14:44:37 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|
|