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.
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.
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);
}
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 */ }
rules:
E0024:
max_loc: 30
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.