Deep nesting (ARCH7184)
Key php.quality.deep-nesting · Severity warning · Category quality
Deeply nested if/for/while blocks hurt readability and raise cognitive load. Flatten them with early-return guard clauses.
Incorrect
Section titled “Incorrect”<?phpfunction ship(Order $o): void{ if ($o->isPaid()) { if ($o->hasStock()) { if (!$o->isShipped()) { $this->dispatch($o); } } }}Correct
Section titled “Correct”<?phpfunction ship(Order $o): void{ if (!$o->isPaid()) return; if (!$o->hasStock()) return; if ($o->isShipped()) return;
$this->dispatch($o);}Convert conditions into early-return guards to reduce nesting depth.