Aller au contenu

Deep nesting (ARCH7184)

Ce contenu n’est pas encore disponible dans votre langue.

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.

<?php
function ship(Order $o): void
{
if ($o->isPaid()) {
if ($o->hasStock()) {
if (!$o->isShipped()) {
$this->dispatch($o);
}
}
}
}
<?php
function 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.