Documentation

ArrayIndentationSniff extends Sniff

FinalYes

Enforces WordPress array indentation for multi-line arrays.

Tags
link
https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#indentation
since
0.12.0
since
0.13.0

Class name changed: this class is now namespaced.

}

Table of Contents

Properties

$tabIndent  : bool
Should tabs be used for indenting?
$phpcsFile  : File
The current file being sniffed.
$tokens  : array<string|int, mixed>
The list of tokens in the current file being sniffed.
$ignore_tokens  : array<string|int, mixed>
Tokens to ignore for subsequent lines in a multi-line array item.
$tab_width  : int
The --tab-width CLI value that is being used.

Methods

process()  : int|void
Set sniff properties and hand off to child class for processing of the token.
process_token()  : int|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.
add_array_alignment_error()  : void
Throw an error and fix incorrect array alignment.
fix_alignment_error()  : void
Fix incorrect array alignment.
get_indentation_size()  : int
Determine the line indentation whitespace.
get_indentation_string()  : string
Create an indentation string.
ignore_token()  : bool
Should the token be ignored ?

Properties

$tabIndent

Should tabs be used for indenting?

public bool $tabIndent = true

If TRUE, fixes will be made using tabs instead of spaces. The size of each tab is important, so it should be specified using the --tab-width CLI argument.

}

$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

$ignore_tokens

Tokens to ignore for subsequent lines in a multi-line array item.

private array<string|int, mixed> $ignore_tokens = array()

Property is set in the register() method.

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) : int|void
Parameters
$stackPtr : int

The position of the current token in the stack.

Return values
int|void

Integer stack pointer to skip forward or void to continue normal file processing.

register()

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

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

add_array_alignment_error()

Throw an error and fix incorrect array alignment.

protected add_array_alignment_error(int $ptr, string $error, string $error_code, int $expected, int $found, string $new_indent) : void
Parameters
$ptr : int

Stack pointer to the first content on the line.

$error : string

Error message.

$error_code : string

Error code.

$expected : int

Expected nr of spaces (tabs translated to space value).

$found : int

Found nr of spaces (tabs translated to space value).

$new_indent : string

Whitespace indent replacement content.

fix_alignment_error()

Fix incorrect array alignment.

protected fix_alignment_error(int $ptr, string $new_indent) : void
Parameters
$ptr : int

Stack pointer to the first content on the line.

$new_indent : string

Whitespace indent replacement content.

get_indentation_size()

Determine the line indentation whitespace.

protected get_indentation_size(int $ptr) : int
Parameters
$ptr : int

Stack pointer to an arbitrary token on a line.

Return values
int

Nr of spaces found. Where necessary, tabs are translated to spaces.

get_indentation_string()

Create an indentation string.

protected get_indentation_string(int $nr) : string
Parameters
$nr : int

Number of spaces the indentation should be.

Return values
string

ignore_token()

Should the token be ignored ?

protected ignore_token(int $ptr) : bool

This method is only intended to be used with the first token on a line for subsequent lines in an multi-line array item.

Parameters
$ptr : int

Stack pointer to the first token on a line.

Return values
bool

        
On this page

Search results