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

Code Smell

Code Quality Beginner
debt(d3/e5/b5/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). The term lists phpmd, phpcs, phpstan, rector, and phpcpd as detection tools with automated=yes. These are standard PHP quality tools that catch common code smells like long methods, duplicated code, and large classes without requiring specialist configuration.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix lists a catalogue of smells (god class, duplicate code, feature envy, etc.) — addressing these typically requires restructuring methods, extracting classes, or consolidating duplicated logic. This isn't a one-line fix; it's meaningful refactoring work within components.

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

Closest to 'persistent productivity tax' (b5). Code smells apply across all contexts (web, cli, queue-worker) and represent accumulated design debt. The term states 'ignoring them leads to systems where every change risks breaking something else' — this is a persistent drag on velocity across multiple work streams, though not quite system-defining.

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

Closest to 'notable trap' (t5). The misconception field explicitly states the trap: 'A code smell means the code is definitely wrong and must be fixed immediately.' Many developers treat smells as bugs rather than signals requiring investigation. The common_mistakes reinforce this — treating all smells as equally urgent, refactoring without tests, conflating style with structure.

About DEBT scoring →

Also Known As

code smells anti-pattern indicator refactoring trigger

TL;DR

A surface indication in code that usually corresponds to a deeper design problem — not a bug, but a maintainability risk.

Explanation

The term was popularised by Martin Fowler in "Refactoring". A code smell is not necessarily broken — the code may work — but it suggests structural issues that will make the code harder to change safely over time. Common smells: long methods, large classes, long parameter lists, feature envy, data clumps, primitive obsession, and duplicate code. Smells are signals to investigate, not mandates to refactor immediately.

Common Misconception

A code smell means the code is definitely wrong and must be fixed immediately. Smells are indicators that warrant investigation — context matters. A long method in a performance-critical parser may be intentional and correct.

Why It Matters

Code smells are early warning signs of design problems that compound over time — ignoring them leads to systems where every change risks breaking something else. Addressing smells proactively is ten times cheaper than refactoring under pressure.

Common Mistakes

  • Treating all code smells as equally urgent — prioritise smells in frequently-changed, business-critical code.
  • Refactoring smells without tests in place — you need a safety net before restructuring.
  • Conflating code style violations (formatting) with structural smells — they require different remediation.
  • Using smell detection tools as a pass/fail gate rather than a signal to investigate.

Code Examples

✗ Vulnerable
// Multiple smells in one function:
function p($d) {  // cryptic name
    global $db;   // global state
    if($d['t']==1) { // magic number
        $r = $db->query("SELECT * FROM orders WHERE uid=".$d['u']); // SQL injection
        foreach($r as $row) { echo $row['total'] * 0.9; } // magic number
    }
}
✓ Fixed
function applyLoyaltyDiscount(array $request): void {
    $orders   = $this->orderRepo->findByUserId($request['user_id']);
    $discount = LoyaltyDiscount::RATE; // named constant
    foreach ($orders as $order) {
        echo $order->total * (1 - $discount);
    }
}

Added 13 Mar 2026
Edited 22 Mar 2026
Views 85
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 4 pings F 5 pings S 3 pings S 10 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 22 Perplexity 10 Amazonbot 8 Ahrefs 8 SEMrush 5 Google 3 Unknown AI 3 Claude 2 Bing 2 ChatGPT 2 Majestic 1 Meta AI 1
crawler 63 crawler_json 3 pre-tracking 1
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Use the catalogue: long method, god class, duplicate code, feature envy, data clumps, primitive obsession, switch statements, parallel inheritance, lazy class, speculative generality
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Long methods; duplicated code blocks; deeply nested conditionals; large classes with many responsibilities
Auto-detectable: ✓ Yes phpmd phpcs phpstan rector phpcpd
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: High ✗ Manual fix Fix: Medium Context: File Tests: Update


✓ schema.org compliant