Class: PHP_CodeSniffer_File
Source Location: /PHP_CodeSniffer-0.9.0/CodeSniffer/File.php
A PHP_CodeSniffer_File object represents a PHP source file and the tokens associated with it.
Author(s):
Version:
Copyright:
- 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
[line 118]
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.
Class Variables
Method Detail
__construct (Constructor) [line 322]
PHP_CodeSniffer_File __construct(
string
$file, array
$listeners)
|
|
Constructs a PHP_CodeSniffer_File.
Parameters:
addError [line 649]
void addError(
string
$error, int
$stackPtr)
|
|
Adds an error to the error stack.
Parameters:
addTokenListener [line 355]
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 676]
void addWarning(
string
$warning, int
$stackPtr)
|
|
Adds an warning to the warning stack.
Parameters:
findFirstOnLine [line 1884]
int findFirstOnLine(
int|array
$types, int
$start, [bool
$exclude = false], [string
$value = null])
|
|
Returns the position of the first token on a line, matching given type. Returns false if no token can be found.
Parameters:
findNext [line 1822]
int findNext(
int|array
$types, int
$start, [int
$end = null], [bool
$exclude = false], [string
$value = null], [bool
$local = false])
|
|
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 1752]
int findPrevious(
int|array
$types, int
$start, [int
$end = null], [bool
$exclude = false], [string
$value = null], [bool
$local = false])
|
|
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 1378]
string getDeclarationName(
int
$stackPtr)
|
|
Returns the declaration names for T_CLASS, T_INTERFACE and T_FUNCTION tokens.
Parameters:
getErrorCount [line 698]
Returns the number of errors raised.
getErrors [line 722]
Returns the errors raised from processing this file.
getFilename [line 746]
Returns the absolute filename of this file.
getMemberProperties [line 1600]
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 1414]
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.
'pass_by_reference' => false, // Passed by reference.
'type_hint' => string, // Type hint for array or custom type
)
Parameters with default values have and additional array indice of 'default' with the value of the default as a string.
Parameters:
getMethodProperties [line 1513]
array getMethodProperties(
int
$stackPtr)
|
|
Returns the visibility and implementation properies of a method. 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 404]
Returns the token stack for this file.
getTokensAsString [line 1713]
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 1361]
array(int) getValidScopeOpeners(
)
|
|
Returns the token types that are allowed to open scopes.
getWarningCount [line 710]
Returns the number of warnings raised.
getWarnings [line 734]
Returns the warnings raised from processing this file.
hasCondition [line 1935]
boolean hasCondition(
int
$stackPtr, int|array
$types)
|
|
Determine if the passed token has a condition of one of the passed types.
Parameters:
isReference [line 1663]
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 380]
Removes a listener from listening from the specified tokens.
Parameters:
start [line 416]
Starts the stack traversal and tells listeners when tokens are found.
Documentation generated on Mon, 11 Mar 2019 15:09:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|
|