Helper
Utility methods to retrieve (configuration) information from PHP_CodeSniffer.
PHP_CodeSniffer cross-version compatibility helper for PHPCS 2.x vs PHPCS 3.x.
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 commonly used by external standards.
Table of Contents
| DEFAULT_TABWIDTH | The default tab width used by PHP_CodeSniffer. | 4 |
|---|---|---|
| getVersion() | Get the PHP_CodeSniffer version number. | string |
| setConfigData() | Pass config data to PHP_CodeSniffer. | bool |
| getConfigData() | Get the value of a single PHP_CodeSniffer config key. | string|null |
| getCommandLineData() | Get the value of a CLI overrulable single PHP_CodeSniffer config key. | string|null |
| getTabWidth() | Get the applicable tab width as passed to PHP_CodeSniffer from the command-line or the ruleset. | int |
| ignoreAnnotations() | Check whether the `--ignore-annotations` option has been used. | bool |
Constants
DEFAULT_TABWIDTH
The default tab width used by PHP_CodeSniffer.
int
$DEFAULT_TABWIDTH
= 4
Methods
getVersion()
Get the PHP_CodeSniffer version number.
public
static getVersion(
)
: string
Tags
Return values
stringsetConfigData()
Pass config data to PHP_CodeSniffer.
public
static setConfigData(
$key :
string
, $value :
string|null
[, $temp :
bool
= false ]
)
: bool
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
Return values
bool —Whether the setting of the data was successfull.
getConfigData()
Get the value of a single PHP_CodeSniffer config key.
public
static getConfigData(
$key :
string
)
: string|null
Parameters
- $key : string
The name of the config value.
Tags
Return values
string|nullgetCommandLineData()
Get the value of a CLI overrulable single PHP_CodeSniffer config key.
public
static getCommandLineData(
$phpcsFile :
File
, $key :
string
)
: 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
Return values
string|nullgetTabWidth()
Get the applicable tab width as passed to PHP_CodeSniffer from the command-line or the ruleset.
public
static getTabWidth(
$phpcsFile :
File
)
: int
Parameters
- $phpcsFile : File
The file being processed.
Tags
Return values
int —Tab width. Defaults to the PHPCS native default of 4.
ignoreAnnotations()
Check whether the `--ignore-annotations` option has been used.
public
static ignoreAnnotations(
[ $phpcsFile :
File
= null ]
)
: bool
Parameters
- $phpcsFile : File = null
Optional. The current file being processed.
Tags
Return values
bool —True if annotations should be ignored, false otherwise.