An else follows a branch that always leaves
What it finds
if ($x) { return 1; } else { ... }: when the if branch ends with return, throw, break or continue, the else is not needed, and its code can move up one level.
From the rule's source, else_after_jump.rs.
<?phpfunction sign($n){ if ($n < 0) { return -1; } else {tx0 reports: this else follows a branch that always leaves $n = abs($n); } if ($n > 9) { $n = 9; } else { $n = 0; } return $n;} Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/php:else-after-jump" = "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:else-after-jump] reason="..."tx0 explain tx0/php:else-after-jump shows the same in the terminal. Found a false positive? Report it.