PHPCSUtils 1.0.10

Helper
in package

FinalYes

Utility methods to retrieve (configuration) information from PHP_CodeSniffer.

PHP_CodeSniffer cross-version compatibility helper.

Tags
since
1.0.0

The initial methods in this class have been ported over from the external PHPCompatibility & WPCS standards.

Table of Contents

Constants

DEFAULT_TABWIDTH  = 4
The default tab width used by PHP_CodeSniffer.

Methods

getCommandLineData()  : string|null
Get the value of a CLI overrulable single PHP_CodeSniffer config key.
getConfigData()  : string|null
Get the value of a single PHP_CodeSniffer config key.
getEncoding()  : string
Get the applicable (file) encoding as passed to PHP_CodeSniffer from the command-line or the ruleset.
getTabWidth()  : int
Get the applicable tab width as passed to PHP_CodeSniffer from the command-line or the ruleset.
getVersion()  : string
Get the PHP_CodeSniffer version number.
ignoreAnnotations()  : bool
Check whether the "--ignore-annotations" option is in effect.
setConfigData()  : bool
Pass config data to PHP_CodeSniffer.

Constants

DEFAULT_TABWIDTH

The default tab width used by PHP_CodeSniffer.

public int DEFAULT_TABWIDTH = 4
Tags
since
1.0.0

Methods

getCommandLineData()

Get the value of a CLI overrulable single PHP_CodeSniffer config key.

public static getCommandLineData(File $phpcsFile, string $key) : string|null

Use this for config keys which can be set in the CodeSniffer.conf file, on the command-line or in a ruleset.

Parameters
$phpcsFile : File

The file being processed.

$key : string

The name of the config value.

Tags
since
1.0.0
Return values
string|null

getConfigData()

Get the value of a single PHP_CodeSniffer config key.

public static getConfigData(string $key) : string|null
Parameters
$key : string

The name of the config value.

Tags
see
Helper::getCommandLineData()

Alternative for the same which is more reliable if the $phpcsFile object is available.

since
1.0.0
Return values
string|null

getEncoding()

Get the applicable (file) encoding as passed to PHP_CodeSniffer from the command-line or the ruleset.

public static getEncoding([File|null $phpcsFile = null ]) : string
Parameters
$phpcsFile : File|null = null

Optional. The current file being processed.

Tags
since
1.0.0
since
1.0.10

The File type declaration has been removed from the parameter declaration.

Return values
string

Encoding. Defaults to the PHPCS native default, which is 'utf-8' for PHPCS 3.x.

getTabWidth()

Get the applicable tab width as passed to PHP_CodeSniffer from the command-line or the ruleset.

public static getTabWidth(File $phpcsFile) : int
Parameters
$phpcsFile : File

The file being processed.

Tags
since
1.0.0
Return values
int

Tab width. Defaults to the PHPCS native default of 4.

getVersion()

Get the PHP_CodeSniffer version number.

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

ignoreAnnotations()

Check whether the "--ignore-annotations" option is in effect.

public static ignoreAnnotations([File|null $phpcsFile = null ]) : bool
Parameters
$phpcsFile : File|null = null

Optional. The current file being processed.

Tags
since
1.0.0
since
1.0.10

The File type declaration has been removed from the parameter declaration.

Return values
bool

TRUE if annotations should be ignored, FALSE otherwise.

setConfigData()

Pass config data to PHP_CodeSniffer.

public static setConfigData(string $key, mixed $value[, bool $temp = false ][, Config $config = null ]) : bool
Parameters
$key : string

The name of the config value.

$value : mixed

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.

$config : Config = null

The PHPCS config object. This parameter is required for PHPCS 4.x, optional for PHPCS 3.x and not possible to pass for PHPCS 2.x. Passing the $phpcsFile->config property should work in PHPCS 3.x and higher.

Tags
since
1.0.0
Return values
bool

Whether the setting of the data was successfull.


        
On this page

Search results