FunctionDeclarationSniff
extends AbstractPatternSniff
in package
Table of Contents
- $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.
- __construct() : mixed
- Constructs a AbstractPatternSniff.
- process() : void
- Processes the test.
- register() : array<string|int, int>
- Registers the tokens to listen to.
- getPatterns() : array<string|int, mixed>
- Returns an array of patterns to check are correct.
- prepareError() : string
- Prepares an error for the specified patternCode.
- processPattern() : array<string|int, mixed>
- 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
$currFile
The current file being checked.
protected
string
$currFile
= ''
$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
Methods
__construct()
Constructs a AbstractPatternSniff.
public
__construct([bool $ignoreComments = null ]) : mixed
Parameters
- $ignoreComments : bool = null
-
If true, comments will be ignored.
Return values
mixed —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
Return values
void —register()
Registers the tokens to listen to.
public
final register() : array<string|int, int>
Classes extending AbstractPatternTest should implement the getPatterns() method to register the patterns they wish to test.
Tags
Return values
array<string|int, int> —getPatterns()
Returns an array of patterns to check are correct.
protected
getPatterns() : array<string|int, mixed>
Return values
array<string|int, mixed> —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>
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> —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
Return values
void —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
Return values
array<string|int, int> —createSkipPattern()
Creates a skip pattern.
private
createSkipPattern(string $pattern, string $from) : array<string|int, mixed>
Parameters
- $pattern : string
-
The pattern being parsed.
- $from : string
-
The token content that the skip pattern starts from.
Tags
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
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
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
Return values
array<string|int, mixed> —The parsed pattern array.