AbstractArrayAssignmentRestrictionsSniff
extends Sniff
in package
Restricts array assignment of certain keys.
Tags
Table of Contents
Properties
- $exclude : array<string|int, string>
- Exclude groups.
- $groups : array<string, array<string|int, mixed>>
- Groups of variable data to check against.
- $excluded_groups : array<string, bool>
- Cache for the excluded groups information.
- $groups_cache : array<string, array<string|int, mixed>>
- Cache for the group information.
- $phpcsFile : File
- The current file being sniffed.
- $tokens : array<string|int, mixed>
- The list of tokens in the current file being sniffed.
Methods
- callback() : mixed
- Callback to process each confirmed key, to check value.
- getGroups() : array<string, array<string|int, mixed>>
- Groups of variables to restrict.
- process() : int|void
- Set sniff properties and hand off to child class for processing of the token.
- process_token() : void
- Processes this test, when one of its tokens is encountered.
- register() : array<string|int, mixed>
- Returns an array of tokens this test wants to listen for.
- setup_groups() : bool
- Cache the groups.
Properties
$exclude
Exclude groups.
public
array<string|int, string>
$exclude
= array()
Example: 'foo,bar'
Tags
$groups
Groups of variable data to check against.
public
static array<string, array<string|int, mixed>>
$groups
= array()
Don't use this in extended classes, override getGroups() instead. This is only used for Unit tests.
$excluded_groups
Cache for the excluded groups information.
protected
array<string, bool>
$excluded_groups
= array()
Tags
$groups_cache
Cache for the group information.
protected
array<string, array<string|int, mixed>>
$groups_cache
= array()
Tags
$phpcsFile
The current file being sniffed.
protected
File
$phpcsFile
Tags
$tokens
The list of tokens in the current file being sniffed.
protected
array<string|int, mixed>
$tokens
Tags
Methods
callback()
Callback to process each confirmed key, to check value.
public
abstract callback(string $key, mixed $val, int $line, array<string|int, mixed> $group) : mixed
This method must be extended to add the logic to check assignment value.
Parameters
- $key : string
-
Array index / key.
- $val : mixed
-
Assigned value.
- $line : int
-
Token line.
- $group : array<string|int, mixed>
-
Group definition.
Return values
mixed —FALSE if no match, TRUE if matches, STRING if matches with custom error message passed to ->process().
getGroups()
Groups of variables to restrict.
public
abstract getGroups() : array<string, array<string|int, mixed>>
This method should be overridden in extending classes.
Example: groups => array( 'groupname' => array( 'type' => 'error' | 'warning', 'message' => 'Descriptive error message. The error message will be passed the $key and $val of the current array assignment.', 'keys' => array( 'key1', 'another_key' ), ) )
Return values
array<string, array<string|int, mixed>>process()
Set sniff properties and hand off to child class for processing of the token.
public
process(File $phpcsFile, int $stackPtr) : int|void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
process_token()
Processes this test, when one of its tokens is encountered.
public
process_token(int $stackPtr) : void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
register()
Returns an array of tokens this test wants to listen for.
public
register() : array<string|int, mixed>
Return values
array<string|int, mixed>setup_groups()
Cache the groups.
protected
setup_groups() : bool
Tags
Return values
bool —True if the groups were setup. False if not.