Documentation

AssignmentInTernaryConditionSniff extends Sniff

FinalYes

Detects variable assignments being made within conditions.

This is a typical code smell and more often than not a comparison was intended.

Note: this sniff does not detect variable assignments in ternaries without parentheses!

Tags
since
0.14.0
since
3.0.0
  • The generic "assignment in condition" logic has been removed from the sniff in favour of the upstream Generic.CodeAnalysis.AssignmentInCondition sniff.
  • The sniff has been renamed from AssignmentInCondition to AssignmentInTernaryCondition.
link

Upstream sniff.

Table of Contents

Properties

$assignment_tokens  : array<string|int, mixed>
Assignment tokens to trigger on.
$condition_start_tokens  : array<string|int, mixed>
The tokens that indicate the start of a condition.
$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>
Registers the tokens that this sniff wants to listen for.

Properties

$assignment_tokens

Assignment tokens to trigger on.

protected array<string|int, mixed> $assignment_tokens = array()

Set in the register() method.

Tags
since
0.14.0

$condition_start_tokens

The tokens that indicate the start of a condition.

protected array<string|int, mixed> $condition_start_tokens = array()
Tags
since
0.14.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.14.0

register()

Registers the tokens that this sniff wants to listen for.

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

        
On this page

Search results