Documentation

ArrayDeclarationSpacingSniff extends Sniff

FinalYes

Enforces WordPress array spacing format.

  • Checks that arrays with explicit keys are multi-line.
  • Checks that each array item in a multi-line array starts on a new line.
Tags
link
https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#indentation
since
0.11.0
  • The WordPress specific additional checks have now been split off from the WordPress.Arrays.ArrayDeclaration sniff into this sniff.
  • Added sniffing & fixing for arrays with explicit keys.
0.12.0

Decoupled this sniff from the upstream sniff completely. This sniff now extends the WordPressCS native Sniff class instead.

0.13.0

Added the last remaining checks from the WordPress.Arrays.ArrayDeclaration sniff which were not covered elsewhere. The WordPress.Arrays.ArrayDeclaration sniff has now been deprecated.

0.13.0

Class name changed: this class is now namespaced.

0.14.0

Single item arrays with explicit keys are now by default exempt from the "must be multi-line" rule. This behavior can be changed using the allow_single_item_single_line_associative_arrays property.

3.0.0

Removed various whitespace related checks and fixers in favor of the PHPCSExtra NormalizedArrays.Arrays.ArrayBraceSpacing sniff.

3.4.0

The allow_single_item_single_line_associative_arrays property has been deprecated in favor of the new allow_single_item_single_line_explicit_key_arrays property.

Table of Contents

Properties

$allow_single_item_single_line_associative_arrays  : bool
Whether or not to allow single item arrays with explicit keys to be single line.
$allow_single_item_single_line_explicit_key_arrays  : bool
Whether to allow single item arrays with explicit keys to be single line.
$phpcsFile  : File
The current file being sniffed.
$tokens  : array<string|int, mixed>
The list of tokens in the current file being sniffed.

Methods

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.
process_multi_line_array()  : void
Process a multi-line array.
process_single_line_array()  : void
Check that arrays with explicit keys are always multi-line.

Properties

$allow_single_item_single_line_associative_arrays

Whether or not to allow single item arrays with explicit keys to be single line.

Use $allow_single_item_single_line_explicit_key_arrays instead.

public bool $allow_single_item_single_line_associative_arrays = true

Defaults to true.

Tags
since
0.14.0

$allow_single_item_single_line_explicit_key_arrays

Whether to allow single item arrays with explicit keys to be single line.

public bool $allow_single_item_single_line_explicit_key_arrays = true

Defaults to true.

Tags
since
3.4.0

$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

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.

Tags
since
0.12.0

The actual checks contained in this method used to be in the processSingleLineArray() method.

register()

Returns an array of tokens this test wants to listen for.

public register() : array<string|int, mixed>
Tags
since
0.12.0
Return values
array<string|int, mixed>

process_multi_line_array()

Process a multi-line array.

protected process_multi_line_array(int $stackPtr, int $opener) : void
Parameters
$stackPtr : int

The position of the current token in the stack.

$opener : int

The position of the array opener.

Tags
since
0.13.0

The actual checks contained in this method used to be in the ArrayDeclaration sniff.

3.0.0

Removed the $closer parameter.

process_single_line_array()

Check that arrays with explicit keys are always multi-line.

protected process_single_line_array(int $stackPtr, int $opener, int $closer) : void
Parameters
$stackPtr : int

The position of the current token in the stack.

$opener : int

The position of the array opener.

$closer : int

The position of the array closer.

Tags
since
0.13.0

The actual checks contained in this method used to be in the process() method.

On this page

Search results