A switch or match lists the same value twice

tx0/php:duplicate-casedefaultwarningreliability/control-flowdepth fastbug

What it finds

case 'a': ... case 'a': and match ($x) { 1 => ..., 1 => ... }: a value listed twice in one switch or match can only reach the first of its arms; the second is dead, and usually stands for a value that was meant instead.

From the rule's source, duplicate_case.rs.

Example from the rule's tests
<?phpfunction label($status){    switch ($status) {        case 'open':            return 1;        case 'closed':            return 2;        case 'open':tx0 reports: 'open' is listed twice            return 3;    }    return match ($status) {        1, 2 => 'low',        3 => 'mid',        2 => 'again',tx0 reports: 2 is listed twice        default => 'other',    };}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/php:duplicate-case" = "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:duplicate-case] reason="..."

tx0 explain tx0/php:duplicate-case shows the same in the terminal. Found a false positive? Report it.