← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Lazy Class

Code Quality Beginner
debt(d7/e3/b3/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints indicate tools like phpmd and phpstan can flag some cases, but automated detection is explicitly marked 'no' — these tools can surface candidates but cannot reliably confirm a class is truly 'lazy' without human judgment about intent and context. A reviewer must assess whether the abstraction is genuinely unjustified.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix (replace pattern with safer alternative)' (e3). The quick_fix is 'inline the lazy class into its only caller,' which is typically a small, localised refactor — collapsing one class into one caller. It touches the class file and its single caller, but rarely spreads further.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax (one component pays, rest of codebase unaffected)' (b3). A lazy class adds indirection and an extra file to navigate, but its reach is inherently limited by its definition — it has few callers and little logic. The burden is real but constrained to the immediate area of the codebase.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The misconception is 'every abstraction justifies its own class,' which is a widely held OOP belief that leads developers to create lazy classes in good faith, especially under YAGNI pressure. Competent developers trained in OOP instinctively reach for a class and genuinely do not recognise the smell until they've been burned by navigational overhead.

About DEBT scoring →

Also Known As

lazy class smell unnecessary class under-used class

TL;DR

A class that doesn't do enough to justify its existence — the cost of understanding it exceeds the value it provides.

Explanation

Lazy Class is the inverse of God Class: a class so small or trivial that it adds complexity without adding value. It may be the remnant of planned functionality that was never completed, or a class created through over-engineering that could simply be a method, a constant, or data on another class. The fix is either to inline the class into its caller (if it has one consumer) or to merge it with a related class that would benefit from its functionality.

Common Misconception

Every abstraction justifies its own class. A class that does so little it barely earns its existence adds navigation overhead — if its logic would fit clearly inside the caller or a simpler structure, collapse it.

Why It Matters

A class that does too little to justify its existence adds indirection without value — it increases the number of files developers must understand without providing meaningful abstraction.

Common Mistakes

  • Creating a class to wrap a single function call — a plain function or static method is clearer.
  • Abstract classes with only one concrete subclass — inline the subclass or make the abstract concrete.
  • Data transfer objects that are never validated or enriched — use an array or typed array instead.
  • Classes created 'for future extensibility' without a current use case — YAGNI applies.

Code Examples

✗ Vulnerable
// Class with a single trivial method — doesn't justify its existence
class StringHelper {
    public function upper(string $s): string { return strtoupper($s); }
}
✓ Fixed
// Just call strtoupper() directly
// A class is justified when it encapsulates state + meaningful behaviour:
class CurrencyFormatter {
    public function __construct(private string $locale, private string $currency) {}
    public function format(int $cents): string {
        return NumberFormatter::create($this->locale, NumberFormatter::CURRENCY)
            ->formatCurrency($cents / 100, $this->currency);
    }
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 88
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings S 0 pings M 2 pings T 0 pings W 1 ping T 1 ping F 0 pings S 0 pings S 0 pings M 1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 1 ping T 1 ping F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M
No pings yet today
Amazonbot 1
Amazonbot 10 Ahrefs 7 Bing 6 PetalBot 6 SEMrush 5 Google 4 ChatGPT 3 Scrapy 3 Brave Search 3 Majestic 2 Perplexity 2 Claude 2 Twitter/X 2 Applebot 2 Meta AI 1 Qwen 1 Unknown AI 1
crawler 54 crawler_json 6
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Inline the lazy class into its only caller — a class that does too little doesn't justify the abstraction overhead; merge thin wrappers that add no value
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Class with only one method and one caller; wrapper class that just delegates with no transformation; PHP class with only 5-10 lines doing nothing interesting
Auto-detectable: ✗ No phpmd phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✓ Auto-fixable Fix: Low Context: Class Tests: Update


✓ schema.org compliant