apidoc
[ class tree: apidoc ] [ index: apidoc ] [ all elements ]

Class: File

Source Location: /PHP_CodeSniffer-3.1.1/src/Files/File.php

Class Overview


Represents a piece of content being checked during the run.


Author(s):

Copyright:

  • 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)

Variables

Methods


Child classes:

LocalFile
A local file represents a chunk of text has a file system location.
DummyFile
A dummy file represents a chunk of text that does not have a file system location.

Inherited Variables

Inherited Methods


Class Details

[line 19]
Represents a piece of content being checked during the run.


[ Top ]


Class Variables

$activeListener =  ''

[line 182]

The class name of the sniff currently processing the file.
  • Access: protected

Type:   string


[ Top ]

$config =  null

[line 41]

The config data for the run.
  • Access: public

Type:   \PHP_CodeSniffer\Config


[ Top ]

$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.

  • Access: protected

Type:   array


[ Top ]

$content =  ''

[line 34]

The absolute path to the file associated with this object.
  • Access: protected

Type:   string


[ Top ]

$eolChar =  ''

[line 62]

The EOL character this file uses.
  • Access: public

Type:   string


[ Top ]

$errorCount =  0

[line 133]

The total number of errors raised.
  • Access: protected

Type:   integer


[ Top ]

$errors = array()

[line 110]

The errors raised from sniffs.
  • See: getErrors()
  • Access: protected

Type:   array


[ Top ]

$fixableCount =  0

[line 147]

The total number of errors and warnings that can be fixed.
  • Access: protected

Type:   integer


[ Top ]

$fixedCount =  0

[line 154]

The total number of errors and warnings that were fixed.
  • Access: protected

Type:   integer


[ Top ]

$fixer =  null

[line 69]

The Fixer object to control fixing errors.
  • Access: public

Type:   \PHP_CodeSniffer\Fixer


[ Top ]

$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.

  • Access: public

Type:   boolean


[ Top ]

$ignored =  false

[line 55]

If TRUE, the entire file is being ignored.
  • Access: public

Type:   string


[ Top ]

$ignoredCodes = array()

[line 168]

An array of message codes that are being ignored.
  • Access: protected

Type:   array


[ Top ]

$ignoredListeners = array()

[line 161]

An array of sniffs that are being ignored.
  • Access: protected

Type:   array


[ Top ]

$listeners = array()

[line 175]

An array of sniffs listening to this file's processing.
  • Access: protected

Type:   \PHP_CodeSniffer\Sniffs\Sniff[]


[ Top ]

$listenerTimes = array()

[line 189]

An array of sniffs being processed and how long they took.
  • Access: protected

Type:   array


[ Top ]

$metrics = array()

[line 126]

The metrics recorded by sniffs.
  • See: getMetrics()
  • Access: protected

Type:   array


[ Top ]

$numTokens =  0

[line 95]

The number of tokens in this file.

Stored here to save calling count() everywhere.

  • Access: public

Type:   integer


[ Top ]

$path =  ''

[line 27]

The absolute path to the file associated with this object.
  • Access: public

Type:   string


[ Top ]

$ruleset =  null

[line 48]

The ruleset used for the run.
  • Access: public

Type:   \PHP_CodeSniffer\Ruleset


[ Top ]

$tokenizer =  null

[line 76]

The tokenizer being used for this file.
  • Access: public

Type:   \PHP_CodeSniffer\Tokenizers\Tokenizer


[ Top ]

$tokens = array()

[line 102]

The tokens stack map.
  • Access: protected

Type:   array


[ Top ]

$warningCount =  0

[line 140]

The total number of warnings raised.
  • Access: protected

Type:   integer


[ Top ]

$warnings = array()

[line 118]

The warnings raised from sniffs.
  • See: getWarnings()
  • Access: protected

Type:   array


[ Top ]



Method Detail

__construct (Constructor)   [line 210]

void __construct( string $path, Ruleset $ruleset, Config $config)

Constructs a file.
  • Access: public

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.

[ Top ]

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.
  • Access: public

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?

[ Top ]

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.
  • Access: public

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.

[ Top ]

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.

  • Access: public

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.

[ Top ]

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.

  • Access: public

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.

[ Top ]

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.
  • Access: protected

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?

[ Top ]

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.
  • Access: public

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?

[ Top ]

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.
  • Access: public

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.

[ Top ]

cleanUp   [line 569]

void cleanUp( )

Remove vars stored in this file that are no longer required.
  • Access: public

[ Top ]

disableCaching   [line 280]

void disableCaching( )

Disables caching of this file.
  • Access: public

[ Top ]

findEndOfStatement   [line 1966]

int findEndOfStatement( int $start, [int|array $ignore = null])

Returns the position of the last non-whitespace token in a statement.
  • Access: public

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.

[ Top ]

findExtendedClassName   [line 2172]

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.

  • Access: public

Parameters:

int   $stackPtr   —  The stack position of the class.

[ Top ]

findFirstOnLine   [line 2051]

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.

[ Top ]

findImplementedInterfaceNames   [line 2224]

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.

  • Access: public

Parameters:

int   $stackPtr   —  The stack position of the class.

[ Top ]

findNext   [line 1852]

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.

[ Top ]

