$activeListener = ''
[line 182]
The class name of the sniff currently processing the file.
$config = null
[line 41]
The config data for the run.
Type:
\PHP_CodeSniffer\Config
$configCache = array()
[line 198]
A cache of often used config settings to improve performance.
Storing them here saves 10k+ calls to __get() in the Config class.
$content = ''
[line 34]
The absolute path to the file associated with this object.
$eolChar = ''
[line 62]
The EOL character this file uses.
$errorCount = 0
[line 133]
The total number of errors raised.
$errors = array()
[line 110]
The errors raised from sniffs.
- See: getErrors()
- Access: protected
$fixableCount = 0
[line 147]
The total number of errors and warnings that can be fixed.
$fixedCount = 0
[line 154]
The total number of errors and warnings that were fixed.
$fixer = null
[line 69]
The Fixer object to control fixing errors.
Type:
\PHP_CodeSniffer\Fixer
$fromCache = false
[line 86]
Was the file loaded from cache?
If TRUE, the file was loaded from a local cache. If FALSE, the file was tokenized and processed fully.
$ignored = false
[line 55]
If TRUE, the entire file is being ignored.
$ignoredCodes = array()
[line 168]
An array of message codes that are being ignored.
$ignoredListeners = array()
[line 161]
An array of sniffs that are being ignored.
$listeners = array()
[line 175]
An array of sniffs listening to this file's processing.
Type:
\PHP_CodeSniffer\Sniffs\Sniff[]
$listenerTimes = array()
[line 189]
An array of sniffs being processed and how long they took.
$metrics = array()
[line 126]
The metrics recorded by sniffs.
- See: getMetrics()
- Access: protected
$numTokens = 0
[line 95]
The number of tokens in this file.
Stored here to save calling count() everywhere.
$path = ''
[line 27]
The absolute path to the file associated with this object.
$ruleset = null
[line 48]
The ruleset used for the run.
Type:
\PHP_CodeSniffer\Ruleset
$tokenizer = null
[line 76]
The tokenizer being used for this file.
Type:
\PHP_CodeSniffer\Tokenizers\Tokenizer
$tokens = array()
[line 102]
The tokens stack map.
$warningCount = 0
[line 140]
The total number of warnings raised.
$warnings = array()
[line 118]
The warnings raised from sniffs.
- See: getWarnings()
- Access: protected
__construct (Constructor) [line 210]
void __construct(
string
$path, Ruleset
$ruleset, Config
$config)
Constructs a file.
Overridden in child classes as:
- LocalFile::__construct()
- Creates a LocalFile object and sets the content.
- DummyFile::__construct()
- Creates a DummyFile object and sets the content.
Parameters:
string
$path
—
The absolute path to the file to process.
\PHP_CodeSniffer\Ruleset
$ruleset
—
The ruleset used for the run.
\PHP_CodeSniffer\Config
$config
—
The config data for the run.
addError [line 595]
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:
string
$error
—
The error message.
int
$stackPtr
—
The stack position where the error occurred.
string
$code
—
A violation code unique to the sniff message.
array
$data
—
Replacements for the error message.
int
$severity
—
The severity level for this error. A value of 0 will be converted into the default severity level.
boolean
$fixable
—
Can the error be fixed by the sniff?
addErrorOnLine [line 662]
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:
string
$error
—
The error message.
int
$line
—
The line on which the error occurred.
string
$code
—
A violation code unique to the sniff message.
array
$data
—
Replacements for the error message.
int
$severity
—
The severity level for this error. A value of 0 will be converted into the default severity level.
addFixableError [line 712]
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:
string
$error
—
The error message.
int
$stackPtr
—
The stack position where the error occurred.
string
$code
—
A violation code unique to the sniff message.
array
$data
—
Replacements for the error message.
int
$severity
—
The severity level for this error. A value of 0 will be converted into the default severity level.
addFixableWarning [line 743]
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:
string
$warning
—
The error message.
int
$stackPtr
—
The stack position where the error occurred.
string
$code
—
A violation code unique to the sniff message.
array
$data
—
Replacements for the warning message.
int
$severity
—
The severity level for this warning. A value of 0 will be converted into the default severity level.
addMessage [line 775]
boolean addMessage(
boolean
$error, string
$message, int
$line, int
$column, string
$code, array
$data, int
$severity, boolean
$fixable)
Adds an error to the error stack.
Parameters:
boolean
$error
—
Is this an error message?
string
$message
—
The text of the message.
int
$line
—
The line on which the message occurred.
int
$column
—
The column at which the message occurred.
string
$code
—
A violation code unique to the sniff message.
array
$data
—
Replacements for the message.
int
$severity
—
The severity level for this message. A value of 0 will be converted into the default severity level.
boolean
$fixable
—
Can the problem be fixed by the sniff?
addWarning [line 629]
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:
string
$warning
—
The error message.
int
$stackPtr
—
The stack position where the error occurred.
string
$code
—
A violation code unique to the sniff message.
array
$data
—
Replacements for the warning message.
int
$severity
—
The severity level for this warning. A value of 0 will be converted into the default severity level.
boolean
$fixable
—
Can the warning be fixed by the sniff?
addWarningOnLine [line 686]
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:
string
$warning
—
The error message.
int
$line
—
The line on which the warning occurred.
string
$code
—
A violation code unique to the sniff message.
array
$data
—
Replacements for the warning message.
int
$severity
—
The severity level for this warning. A value of 0 will will be converted into the default severity level.
cleanUp [line 569]
Remove vars stored in this file that are no longer required.
disableCaching [line 280]
Disables caching of this file.
findEndOfStatement [line 1925]
int findEndOfStatement(
int
$start, [int|array
$ignore = null])
Returns the position of the last non-whitespace token in a statement.
Parameters:
int
$start
—
The position to start searching from in the token stack.
int|array
$ignore
—
Token types that should not be considered stop points.
findExtendedClassName [line 2131]
string|false findExtendedClassName(
int
$stackPtr)
Returns the name of the class that the specified class extends.
(works for classes, anonymous classes and interfaces)
Returns FALSE on error or if there is no extended class name.
Parameters:
int
$stackPtr
—
The stack position of the class.
findFirstOnLine [line 2010]
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.
- Return: | bool
- Access: public
Parameters:
int|array
$types
—
The type(s) of tokens to search for.
int
$start
—
The position to start searching from in the token stack. The first token matching on this line before this token will be returned.
bool
$exclude
—
If true, find the token that is NOT of the types specified in $types.
string
$value
—
The value that the token must be equal to. If value is omitted, tokens with any value will be returned.
findImplementedInterfaceNames [line 2183]
array|false findImplementedInterfaceNames(
int
$stackPtr)
Returns the names of the interfaces that the specified class implements.
Returns FALSE on error or if there are no implemented interface names.
Parameters:
int
$stackPtr
—
The stack position of the class.
findNext [line 1811]
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.
- See: findPrevious()
- Access: public
Parameters:
int|array
$types
—
The type(s) of tokens to search for.
int
$start
—
The position to start searching from in the token stack.
int
$end
—
The end position to fail if no token is found. if not specified or null, end will default to the end of the token stack.
bool
$exclude
—
If true, find the next token that is NOT of a type specified in $types.
string
$value
—
The value that the token(s) must be equal to. If value is omitted, tokens with any value will be returned.
bool
$local
—
If true, tokens outside the current statement will not be checked. i.e., checking will stop at the next semi-colon found.
findPrevious [line 1730]
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.
- See: findNext()
- Access: public
Parameters:
int|array
$types
—
The type(s) of tokens to search for.
int
$start
—
The position to start searching from in the token stack.
int
$end
—
The end position to fail if no token is found. if not specified or null, end will default to the start of the token stack.
bool
$exclude
—
If true, find the previous token that is NOT of the types specified in $types.
string
$value
—
The value that the token(s) must be equal to. If value is omitted, tokens with any value will be returned.
bool
$local
—
If true, tokens outside the current statement will not be checked. IE. checking will stop at the previous semi-colon found.
findStartOfStatement [line 1860]
int findStartOfStatement(
int
$start, [int|array
$ignore = null])
Returns the position of the first non-whitespace token in a statement.
Parameters:
int
$start
—
The position to start searching from in the token stack.
int|array
$ignore
—
Token types that should not be considered stop points.
getClassProperties [line 1542]
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.
);
- Throws: \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a T_CLASS token.
- Access: public
Parameters:
int
$stackPtr
—
The position in the stack of the T_CLASS token to acquire the properties for.
getCondition [line 2097]
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:
int
$stackPtr
—
The position of the token we are checking.
int
$type
—
The type of token to search for.
getDeclarationName [line 1116]
string|null getDeclarationName(
int
$stackPtr)
Returns the declaration names for classes, interfaces, traits, and functions.
- Return: The name of the class, interface, trait, or function; or NULL if the function or class is anonymous.
- Throws: \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type T_FUNCTION, T_CLASS, T_ANON_CLASS, T_CLOSURE, T_TRAIT, or T_INTERFACE.
- Access: public
Parameters:
int
$stackPtr
—
The position of the declaration token which declared the class, interface, trait, or function.
getErrorCount [line 989]
Returns the number of errors raised.
getErrors [line 1061]
Returns the errors raised from processing this file.
getFilename [line 1097]
Returns the absolute filename of this file.
getFixableCount [line 1025]
Returns the number of fixable errors/warnings raised.
getFixedCount [line 1037]
Returns the number of fixed errors/warnings.
getIgnoredLines [line 1049]
Returns the list of ignored lines.
getMemberProperties [line 1443]
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 protected or protected
'is_static' => false, // true if the static keyword was found.
);
- Throws: \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a T_VARIABLE token, or if the position is not a class member variable.
- Access: public
Parameters:
int
$stackPtr
—
The position in the stack of the T_VARIABLE token to acquire the properties for.
getMethodParameters [line 1179]
array getMethodParameters(
int
$stackPtr)
Returns the method parameters for the specified function token.
Each parameter is in the following format:
0 => array(
'name' => '$var', // The variable name.
'content' => string, // The full content of the variable definition.
'pass_by_reference' => boolean, // Is the variable passed by reference?
'variable_length' => boolean, // Is the param of variable length through use of `...` ?
'type_hint' => string, // The type hint for the variable.
'nullable_type' => boolean, // Is the variable using a nullable type?
)
Parameters with default values have an additional array index of 'default' with the value of the default as a string.
- Throws: \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of type T_FUNCTION or T_CLOSURE.
- Access: public
Parameters:
int
$stackPtr
—
The position in the stack of the function token to acquire the parameters for.
getMethodProperties [line 1346]
array getMethodProperties(
int
$stackPtr)
Returns the visibility and implementation properties of a method.
The format of the array is: array(
'scope' => 'public', // public protected 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.
);
- Throws: \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a T_FUNCTION token.
- Access: public
Parameters:
int
$stackPtr
—
The position in the stack of the function token to acquire the properties for.
getMetrics [line 1085]
Returns the metrics found while processing this file.
getSuccessCount [line 1013]
Returns the number of successes recorded.
getTokens [line 557]
Returns the token stack for this file.
getTokensAsString [line 1687]
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.
- Return: The token contents.
- Access: public
Parameters:
int
$start
—
The position to start from in the token stack.
int
$length
—
The length of tokens to traverse from the start pos.
getWarningCount [line 1001]
Returns the number of warnings raised.
getWarnings [line 1073]
Returns the warnings raised from processing this file.
hasCondition [line 2060]
boolean hasCondition(
int
$stackPtr, int|array
$types)
Determine if the passed token has a condition of one of the passed types.
Parameters:
int
$stackPtr
—
The position of the token we are checking.
int|array
$types
—
The type(s) of tokens to search for.
isReference [line 1593]
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:
int
$stackPtr
—
The position of the T_BITWISE_AND token.
parse [line 497]
Tokenizes the file and prepares it for the test run.
process [line 292]
Starts the stack traversal and tells listeners when tokens are found.
Overridden in child classes as:
- LocalFile::process()
- Processes the file.
recordMetric [line 967]
boolean recordMetric(
int
$stackPtr, string
$metric, string
$value)
Adds an warning to the warning stack.
Parameters:
int
$stackPtr
—
The stack position where the metric was recorded.
string
$metric
—
The name of the metric being recorded.
string
$value
—
The value of the metric being recorded.
reloadContent [line 269]
Reloads the content of the file.
By default, we have no idea where our content comes from, so we can't do anything.
Overridden in child classes as:
- LocalFile::reloadContent()
- Loads the latest version of the file's content from the file system.
setContent [line 246]
void setContent(
string
$content)
Set the content of the file.
Setting the content also calculates the EOL char being used.
Parameters:
string
$content
—
The file content.