Documentation

ArrayBraceSpacingSniff
in package
implements Sniff

FinalYes

Enforce consistent spacing for the open/close braces of arrays.

The sniff allows for having different settings for:

  • space between the array keyword and the open parenthesis for long arrays;
  • spaces on the inside of the braces for single-line arrays;
  • spaces on the inside of the braces for multi-line arrays;
  • spaces on the inside of the braces for empty arrays.

Note: If 'newline' is expected and no new line is encountered, a new line will be added, but no assumptions will be made about the intended indentation of the code. This should be handled by a (separate) indentation sniff.

Tags
since
1.0.0

Table of Contents

Interfaces

Sniff

Properties

$keywordSpacing  : int|false
Number of spaces which should be between the `array` keyword and the open parenthesis for long arrays.
$spacesMultiLine  : string|int|false
Number of spaces which should be on the inside of array braces for a multi-line array.
$spacesSingleLine  : int|false
Number of spaces which should be on the inside of array braces for a single-line array.
$spacesWhenEmpty  : string|int|false
Number of spaces to enforce between the braces for an empty array.

Methods

process()  : void
Processes this test when one of its tokens is encountered.
register()  : array<string|int, int|string>
Returns an array of tokens this test wants to listen for.

Properties

$keywordSpacing

Number of spaces which should be between the `array` keyword and the open parenthesis for long arrays.

public int|false $keywordSpacing = 0

Accepted values:

  • (int) number of spaces.
  • or false to turn this check off.

Defaults to 0 spaces.

Tags
since
1.0.0

$spacesMultiLine

Number of spaces which should be on the inside of array braces for a multi-line array.

public string|int|false $spacesMultiLine = 'newline'

Accepted values:

  • (string) 'newline'
  • (int) number of spaces.
  • or false to turn this check off.

Defaults to 'newline'.

Tags
since
1.0.0

$spacesSingleLine

Number of spaces which should be on the inside of array braces for a single-line array.

public int|false $spacesSingleLine = 0

Accepted values:

  • (int) number of spaces.
  • or false to turn this check off.

Defaults to 0 spaces.

Tags
since
1.0.0

$spacesWhenEmpty

Number of spaces to enforce between the braces for an empty array.

public string|int|false $spacesWhenEmpty = 0

Accepted values:

  • (string) 'newline'
  • (int) number of spaces.
  • or false to turn this check off.

Defaults to 0 spaces.

Tags
since
1.0.0

Methods

process()

Processes this test when one of its tokens is encountered.

public process(File $phpcsFile, int $stackPtr) : void
Parameters
$phpcsFile : File

The PHP_CodeSniffer file where the token was found.

$stackPtr : int

The position in the PHP_CodeSniffer file's token stack where the token was found.

Tags
since
1.0.0

register()

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

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

        
On this page

Search results