PHPCSHelper
in package
PHPCS cross-version compatibility helper class.
A number of PHPCS classes were split up into several classes in PHPCS 3.x Those classes cannot be aliased as they don't represent the same object. This class provides helper methods for functions which were contained in one of these classes and which are used within the PHPCompatibility library.
Additionally, this class contains some duplicates of PHPCS native methods. These methods have received bug fixes or improved functionality between the lowest supported PHPCS version and the latest PHPCS stable version and to provide the same results cross-version, PHPCompatibility needs to use the up-to-date versions of these methods.
Tags
Table of Contents
Methods
- findEndOfStatement() : int
- Returns the position of the last non-whitespace token in a statement.
- findExtendedClassName() : string|false
- Returns the name of the class that the specified class extends (works for classes, anonymous classes and interfaces).
- findImplementedInterfaceNames() : array<string|int, mixed>|false
- Returns the name(s) of the interface(s) that the specified class implements.
- findStartOfStatement() : int
- Returns the position of the first non-whitespace token in a statement.
- getCommandLineData() : string|null
- Get the value of a single PHPCS config key.
- getConfigData() : string|null
- Get the value of a single PHPCS config key.
- getMethodParameters() : array<string|int, mixed>|false
- Returns the method parameters for the specified function token.
- getVersion() : string
- Get the PHPCS version number.
- setConfigData() : void
- Pass config data to PHPCS.
Methods
findEndOfStatement()
Returns the position of the last non-whitespace token in a statement.
public
static findEndOfStatement(PHP_CodeSniffer_File $phpcsFile, int $start[, int|array<string|int, mixed> $ignore = null ]) : int
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
Instance of phpcsFile.
- $start : int
-
The position to start searching from in the token stack.
- $ignore : int|array<string|int, mixed> = null
-
Token types that should not be considered stop points.
Tags
Return values
intfindExtendedClassName()
Returns the name of the class that the specified class extends (works for classes, anonymous classes and interfaces).
public
static findExtendedClassName(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : string|false
Returns FALSE on error or if there is no extended class name.
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
Instance of phpcsFile.
- $stackPtr : int
-
The position of the class token in the stack.
Tags
Return values
string|falsefindImplementedInterfaceNames()
Returns the name(s) of the interface(s) that the specified class implements.
public
static findImplementedInterfaceNames(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : array<string|int, mixed>|false
Returns FALSE on error or if there are no implemented interface names.
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The file being scanned.
- $stackPtr : int
-
The position of the class token.
Tags
Return values
array<string|int, mixed>|falsefindStartOfStatement()
Returns the position of the first non-whitespace token in a statement.
public
static findStartOfStatement(PHP_CodeSniffer_File $phpcsFile, int $start[, int|array<string|int, mixed> $ignore = null ]) : int
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
Instance of phpcsFile.
- $start : int
-
The position to start searching from in the token stack.
- $ignore : int|array<string|int, mixed> = null
-
Token types that should not be considered stop points.
Tags
Return values
intgetCommandLineData()
Get the value of a single PHPCS config key.
public
static getCommandLineData(PHP_CodeSniffer_File $phpcsFile, string $key) : string|null
This config key can be set in the CodeSniffer.conf
file, on the
command-line or in a ruleset.
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The file being scanned.
- $key : string
-
The name of the config value.
Tags
Return values
string|nullgetConfigData()
Get the value of a single PHPCS config key.
public
static getConfigData(string $key) : string|null
Parameters
- $key : string
-
The name of the config value.
Tags
Return values
string|nullgetMethodParameters()
Returns the method parameters for the specified function token.
public
static getMethodParameters(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : array<string|int, mixed>|false
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.
'type_hint_token' => integer, // The stack pointer to the type hint
// or false if there is no type hint.
'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
- $phpcsFile : PHP_CodeSniffer_File
-
Instance of phpcsFile.
- $stackPtr : int
-
The position in the stack of the function token to acquire the parameters for.
Tags
Return values
array<string|int, mixed>|falsegetVersion()
Get the PHPCS version number.
public
static getVersion() : string
Tags
Return values
stringsetConfigData()
Pass config data to PHPCS.
public
static setConfigData(string $key, string|null $value[, bool $temp = false ]) : void
PHPCS cross-version compatibility helper.
Parameters
- $key : string
-
The name of the config value.
- $value : string|null
-
The value to set. If null, the config entry is deleted, reverting it to the default value.
- $temp : bool = false
-
Set this config data temporarily for this script run. This will not write the config data to the config file.