website/errors/logicalOr.alwaysTrue.md
<?php declare(strict_types = 1);
function doFoo(int $i): bool
{
return ($i >= 0) or ($i < 0);
}
PHPStan determined that the result of the or expression is always true. At least one side of the operator is guaranteed to be truthy regardless of the input. In the example above, every integer is either greater than or equal to zero, or less than zero, so the entire expression is always true. This usually indicates a logic error, a redundant check, or dead code.
The or keyword is the low-precedence version of ||. This identifier specifically covers the or keyword; for ||, see booleanOr.alwaysTrue.
Fix the logic to produce a meaningful condition:
<?php declare(strict_types = 1);
function doFoo(int $i): bool
{
- return ($i >= 0) or ($i < 0);
+ return ($i >= 0) or ($i === -1);
}
Or simplify the expression if the result is intentionally always true:
<?php declare(strict_types = 1);
-function doFoo(int $i): bool
+function doFoo(int $i): true
{
- return ($i >= 0) or ($i < 0);
+ return true;
}