Class: PHP_CodeSniffer_File
Source Location: /PHP_CodeSniffer-2.7.1/CodeSniffer/File.php
A PHP_CodeSniffer_File object represents a PHP source file and the tokens associated with it.
Author(s):
Version:
Copyright:
- 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
[line 117]
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, // 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.
Class Variables
Method Detail
__construct (Constructor) [line 303]
PHP_CodeSniffer_File __construct(
string
$file, array
$listeners, array
$ruleset, PHP_CodeSniffer
$phpcs)
|
|
Constructs a PHP_CodeSniffer_File.
Parameters:
addError [line 811]
boolean addError(
string
$error, int
$stackPtr, [string
$code = ''], [array
$data = array()], [int
$severity = 0], [boolean
$fixable = false])
|
|
Records an error against a specific token in the file.
Parameters:
addErrorOnLine [line 878]
boolean addErrorOnLine(
string
$error, int
$line, [string
$code = ''], [array
$data = array()], [int
$severity = 0])
|
|
Records an error against a specific line in the file.
Parameters:
addFixableError [line 928]
boolean addFixableError(
string
$error, int
$stackPtr, [string
$code = ''], [array
$data = array()], [int
$severity = 0])
|
|
Records a fixable error against a specific token in the file. Returns true if the error was recorded and should be fixed.
Parameters:
addFixableWarning [line 959]
boolean addFixableWarning(
string
$warning, int
$stackPtr, [string
$code = ''], [array
$data = array()], [int
$severity = 0])
|
|
Records a fixable warning against a specific token in the file. Returns true if the warning was recorded and should be fixed.
Parameters:
addTokenListener [line 365]
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 845]
boolean addWarning(
string
$warning, int
$stackPtr, [string
$code = ''], [array
$data = array()], [int
$severity = 0], [boolean
$fixable = false])
|
|
Records a warning against a specific token in the file.
Parameters:
addWarningOnLine [line 902]
boolean addWarningOnLine(
string
$warning, int
$line, [string
$code = ''], [array
$data = array()], [int
$severity = 0])
|
|
Records a warning against a specific token in the file.
Parameters:
cleanUp [line 634]
Remove vars stored in this file that are no longer required.
detectLineEndings [line 753]
string detectLineEndings(
string
$file, [string
$contents = null])
|
|
Opens a file and detects the EOL character being used.
Parameters:
findEndOfStatement [line 3474]
int findEndOfStatement(
int
$start, [int|array
$ignore = null])
|
|
Returns the position of the last non-whitespace token in a statement.
Parameters:
findExtendedClassName [line 3679]
string findExtendedClassName(
int
$stackPtr)
|
|
Returns the name of the class that the specified class extends. Returns FALSE on error or if there is no extended class name.
Parameters:
findFirstOnLine [line 3559]
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:
findImplementedInterfaceNames [line 3728]
array|false findImplementedInterfaceNames(
int
$stackPtr)
|
|
Returns the name(s) of the interface(s) that the specified class implements. Returns FALSE on error or if there are no implemented interface names.
Parameters:
findNext [line 3360]
int|bool 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 3279]
int|bool findPrevious(
int|array
$types, int
$start, [int
$end = null], [bool
$exclude = false], [string
$value = null], [bool
$local = false])
|
|
Returns the position of the previous specified token(s). If a value is specified, the previous token of the specified type(s) containing the specified value will be returned. Returns false if no token can be found.
Parameters:
findStartOfStatement [line 3409]
int findStartOfStatement(
int
$start, [int|array
$ignore = null])
|
|
Returns the position of the first non-whitespace token in a statement.
Parameters:
getClassProperties [line 3091]
array getClassProperties(
int
$stackPtr)
|
|
Returns the visibility and implementation properties of a class. The format of the array is: array(
'is_abstract' => false, // true if the abstract keyword was found.
'is_final' => false, // true if the final keyword was found.
);
Parameters:
getCondition [line 3646]
int getCondition(
int
$stackPtr, int
$type)
|
|
Return the position of the condition for the passed token. Returns FALSE if the token does not have the condition.
Parameters:
getDeclarationName [line 2658]
string|null getDeclarationName(
int
$stackPtr)
|
|
Returns the declaration names for T_CLASS, T_INTERFACE and T_FUNCTION tokens.
Parameters:
getErrorCount [line 1305]
Returns the number of errors raised.
getErrors [line 1365]
Returns the errors raised from processing this file.
getFilename [line 1401]
Returns the absolute filename of this file.
getFixableCount [line 1341]
Returns the number of fixable errors/warnings raised.
getIgnoredLines [line 1353]
Returns the list of ignored lines.
getMemberProperties [line 2993]
array getMemberProperties(
int
$stackPtr)
|
|
Returns the visibility and implementation properties 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 2756]
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 an additional array index of 'default' with the value of the default as a string.
Parameters:
getMethodProperties [line 2905]
array getMethodProperties(
int
$stackPtr)
|
|
Returns the visibility and implementation properties 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.
'is_closure' => false, // true if no name is found.
);
Parameters:
getMetrics [line 1389]
Returns the metrics found while processing this file.
getSuccessCount [line 1329]
Returns the number of successes recorded.
getTokens [line 425]
Returns the token stack for this file.
getTokensAsString [line 3236]
string getTokensAsString(
int
$start, int
$length)
|
|
Returns the content of the tokens from the specified start position in the token stack for the specified length.
Parameters:
getWarningCount [line 1317]
Returns the number of warnings raised.
getWarnings [line 1377]
Returns the warnings raised from processing this file.
hasCondition [line 3609]
boolean hasCondition(
int
$stackPtr, int|array
$types)
|
|
Determine if the passed token has a condition of one of the passed types.
Parameters:
isAnonymousFunction [line 2698]
boolean isAnonymousFunction(
int
$stackPtr)
|
|
Check if the token at the specified position is a anonymous function.
Parameters:
isReference [line 3142]
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:
recordMetric [line 1279]
boolean recordMetric(
int
$stackPtr, string
$metric, string
$value)
|
|
Adds an warning to the warning stack.
Parameters:
refreshTokenListeners [line 412]
void refreshTokenListeners(
)
|
|
Rebuilds the list of listeners to ensure their state is cleared.
removeTokenListener [line 391]
Removes a listener from listening from the specified tokens.
Parameters:
setActiveListener [line 345]
void setActiveListener(
string
$activeListener)
|
|
Sets the name of the currently active sniff.
Parameters:
start [line 440]
void start(
[string
$contents = null])
|
|
Starts the stack traversal and tells listeners when tokens are found.
Parameters:
tokenizeString [line 1423]
array tokenizeString(
string
$string, object
$tokenizer, [string
$eolChar = '\n'], [int
$tabWidth = null], [string
$encoding = null])
|
|
Creates an array of tokens when given some PHP code. Starts by using token_get_all() but does a lot of extra processing to insert information about the context of the token.
Parameters:
Documentation generated on Mon, 11 Mar 2019 14:50:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|
|