Unused Function
debt(d5/e1/b3/t3)
Closest to 'specialist tool catches it' (d5). The detection_hints list phpstan, psalm, and php-dead-code — all specialist static analysis tools rather than default linters. The quick_fix notes PHPStan catches unused private methods at level 6+, but public methods require more careful analysis. This firmly places detection at the specialist-tool tier rather than default linter (d3) or review-only (d7).
Closest to 'one-line patch or single-call swap' (e1). The quick_fix is simply deleting the dead function — a single removal action, often in one file. The common_mistakes note that git history preserves old methods so there is no recovery risk. No refactor is needed; the fix is pure deletion.
Closest to 'localised tax' (b3). Unused functions impose a reading and maintenance tax on the files or classes they inhabit, misdirecting developers who encounter them. However, the burden is localised — unused functions in one module do not structurally constrain the rest of the codebase. The applies_to scope covers web/cli/queue contexts but each dead function's tax is self-contained rather than cross-cutting.
Closest to 'minor surprise (one edge case)' (t3). The misconception is that unused methods are fully safe because they never execute. The subtle trap is that they can be invoked via dynamic dispatch or reflection, and they mislead readers into studying or wiring in dead code incorrectly. This is a real but documented and relatively understandable gotcha, not a deep contradiction of developer intuition.
Also Known As
TL;DR
Explanation
Unused private methods are detectable by static analysis and have no legitimate use — remove them. Unused public methods are harder because they may be called dynamically or from outside the codebase, but any that are confirmed unused should also be removed. Dead methods stay in codebases because developers are afraid to delete them ('someone might need it') — version control is the safety net; delete confidently. YAGNI applies: You Aren't Gonna Need It.
Common Misconception
Why It Matters
Common Mistakes
- Keeping methods 'just in case' — git history preserves them; remove now, restore if ever needed.
- Not running dead code detection tools — PHPStan detects unused private methods automatically.
- Unused abstract method implementations left after an interface changed.
- Helper functions added during development that became unnecessary after refactoring.
Code Examples
class OrderService {
public function processOrder(Order $o): void { /* used */ }
private function formatOrderLegacy(Order $o): string {
// Never called anywhere — dead code
return $o->id . '-' . $o->total;
}
private function validateOrderV1(array $data): bool {
// Replaced by validateOrder() — never called
return isset($data['id']);
}
}
// Remove unused private methods — git preserves the history:
class OrderService {
public function processOrder(Order $o): void { /* used */ }
// formatOrderLegacy() removed — was never called
// validateOrderV1() removed — replaced by validateOrder()
}