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
Table of Contents
Interfaces
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
METRIC_NAME
Name of the metric.
public
string
METRIC_NAME
= 'Type of and/or operator used'
Tags
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
$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
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
register()
Returns an array of tokens this test wants to listen for.
public
register() : array<string|int, int|string>