Documentation

AbstractArrayAssignmentRestrictionsSniff extends Sniff

AbstractYes

Restricts array assignment of certain keys.

Tags
since
0.3.0
since
0.10.0

Class became a proper abstract class. This was already the behaviour. Moved the file and renamed the class from \WordPressCS\WordPress\Sniffs\Arrays\ArrayAssignmentRestrictionsSniff to \WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff.

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
since
0.3.0
since
1.0.0

This property now expects to be passed an array. Previously a comma-delimited string was expected.

$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.

$phpcsFile

The current file being sniffed.

protected File $phpcsFile
Tags
since
0.4.0

$tokens

The list of tokens in the current file being sniffed.

protected array<string|int, mixed> $tokens
Tags
since
0.4.0

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
since
0.11.0
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.


        
On this page

Search results