Documentation

InvalidDeprecationVersionSniff
in package
implements Sniff, DeprecatedSniff

Table of Contents

Interfaces

Sniff
DeprecatedSniff

Methods

getDeprecationMessage()  : string
Optionally provide an arbitrary custom message to display with the deprecation.
getDeprecationVersion()  : string
Provide the version number in which the sniff was deprecated.
getRemovalVersion()  : string
Provide the version number in which the sniff will be removed.
process()  : void|int
Called when one of the token types that this sniff is listening for is found.
register()  : array<string|int, int|string>
Registers the tokens that this sniff wants to listen for.

Methods

getDeprecationMessage()

Optionally provide an arbitrary custom message to display with the deprecation.

public getDeprecationMessage() : string

Typically intended to allow for displaying information about what to replace the deprecated sniff with. Example: "Use the Stnd.Cat.SniffName sniff instead." Multi-line messages (containing new line characters) are supported.

An empty string can be returned if there is no replacement/no need for a custom message.

Return values
string

getDeprecationVersion()

Provide the version number in which the sniff was deprecated.

public getDeprecationVersion() : string

Recommended format for PHPCS native sniffs: "v3.3.0". Recommended format for external sniffs: "StandardName v3.3.0".

Return values
string

getRemovalVersion()

Provide the version number in which the sniff will be removed.

public getRemovalVersion() : string

Recommended format for PHPCS native sniffs: "v3.3.0". Recommended format for external sniffs: "StandardName v3.3.0".

If the removal version is not yet known, it is recommended to set this to: "a future version".

Return values
string

process()

Called when one of the token types that this sniff is listening for is found.

public process(File $phpcsFile, mixed $stackPtr) : void|int

The stackPtr variable indicates where in the stack the token was found. A sniff can acquire information about this token, along with all the other tokens within the stack by first acquiring the token stack:

$tokens = $phpcsFile->getTokens(); echo 'Encountered a '.$tokens[$stackPtr]['type'].' token'; echo 'token information: '; print_r($tokens[$stackPtr]);

If the sniff discovers an anomaly in the code, they can raise an error by calling addError() on the \PHP_CodeSniffer\Files\File object, specifying an error message and the position of the offending token:

$phpcsFile->addError('Encountered an error', $stackPtr);
Parameters
$phpcsFile : File

The PHP_CodeSniffer file where the token was found.

$stackPtr : mixed

The position in the PHP_CodeSniffer file's token stack where the token was found.

Return values
void|int

Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return $phpcsFile->numTokens to skip the rest of the file.

register()

Registers the tokens that this sniff wants to listen for.

public register() : array<string|int, int|string>

An example return value for a sniff that wants to listen for whitespace and any comments would be:

return array( T_WHITESPACE, T_DOC_COMMENT, T_COMMENT, );
Return values
array<string|int, int|string>

        
On this page

Search results