NestedNotOperators
info on by default quick-fixGroup: Code style · PhpStorm name: NestedNotOperatorsInspection
Stacking logical-not operators (!!$x, !!!$x) is a cryptic way to write a boolean cast or a single negation. An even number of ! is a (bool) cast, an odd number is one !.
Example
php
<?php
$ok = !!$token;
$off = !!!$token;
$six = !!!!!!$token;
$both = !!($m > $n);
$neg = !!! ($p instanceof Item);
$wrap = !( !(count($list)) );
$deep = !(!(!(($flag))));
$one = !$token;php
<?php
$ok = (bool)$token;
$off = !$token;
$six = (bool)$token;
$both = (bool)($m > $n);
$neg = !($p instanceof Item);
$wrap = (bool)count($list);
$deep = !$flag;
$one = !$token;Reported:
- line 2: Simplify the stacked negations to '(bool)$token'.
- line 3: Simplify the stacked negations to '!$token'.
- line 4: Simplify the stacked negations to '(bool)$token'.
- line 5: Simplify the stacked negations to '(bool)($m > $n)'.
- line 6: Simplify the stacked negations to '!($p instanceof Item)'.
- line 7: Simplify the stacked negations to '(bool)count($list)'.
- line 8: Simplify the stacked negations to '!$flag'.
Configure
In custos.json:
json
{
"rules": {
"NestedNotOperators": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore NestedNotOperators
/**
* @noinspection NestedNotOperatorsInspection
*/