Documentation

ControlStructureSpacingSniff extends Sniff

FinalYes

Checks that control structures have the correct spacing around brackets, based upon Squiz code.

Tags
since
0.1.0
since
2013-06-11

This sniff no longer supports JS.

since
0.3.0

This sniff now has the ability to fix most errors it flags.

since
0.7.0

This class now extends the WordPressCS native Sniff class.

since
0.13.0

Class name changed: this class is now namespaced.

since
3.0.0

Checks related to function declarations have been removed from this sniff.

Last synced with base class 2021-11-20 at commit 7f11ffc8222b123c06345afd3261221561c3bb29. Note: This class has diverged quite far from the original. All the same, checking occasionally to see if there are upstream fixes made from which this sniff can benefit, is warranted.

link
https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php

Table of Contents

Properties

$blank_line_after_check  : bool
Check for blank lines after control structures.
$blank_line_check  : bool
Check for blank lines on start/end of control structures.
$space_before_colon  : string
Require for space before T_COLON when using the alternative syntax for control structures.
$phpcsFile  : File
The current file being sniffed.
$tokens  : array<string|int, mixed>
The list of tokens in the current file being sniffed.
$ignore_extra_space_after_open_paren  : array<string|int, mixed>
Tokens for which to ignore extra space on the inside of parenthesis.

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.

Properties

$space_before_colon

Require for space before T_COLON when using the alternative syntax for control structures.

public string $space_before_colon = 'required'

one of 'required', 'forbidden', 'optional'

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

Tokens for which to ignore extra space on the inside of parenthesis.

private array<string|int, mixed> $ignore_extra_space_after_open_paren = array(\T_DO => true, \T_ELSE => true, \T_TRY => true, \T_FINALLY => true)

For do / else / try / finally, there are no parenthesis, so skip it.

Tags
since
0.11.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.

register()

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

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

        
On this page

Search results