Documentation

AbstractPatternSniff
in package
implements Sniff

AbstractYes

Table of Contents

Interfaces

Sniff

Properties

$ignoreComments  : bool
If true, comments will be ignored if they are found in the code.
$currFile  : string
The current file being checked.
$errorPos  : array<int, bool>
Positions in the stack where errors have occurred.
$parsedPatterns  : array<string|int, mixed>
The parsed patterns array.
$supplementaryTokens  : array<string|int, int>
Tokens that this sniff wishes to process outside of the patterns.

Methods

__construct()  : mixed
Constructs a AbstractPatternSniff.
process()  : void
Processes the test.
register()  : array<string|int, int|string>
Registers the tokens to listen to.
getPatterns()  : array<string|int, string>
Returns the patterns that should be checked.
prepareError()  : string
Prepares an error for the specified patternCode.
processPattern()  : array<string|int, mixed>|false
Processes the pattern and verifies the code at $stackPtr.
processSupplementary()  : void
Processes any tokens registered with registerSupplementary().
registerSupplementary()  : array<string|int, int>
Registers any supplementary tokens that this test might wish to process.
createSkipPattern()  : array<string|int, mixed>
Creates a skip pattern.
createTokenPattern()  : array<string|int, mixed>
Creates a token pattern.
getListenerTokenPos()  : int
Returns the position in the pattern that this test should register as a listener for the pattern.
getPatternTokenTypes()  : array<int, int>
Returns the token types that the specified pattern is checking for.
parse()  : array<string|int, mixed>
Parses a pattern string into an array of pattern steps.

Properties

$ignoreComments

If true, comments will be ignored if they are found in the code.

public bool $ignoreComments = false

$errorPos

Positions in the stack where errors have occurred.

private array<int, bool> $errorPos = []

$parsedPatterns

The parsed patterns array.

private array<string|int, mixed> $parsedPatterns = []

$supplementaryTokens

Tokens that this sniff wishes to process outside of the patterns.

private array<string|int, int> $supplementaryTokens = []
Tags
see
registerSupplementary()
processSupplementary()

Methods

__construct()

Constructs a AbstractPatternSniff.

public __construct([bool $ignoreComments = null ]) : mixed
Parameters
$ignoreComments : bool = null

If true, comments will be ignored.

process()

Processes the test.

public final process(File $phpcsFile, int $stackPtr) : void
Parameters
$phpcsFile : File

The PHP_CodeSniffer file where the token occurred.

$stackPtr : int

The position in the tokens stack where the listening token type was found.

Tags
see
register()

register()

Registers the tokens to listen to.

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

Classes extending AbstractPatternTest should implement the getPatterns() method to register the patterns they wish to test.

Tags
see
process()
Return values
array<string|int, int|string>

getPatterns()

Returns the patterns that should be checked.

protected abstract getPatterns() : array<string|int, string>
Return values
array<string|int, string>

prepareError()

Prepares an error for the specified patternCode.

protected prepareError(string $found, string $patternCode) : string
Parameters
$found : string

The actual found string in the code.

$patternCode : string

The expected pattern code.

Return values
string —

The error message.

processPattern()

Processes the pattern and verifies the code at $stackPtr.

protected processPattern(array<string|int, mixed> $patternInfo, File $phpcsFile, int $stackPtr) : array<string|int, mixed>|false
Parameters
$patternInfo : array<string|int, mixed>

Information about the pattern used for checking, which includes are parsed token representation of the pattern.

$phpcsFile : File

The PHP_CodeSniffer file where the token occurred.

$stackPtr : int

The position in the tokens stack where the listening token type was found.

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

processSupplementary()

Processes any tokens registered with registerSupplementary().

protected processSupplementary(File $phpcsFile, int $stackPtr) : void
Parameters
$phpcsFile : File

The PHP_CodeSniffer file where to process the skip.

$stackPtr : int

The position in the tokens stack to process.

Tags
see
registerSupplementary()

registerSupplementary()

Registers any supplementary tokens that this test might wish to process.

protected registerSupplementary() : array<string|int, int>

A sniff may wish to register supplementary tests when it wishes to group an arbitrary validation that cannot be performed using a pattern, with other pattern tests.

Tags
see
processSupplementary()
Return values
array<string|int, int>

createSkipPattern()

Creates a skip pattern.

private createSkipPattern(string $pattern, int $from) : array<string|int, mixed>
Parameters
$pattern : string

The pattern being parsed.

$from : int

The token position that the skip pattern starts from.

Tags
see
createTokenPattern()
parse()
Return values
array<string|int, mixed> —

The pattern step.

createTokenPattern()

Creates a token pattern.

private createTokenPattern(string $str) : array<string|int, mixed>
Parameters
$str : string

The tokens string that the pattern should match.

Tags
see
createSkipPattern()
parse()
Return values
array<string|int, mixed> —

The pattern step.

getListenerTokenPos()

Returns the position in the pattern that this test should register as a listener for the pattern.

private getListenerTokenPos(array<string|int, mixed> $pattern) : int
Parameters
$pattern : array<string|int, mixed>

The pattern to acquire the listener for.

Tags
throws
RuntimeException

If we could not determine a token to listen for.

Return values
int —

The position in the pattern that this test should register as the listener.

getPatternTokenTypes()

Returns the token types that the specified pattern is checking for.

private getPatternTokenTypes(array<string|int, mixed> $pattern) : array<int, int>

Returned array is in the format: array( T_WHITESPACE => 0, // 0 is the position where the T_WHITESPACE token // should occur in the pattern. );

Parameters
$pattern : array<string|int, mixed>

The parsed pattern to find the acquire the token types from.

Return values
array<int, int>

parse()

Parses a pattern string into an array of pattern steps.

private parse(string $pattern) : array<string|int, mixed>
Parameters
$pattern : string

The pattern to parse.

Tags
see
createSkipPattern()
createTokenPattern()
Return values
array<string|int, mixed> —

The parsed pattern array.

On this page

Search results