BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
PHP_CodeSniffer\Files\File Class Reference
Inheritance diagram for PHP_CodeSniffer\Files\File:

Public Member Functions

 __construct ($path, Ruleset $ruleset, Config $config)
 
 setContent ($content)
 
 reloadContent ()
 
 disableCaching ()
 
 process ()
 
 parse ()
 
 getTokens ()
 
 cleanUp ()
 
 addError ($error, $stackPtr, $code, $data=array(), $severity=0, $fixable=false)
 
 addWarning ($warning, $stackPtr, $code, $data=array(), $severity=0, $fixable=false)
 
 addErrorOnLine ($error, $line, $code, $data=array(), $severity=0)
 
 addWarningOnLine ($warning, $line, $code, $data=array(), $severity=0)
 
 addFixableError ($error, $stackPtr, $code, $data=array(), $severity=0)
 
 addFixableWarning ($warning, $stackPtr, $code, $data=array(), $severity=0)
 
 recordMetric ($stackPtr, $metric, $value)
 
 getErrorCount ()
 
 getWarningCount ()
 
 getSuccessCount ()
 
 getFixableCount ()
 
 getFixedCount ()
 
 getIgnoredLines ()
 
 getErrors ()
 
 getWarnings ()
 
 getMetrics ()
 
 getFilename ()
 
 getDeclarationName ($stackPtr)
 
 getMethodParameters ($stackPtr)
 
 getMethodProperties ($stackPtr)
 
 getMemberProperties ($stackPtr)
 
 getClassProperties ($stackPtr)
 
 isReference ($stackPtr)
 
 getTokensAsString ($start, $length)
 
 findPrevious ($types, $start, $end=null, $exclude=false, $value=null, $local=false)
 
 findNext ($types, $start, $end=null, $exclude=false, $value=null, $local=false)
 
 findStartOfStatement ($start, $ignore=null)
 
 findEndOfStatement ($start, $ignore=null)
 
 findFirstOnLine ($types, $start, $exclude=false, $value=null)
 
 hasCondition ($stackPtr, $types)
 
 getCondition ($stackPtr, $type)
 
 findExtendedClassName ($stackPtr)
 
 findImplementedInterfaceNames ($stackPtr)
 

Public Attributes

 $path = ''
 
 $config = null
 
 $ruleset = null
 
 $ignored = false
 
 $eolChar = ''
 
 $fixer = null
 
 $tokenizer = null
 
 $fromCache = false
 
 $numTokens = 0
 

Protected Member Functions

 addMessage ($error, $message, $line, $column, $code, $data, $severity, $fixable)
 

Protected Attributes

 $content = ''
 
 $tokens = array()
 
 $errors = array()
 
 $warnings = array()
 
 $metrics = array()
 
 $errorCount = 0
 
 $warningCount = 0
 
 $fixableCount = 0
 
 $fixedCount = 0
 
 $ignoredListeners = array()
 
 $ignoredCodes = array()
 
 $listeners = array()
 
 $activeListener = ''
 
 $listenerTimes = array()
 
 $configCache = array()
 

Constructor & Destructor Documentation

PHP_CodeSniffer\Files\File::__construct (   $path,
Ruleset  $ruleset,
Config  $config 
)

Constructs a file.

Parameters
string$pathThe absolute path to the file to process.
\PHP_CodeSniffer\Ruleset$rulesetThe ruleset used for the run.
\PHP_CodeSniffer\Config$configThe config data for the run.
Returns
void

Member Function Documentation

PHP_CodeSniffer\Files\File::addError (   $error,
  $stackPtr,
  $code,
  $data = array(),
  $severity = 0,
  $fixable = false 
)

Records an error against a specific token in the file.

Parameters
string$errorThe error message.
int$stackPtrThe stack position where the error occurred.
string$codeA violation code unique to the sniff message.
array$dataReplacements for the error message.
int$severityThe severity level for this error. A value of 0 will be converted into the default severity level.
boolean$fixableCan the error be fixed by the sniff?
Returns
boolean
PHP_CodeSniffer\Files\File::addErrorOnLine (   $error,
  $line,
  $code,
  $data = array(),
  $severity = 0 
)

Records an error against a specific line in the file.

