A case of a switch is loosely equal to an earlier case, so it can never be reached
What it finds
A case of a switch is loosely equal to an earlier case, so it can never be reached
<?phpswitch ($code) { case 1: $a = 'one'; break; case '1':tx0 reports: '1' equals the earlier case 1 under == $a = 'text one'; break; case '01':tx0 reports: '01' equals the earlier case 1 $a = 'padded'; break; case 'abc': case 'ABC': case '1a': case 2.5: case '2.50':tx0 reports: equals the earlier case 2.5 break;}switch ($flag) { case false: break; case null:tx0 reports: null equals the earlier case false break; case 0:tx0 reports: 0 equals the earlier case false break;}switch ($name) { case 0: case 'a': case '': case 'b': case 'b': break;} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/php:case-equal-to-earlier-case" = "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:case-equal-to-earlier-case] reason="..."tx0 explain tx0/php:case-equal-to-earlier-case shows the same in the terminal. Found a false positive? Report it.