Every branch of a conditional does the same
What it finds
if ($c) { f(); } else { f(); } and $c ? $a : $a: when every branch does the same, the condition decides nothing, and one of the branches was probably meant to differ. Empty branches are left to the rules about empty blocks.
From the rule's source, identical_branches.rs.
<?phpfunction pick($flag, $a, $b){ if ($flag) {tx0 reports: every branch of this if does the same log_it($a); } else { log_it($a); } if ($flag) { log_it($a); } else { log_it($b); } if ($flag) { } else { } $x = $flag ? $a : $a;tx0 reports: both results of the conditional are $a $y = $flag ?: $a; return $flag ? $a : $b;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/php:identical-branches" = "off"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:identical-branches] reason="..."tx0 explain tx0/php:identical-branches shows the same in the terminal. Found a false positive? Report it.