← Home ← Codex ← DEBT ← Engine
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 200
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings S 0 pings S 0 pings M 0 pings T 1 ping 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 0 pings T 0 pings 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 0 pings F 0 pings S 0 pings S
No pings yet today
No pings yesterday
Scrapy 22 Ahrefs 15 Amazonbot 14 Perplexity 11 Bing 10 Google 9 SEMrush 9 PetalBot 6 Unknown AI 4 ChatGPT 4 Claude 3 Twitter/X 2 Brave Search 2 Applebot 2 Majestic 1 Meta AI 1 Baidu 1
crawler 111 crawler_json 4 pre-tracking 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Lint quality Lint is an automated tool that scans your code for errors, bugs, and style problems without running it. It catches mistakes early, like a spell-checker for code.

Linting catches entire categories of bugs before they reach production or even your test suite. As projects grow, consistent automated checks save hours of manual review and prevent embarrassing mistakes.

💡 Enable your linter in your editor so you see warnings as you type, not after you've written 200 lines.

Ask Codex about Lint →
Regression quality A regression is when code that used to work correctly stops working after a change. Something that was fine yesterday is now broken today.

Every codebase grows, and changes ripple in unexpected ways. Understanding regressions teaches you to test broadly, not just the code you touched, and to value automated test suites that catch breaks before users do.

💡 After any code change, ask: "What else uses this?" and test those paths too.

Ask Codex about Regression →
⚡ 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