Parameters
string$errorThe error message.
int$lineThe line on which the error occurred.
string$codeA violation code unique to the sniff message.
array$dataReplacements for the error message.
int$severityThe severity level for this error. A value of 0 will be converted into the default severity level.
Returns
boolean
PHP_CodeSniffer\Files\File::addFixableError (   $error,
  $stackPtr,
  $code,
  $data = array(),
  $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$errorThe error message.
int$stackPtrThe stack position where the error occurred.
string$codeA violation code unique to the sniff message.
array$dataReplacements for the error message.
int$severityThe severity level for this error. A value of 0 will be converted into the default severity level.
Returns
boolean
PHP_CodeSniffer\Files\File::addFixableWarning (   $warning,
  $stackPtr,
  $code,
  $data = array(),
  $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$warningThe error message.
int$stackPtrThe stack position where the error occurred.
string$codeA violation code unique to the sniff message.
array$dataReplacements for the warning message.
int$severityThe severity level for this warning. A value of 0 will be converted into the default severity level.
Returns
boolean
PHP_CodeSniffer\Files\File::addMessage (   $error,
  $message,
  $line,
  $column,
  $code,
  $data,
  $severity,
  $fixable 
)
protected

Adds an error to the error stack.

Parameters
boolean$errorIs this an error message?
string$messageThe text of the message.
int$lineThe line on which the message occurred.
int$columnThe column at which the message occurred.
string$codeA violation code unique to the sniff message.
array$dataReplacements for the message.
int$severityThe severity level for this message. A value of 0 will be converted into the default severity level.
boolean$fixableCan the problem be fixed by the sniff?
Returns
boolean
PHP_CodeSniffer\Files\File::addWarning (   $warning,
  $stackPtr,
  $code,
  $data = array(),
  $severity = 0,
  $fixable = false 
)

Records a warning against a specific token in the file.

Parameters
string$warningThe error message.
int$stackPtrThe stack position where the error occurred.
string$codeA violation code unique to the sniff message.
array$dataReplacements for the warning message.
int$severityThe severity level for this warning. A value of 0 will be converted into the default severity level.
boolean$fixableCan the warning be fixed by the sniff?
Returns
boolean
PHP_CodeSniffer\Files\File::addWarningOnLine (   $warning,
  $line,
  $code,
  $data = array(),
  $severity = 0 
)

Records a warning against a specific token in the file.

Parameters
string$warningThe error message.
int$lineThe line on which the warning occurred.
string$codeA violation code unique to the sniff message.
array$dataReplacements for the warning message.
int$severityThe severity level for this warning. A value of 0 will will be converted into the default severity level.
Returns
boolean
PHP_CodeSniffer\Files\File::cleanUp ( )

Remove vars stored in this file that are no longer required.

Returns
void
PHP_CodeSniffer\Files\File::disableCaching ( )

Disables caching of this file.

Returns
void
PHP_CodeSniffer\Files\File::findEndOfStatement (   $start,
  $ignore = null 
)

Returns the position of the last non-whitespace token in a statement.

Parameters
int$startThe position to start searching from in the token stack.
int | array$ignoreToken types that should not be considered stop points.
Returns
int
PHP_CodeSniffer\Files\File::findExtendedClassName (   $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$stackPtrThe stack position of the class.
Returns
string|false
PHP_CodeSniffer\Files\File::findFirstOnLine (   $types,
  $start,
  $exclude = false,
  $value = null 
)

Returns the position of the first token on a line, matching given type.

Returns false if no token can be found.

Parameters
int | array$typesThe type(s) of tokens to search for.
int$startThe position to start searching from in the token stack. The first token matching on this line before this token will be returned.
bool$excludeIf true, find the token that is NOT of the types specified in $types.
string$valueThe value that the token must be equal to. If value is omitted, tokens with any value will be returned.
Returns
int | bool
PHP_CodeSniffer\Files\File::findImplementedInterfaceNames (   $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$stackPtrThe stack position of the class.
Returns
array|false
PHP_CodeSniffer\Files\File::findNext (   $types,
  $start,
  $end = null,
  $exclude = false,
  $value = null,
  $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
int | array$typesThe type(s) of tokens to search for.
int$startThe position to start searching from in the token stack.
int$endThe 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$excludeIf true, find the next token that is NOT of a type specified in $types.
string$valueThe value that the token(s) must be equal to. If value is omitted, tokens with any value will be returned.
bool$localIf true, tokens outside the current statement will not be checked. i.e., checking will stop at the next semi-colon found.
Returns
int|bool
See Also
findPrevious()
PHP_CodeSniffer\Files\File::findPrevious (   $types,
  $start,
  $end = null,
  $exclude = false,
  $value = null,
  $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
int | array$typesThe type(s) of tokens to search for.
int$startThe position to start searching from in the token stack.
int$endThe 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$excludeIf true, find the previous token that is NOT of the types specified in $types.
string$valueThe value that the token(s) must be equal to. If value is omitted, tokens with any value will be returned.
bool$localIf true, tokens outside the current statement will not be checked. IE. checking will stop at the previous semi-colon found.
Returns
int|bool
See Also
findNext()
PHP_CodeSniffer\Files\File::findStartOfStatement (   $start,
  $ignore = null 
)

Returns the position of the first non-whitespace token in a statement.

Parameters
int$startThe position to start searching from in the token stack.
int | array$ignoreToken types that should not be considered stop points.
Returns
int
PHP_CodeSniffer\Files\File::getClassProperties (   $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
int$stackPtrThe position in the stack of the T_CLASS token to acquire the properties for.
Returns
array
Exceptions
\PHP_CodeSniffer\Exceptions\TokenizerExceptionIf the specified position is not a T_CLASS token.
PHP_CodeSniffer\Files\File::getCondition (   $stackPtr,
  $type 
)

Return the position of the condition for the passed token.

Returns FALSE if the token does not have the condition.

Parameters
int$stackPtrThe position of the token we are checking.
int$typeThe type of token to search for.
Returns
int
PHP_CodeSniffer\Files\File::getDeclarationName (   $stackPtr)

Returns the declaration names for classes, interfaces, traits, and functions.

Parameters
int$stackPtrThe position of the declaration token which declared the class, interface, trait, or function.
Returns
string|null The name of the class, interface, trait, or function; or NULL if the function or class is anonymous.
Exceptions
\PHP_CodeSniffer\Exceptions\RuntimeExceptionIf the specified token is not of type T_FUNCTION, T_CLASS, T_ANON_CLASS, T_CLOSURE, T_TRAIT, or T_INTERFACE.
PHP_CodeSniffer\Files\File::getErrorCount ( )

Returns the number of errors raised.

Returns
int
PHP_CodeSniffer\Files\File::getErrors ( )

Returns the errors raised from processing this file.

Returns
array
PHP_CodeSniffer\Files\File::getFilename ( )

Returns the absolute filename of this file.

Returns
string
PHP_CodeSniffer\Files\File::getFixableCount ( )

Returns the number of fixable errors/warnings raised.

Returns
int
PHP_CodeSniffer\Files\File::getFixedCount ( )

Returns the number of fixed errors/warnings.

Returns
int
PHP_CodeSniffer\Files\File::getIgnoredLines ( )

Returns the list of ignored lines.

Returns
array
PHP_CodeSniffer\Files\File::getMemberProperties (   $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. );

Parameters
int$stackPtrThe position in the stack of the T_VARIABLE token to acquire the properties for.
Returns
array
Exceptions
\PHP_CodeSniffer\Exceptions\TokenizerExceptionIf the specified position is not a T_VARIABLE token, or if the position is not a class member variable.
PHP_CodeSniffer\Files\File::getMethodParameters (   $stackPtr)

Returns the method parameters for the specified function token.

Each parameter is in the following format:

0 => array( 'name' => '$var', // The variable name. 'token' => integer, // The stack pointer to 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.

Parameters
int$stackPtrThe position in the stack of the function token to acquire the parameters for.
Returns
array
Exceptions
\PHP_CodeSniffer\Exceptions\TokenizerExceptionIf the specified $stackPtr is not of type T_FUNCTION or T_CLOSURE.
PHP_CodeSniffer\Files\File::getMethodProperties (   $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. );

Parameters
int$stackPtrThe position in the stack of the function token to acquire the properties for.
Returns
array
Exceptions
\PHP_CodeSniffer\Exceptions\TokenizerExceptionIf the specified position is not a T_FUNCTION token.
PHP_CodeSniffer\Files\File::getMetrics ( )

Returns the metrics found while processing this file.

Returns
array
PHP_CodeSniffer\Files\File::getSuccessCount ( )

Returns the number of successes recorded.

Returns
int
PHP_CodeSniffer\Files\File::getTokens ( )

Returns the token stack for this file.

Returns
array
PHP_CodeSniffer\Files\File::getTokensAsString (   $start,
  $length 
)

Returns the content of the tokens from the specified start position in the token stack for the specified length.

Parameters
int$startThe position to start from in the token stack.
int$lengthThe length of tokens to traverse from the start pos.
Returns
string The token contents.
PHP_CodeSniffer\Files\File::getWarningCount ( )

Returns the number of warnings raised.

Returns
int
PHP_CodeSniffer\Files\File::getWarnings ( )

Returns the warnings raised from processing this file.

Returns
array
PHP_CodeSniffer\Files\File::hasCondition (   $stackPtr,
  $types 
)

Determine if the passed token has a condition of one of the passed types.

Parameters
int$stackPtrThe position of the token we are checking.
int | array$typesThe type(s) of tokens to search for.
Returns
boolean
PHP_CodeSniffer\Files\File::isReference (   $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$stackPtrThe position of the T_BITWISE_AND token.
Returns
boolean
PHP_CodeSniffer\Files\File::parse ( )

Tokenizes the file and prepares it for the test run.

Returns
void
PHP_CodeSniffer\Files\File::process ( )

Starts the stack traversal and tells listeners when tokens are found.

Returns
void
PHP_CodeSniffer\Files\File::recordMetric (   $stackPtr,
  $metric,
  $value 
)

Adds an warning to the warning stack.

Parameters
int$stackPtrThe stack position where the metric was recorded.
string$metricThe name of the metric being recorded.
string$valueThe value of the metric being recorded.
Returns
boolean
PHP_CodeSniffer\Files\File::reloadContent ( )

Reloads the content of the file.

By default, we have no idea where our content comes from, so we can't do anything.

Returns
void
PHP_CodeSniffer\Files\File::setContent (   $content)

Set the content of the file.

Setting the content also calculates the EOL char being used.

Parameters
string$contentThe file content.
Returns
void

The documentation for this class was generated from the following file: