A statement follows a return, throw, exit, break or continue in the same block

tx0/php:unreachable-codedefaultwarningreliability/control-flowdepth fastbug

What it finds

A statement right after return, throw, exit, break, continue or goto in the same block never runs. It is often left over from an edit, or the jump was meant to be conditional. Declarations of functions and classes are hoisted and still take effect, a label can be reached by goto, and inline HTML and a break after a return in a switch, a common habit, are left alone, so none of them is reported.

From the rule's source, unreachable_code.rs.

Example from the rule's tests
<?phpfunction first($items){    foreach ($items as $item) {        if ($item) {            continue;            log_it($item);tx0 reports: this statement can never run        }    }    return 1;    cleanup();tx0 reports: this statement can never run} function second($x){    switch ($x) {        case 1:            return 1;            break;        case 2:            break;            $x++;tx0 reports: this statement can never run        default:            return 2;    }    throw new RuntimeException('no');    function helper() {}}
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:unreachable-code" = "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:unreachable-code] reason="..."

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