findPrevious   [line 1771]

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.

[ Top ]

findStartOfStatement   [line 1901]

int findStartOfStatement( int $start, [int|array $ignore = null])

Returns the position of the first non-whitespace token in a statement.
  • Access: public

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.

[ Top ]

getClassProperties   [line 1545]

array getClassProperties( int $stackPtr)

Returns the visibility and implementation properties of a class.

The format of the array is:

  1.    array(
  2.     'is_abstract' => false// true if the abstract keyword was found.
  3.     'is_final'    => false// true if the final keyword was found.
  4.    );

  • 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.

[ Top ]

getCondition   [line 2138]

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.

  • Access: public

Parameters:

int   $stackPtr   —  The position of the token we are checking.
int   $type   —  The type of token to search for.

[ Top ]

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.

[ Top ]

getErrorCount   [line 989]

int getErrorCount( )

Returns the number of errors raised.
  • Access: public

[ Top ]

getErrors   [line 1061]

array getErrors( )

Returns the errors raised from processing this file.
  • Access: public

[ Top ]

getFilename   [line 1097]

string getFilename( )

Returns the absolute filename of this file.
  • Access: public

[ Top ]

getFixableCount   [line 1025]

int getFixableCount( )

Returns the number of fixable errors/warnings raised.
  • Access: public

[ Top ]

getFixedCount   [line 1037]

int getFixedCount( )

Returns the number of fixed errors/warnings.
  • Access: public

[ Top ]

getIgnoredLines   [line 1049]

array getIgnoredLines( )

Returns the list of ignored lines.
  • Access: public

[ Top ]

getMemberProperties   [line 1446]

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:

  1.    array(
  2.     'scope'       => 'public'// public protected or protected
  3.     'is_static'   => false,    // true if the static keyword was found.
  4.    );

  • 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.

[ Top ]

getMethodParameters   [line 1180]

array getMethodParameters( int $stackPtr)

Returns the method parameters for the specified function token.

Each parameter is in the following format:

  1.    0 => array(
  2.          'name'              => '$var',  // The variable name.
  3.          'token'             => integer// The stack pointer to the variable name.
  4.          'content'           => string,  // The full content of the variable definition.
  5.          'pass_by_reference' => boolean// Is the variable passed by reference?
  6.          'variable_length'   => boolean// Is the param of variable length through use of `...` ?
  7.          'type_hint'         => string,  // The type hint for the variable.
  8.          'nullable_type'     => boolean// Is the variable using a nullable type?
  9.         )

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.

[ Top ]

getMethodProperties   [line 1349]

array getMethodProperties( int $stackPtr)

Returns the visibility and implementation properties of a method.

The format of the array is:

  1.    array(
  2.     'scope'           => 'public'// public protected or protected
  3.     'scope_specified' => true,     // true is scope keyword was found.
  4.     'is_abstract'     => false,    // true if the abstract keyword was found.
  5.     'is_final'        => false,    // true if the final keyword was found.
  6.     'is_static'       => false,    // true if the static keyword was found.
  7.    );

  • 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.

[ Top ]

getMetrics   [line 1085]

array getMetrics( )

Returns the metrics found while processing this file.
  • Access: public

[ Top ]

getSuccessCount   [line 1013]

int getSuccessCount( )

Returns the number of successes recorded.
  • Access: public

[ Top ]

getTokens   [line 557]

array getTokens( )

Returns the token stack for this file.
  • Access: public

[ Top ]

getTokensAsString   [line 1728]

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.

[ Top ]

getWarningCount   [line 1001]

int getWarningCount( )

Returns the number of warnings raised.
  • Access: public

[ Top ]

getWarnings   [line 1073]

array getWarnings( )

Returns the warnings raised from processing this file.
  • Access: public

[ Top ]

hasCondition   [line 2101]

boolean hasCondition( int $stackPtr, int|array $types)

Determine if the passed token has a condition of one of the passed types.
  • Access: public

Parameters:

int   $stackPtr   —  The position of the token we are checking.
int|array   $types   —  The type(s) of tokens to search for.

[ Top ]

isReference   [line 1596]

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.

  • Access: public

Parameters:

int   $stackPtr   —  The position of the T_BITWISE_AND token.

[ Top ]

parse   [line 497]

void parse( )

Tokenizes the file and prepares it for the test run.
  • Access: public

[ Top ]

process   [line 292]

void process( )

Starts the stack traversal and tells listeners when tokens are found.
  • Access: public

Overridden in child classes as:

LocalFile::process()
Processes the file.

[ Top ]

recordMetric   [line 967]

boolean recordMetric( int $stackPtr, string $metric, string $value)

Adds an warning to the warning stack.
  • Access: public

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.

[ Top ]

reloadContent   [line 269]

void reloadContent( )

Reloads the content of the file.

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

  • Access: public

Overridden in child classes as:

LocalFile::reloadContent()
Loads the latest version of the file's content from the file system.

[ Top ]

setContent   [line 246]

void setContent( string $content)

Set the content of the file.

Setting the content also calculates the EOL char being used.

  • Access: public

Parameters:

string   $content   —  The file content.

[ Top ]


Documentation generated on Mon, 16 Oct 2017 23:00:24 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.