Documentation

DisallowLogicalAndOrSniff
in package
implements Sniff

FinalYes

Enforce the use of the boolean `&&` and `||` operators instead of the logical `and`/`or` operators.

Note: as the operator precedence of the logical operators is significantly lower than the operator precedence of boolean operators, this sniff does not contain an auto-fixer.

Tags
since
1.0.0

Table of Contents

Interfaces

Sniff

Constants

METRIC_NAME  = 'Type of and/or operator used'
Name of the metric.

Properties

$metricType  : array<int|string, string>
The tokens this sniff records metrics for.
$targetTokenInfo  : array<int|string, array<string, string>>
The tokens this sniff targets with error code and replacements.

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.

Constants

Properties

$metricType

The tokens this sniff records metrics for.

private array<int|string, string> $metricType = [\T_LOGICAL_AND => 'logical (and/or)', \T_LOGICAL_OR => 'logical (and/or)', \T_BOOLEAN_AND => 'boolean (&&/||)', \T_BOOLEAN_OR => 'boolean (&&/||)']
Tags
since
1.0.0

$targetTokenInfo

The tokens this sniff targets with error code and replacements.

private array<int|string, array<string, string>> $targetTokenInfo = [\T_LOGICAL_AND => ['error_code' => 'LogicalAnd', 'replacement' => '&&'], \T_LOGICAL_OR => ['error_code' => 'LogicalOr', 'replacement' => '||']]
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 file being scanned.

$stackPtr : int

The position of the current token in the stack passed in $tokens.

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