Long Method
debt(d3/e3/b5/t5)
Closest to 'default linter catches the common case' (d3). The term's detection_hints list phpcs, phpstan, and rector — phpcs with a line-length or method-length sniff catches oversized methods by default configuration, making this a standard linter-level detection rather than requiring specialist tooling or manual review.
Closest to 'simple parameterised fix' (e3). The quick_fix prescribes extracting commented blocks into named private methods — a mechanical refactor within one component that doesn't require touching multiple files. It's more than a one-line patch (e1) but stays within a single class or file.
Closest to 'persistent productivity tax' (b5). Long methods apply across all PHP contexts (web, cli, queue-worker) and compound over time — each inline addition makes the method harder to test, name, and change safely. The decay flavour is strong: the cost accumulates across many work streams as the method grows and resists modification, but it doesn't yet define the system's shape unless it becomes a god class.
Closest to 'notable trap' (t5). The misconception field directly identifies the canonical wrong belief: 'a long method is fine if it is well-commented.' This is a widely documented gotcha that most developers eventually encounter and learn — comments compensate superficially but do not fix testability, naming, or change-safety. It contradicts a common intuition but is a known, learnable lesson rather than a catastrophic or cross-ecosystem contradiction.
Also Known As
TL;DR
Explanation
Long methods are one of the most common code smells. A method doing many things is hard to name accurately, hard to test in isolation, and hard to reuse. As a rough guide: if you cannot see the entire method without scrolling, it's worth examining. The refactoring is Extract Method — identify a coherent block of lines that does one thing, give it a descriptive name, and move it to a private helper. Good method names make the original method read like a table of contents.
Common Misconception
Why It Matters
Common Mistakes
- Adding logic inline instead of extracting a named method — 'it's only a few lines' compounds over time.
- Methods that handle multiple abstraction levels: high-level orchestration mixed with low-level detail.
- Not using early return to reduce nesting — deep nesting is a long-method symptom.
- Test methods that are as long as the code they test — long tests indicate long production code.
Code Examples
public function checkout(Cart $cart): Receipt {
// validate items (20 lines)
// calculate discounts (15 lines)
// charge card (10 lines)
// send email (15 lines)
// update inventory (10 lines)
// log audit (5 lines)
// 75 lines total
}
public function checkout(Cart $cart): Receipt {
$this->validateItems($cart);
$total = $this->calculateTotal($cart);
$charge = $this->chargeCard($cart->customer, $total);
$receipt = Receipt::create($charge);
$this->mailer->sendReceipt($receipt);
$this->inventory->deduct($cart);
$this->audit->log('checkout', $receipt);
return $receipt;
}