ComparisonOperandsOrder
info off by default quick-fixGroup: Code style · PhpStorm name: ComparisonOperandsOrderInspection
Enforces one consistent operand order for equality comparisons against a literal/constant: with the project-wide comparison style set to yoda, the literal must come first (10 === $n); with the regular style (default), the variable part must come first ($n === 10).
Example
Style yoda:
php
<?php
$isZero = $counter === 0;
$isNeg = $delta != -3;
$isOn = $flag == true;
$isUnix = $sep !== "/";
$fileOk = $path <> __FILE__;
// no report
$same = 'a' === $label;
$both = PHP_INT_MAX == 99;
$classes = $mode === Mode::FAST;
$less = $counter < 5;php
<?php
$isZero = 0 === $counter;
$isNeg = -3 != $delta;
$isOn = true == $flag;
$isUnix = "/" !== $sep;
$fileOk = __FILE__ <> $path;
// no report
$same = 'a' === $label;
$both = PHP_INT_MAX == 99;
$classes = $mode === Mode::FAST;
$less = $counter < 5;Reported:
- line 3: Put the constant operand on the left side of the comparison.
- line 4: Put the constant operand on the left side of the comparison.
- line 5: Put the constant operand on the left side of the comparison.
- line 6: Put the constant operand on the left side of the comparison.
- line 7: Put the constant operand on the left side of the comparison.
Options
| Option | Type | Default | Effect |
|---|---|---|---|
| (none) | Driven by the global comparison style setting (comparisonStyle: regular default, or yoda). |
Configure
In custos.json:
json
{
"rules": {
"ComparisonOperandsOrder": {
"enabled": true
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore ComparisonOperandsOrder
/**
* @noinspection ComparisonOperandsOrderInspection
*/