phanalist

E0024: The “Never-Ending Method” Rule (Lines of Code per Method)

Imagine a method is a single paragraph in a book. If a paragraph is 200 lines long, nobody can follow it. LOC per Method counts how many lines of code are inside a method body.

How the rule works

We count the lines between the opening { and closing } of a concrete method body. Lines containing only opening/closing braces are excluded. The default threshold is 30 lines.


❌ The “Long Method” Example

This method tries to do everything in one place.

public function processOrder(Order $order): void
{
    $this->validate($order);
    $this->checkStock($order);
    // ... 30 more lines doing shipping, billing, notifications ...
    $this->sendConfirmation($order);
}

✅ The “Small Steps” Example (Refactored)

Each method has a single clear responsibility and can be read in seconds.

public function processOrder(Order $order): void
{
    $this->validate($order);
    $this->processPayment($order);
    $this->ship($order);
    $this->notify($order);
}

private function processPayment(Order $order): void { /* 5 lines */ }
private function ship(Order $order): void { /* 8 lines */ }
private function notify(Order $order): void { /* 6 lines */ }

Configuration

rules:
  E0024:
    max_loc: 30

The Junior’s Rule of Thumb:

If Phanalist flags a method for being too long, your method is doing too many things at once. Split it into smaller helper methods named after what they do.