HumHub Documentation (unofficial)

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
since
8.0.0
since
8.2.0

The duplicate PHPCS methods have been moved from the Sniff base class to this class.

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
since
8.2.0
Return values
int

findExtendedClassName()

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
since
7.1.4
since
8.2.0

Moved from the Sniff class to this class.

Return values
string|false

findImplementedInterfaceNames()

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
since
7.0.3
since
8.2.0

Moved from the Sniff class to this class.

Return values
array<string|int, mixed>|false

findStartOfStatement()

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
since
9.1.0
Return values
int

getCommandLineData()

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
since
8.2.0
Return values
string|null

getConfigData()

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
since
8.0.0
Return values
string|null

getMethodParameters()

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
since
7.0.3
since
8.2.0

Moved from the Sniff class to this class.

throws
PHP_CodeSniffer_Exception

If the specified $stackPtr is not of type T_FUNCTION or T_CLOSURE.

Return values
array<string|int, mixed>|false

getVersion()

Get the PHPCS version number.

public static getVersion() : string
Tags
since
8.0.0
Return values
string

setConfigData()

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.

Tags
since
8.0.0

        
On this page

Search results