An if condition is a literal
What it finds
if (true) and if (0): a condition that is a literal decides nothing, and the code is a leftover from debugging or a disabled feature that should be removed or behind a real setting. while (true) loops are a common idiom and are left alone.
From the rule's source, constant_condition.rs.
<?phpfunction debug($x){ if (false) {tx0 reports: the condition is the literal false dump($x); } while (true) { break; } if ($x) { return 1; }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/php:constant-condition" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/php:constant-condition] reason="..."tx0 explain tx0/php:constant-condition shows the same in the terminal. Found a false positive? Report it.