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

ABC Metric (Assignments, Branches, Conditions)

Code Quality PHP 5.0+ Advanced
debt(d3/e5/b3/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). Tools like phpmetrics, phploc, and phpmd (listed in detection_hints) can automatically calculate ABC scores and flag violations. These are common static analysis tools in the PHP ecosystem that many teams already use, though not universally enabled by default.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix suggests keeping ABC < 20 via 'extraction and delegation' — this typically means splitting methods, introducing new classes, or restructuring logic. Common_mistakes notes that naively splitting methods doesn't reduce actual complexity, so proper remediation requires thoughtful refactoring beyond simple one-line fixes.

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

Closest to 'localised tax' (b3). ABC metric as a quality gate applies broadly across contexts (web, cli, queue-worker per applies_to), but the metric itself is a measurement tool rather than an architectural choice. High ABC methods create localized maintenance burden — the pain is felt method-by-method rather than system-wide. Addressing it doesn't require rearchitecting the whole system.

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

Closest to 'notable trap' (t5). The misconception field explicitly states developers confuse ABC with cyclomatic complexity, thinking they measure the same thing. Common_mistakes reinforces this: developers may reduce ABC superficially by splitting methods without reducing actual complexity, or treat all branches equally when assignments vs calls have different implications. These are documented gotchas that experienced developers eventually learn.

About DEBT scoring →

Also Known As

ABC score Assignment Branch Condition metric

TL;DR

Code complexity metric using vector magnitude of assignments, branches, and conditions — more expressive than line count.

Explanation

The ABC metric (Jerry Fitzpatrick, 1997) measures method complexity using three independent counts: A = assignments (state changes), B = branches (function/method calls and control transfers), and C = conditions (boolean expressions). The final score is computed as the vector magnitude: sqrt(A^2 + B^2 + C^2). Unlike cyclomatic complexity, which focuses on decision paths, ABC captures how much a method mutates state and delegates work. High A suggests excessive state manipulation, high B indicates heavy delegation or deep call chains, and high C reflects complex logic. Tools like PHPMetrics and PHPLoc report ABC per method. Scores above ~20 should be reviewed; above ~50 typically indicate methods that are difficult to test, reason about, and maintain.

Common Misconception

ABC metric and cyclomatic complexity measure the same thing. Cyclomatic complexity counts independent execution paths, while ABC measures state changes, calls, and conditions — they highlight different risks.

Why It Matters

High ABC scores correlate with fragile, hard-to-test code — reducing ABC improves readability, lowers defect rates, and simplifies refactoring.

Common Mistakes

  • Reducing ABC by splitting methods without reducing actual logic complexity.
  • Ignoring high assignment counts — excessive state mutation is a major maintainability risk.
  • Treating all branches equally — external calls and control flow both increase B but have different implications.
  • Using ABC thresholds blindly without considering domain complexity.

Avoid When

  • Evaluating very small methods where ABC adds little insight.
  • Comparing across different domains without normalising expectations.

When To Use

  • Identifying overly complex or state-heavy methods.
  • Enforcing maintainability thresholds in CI pipelines.

Code Examples

💡 Note
Refactoring reduces assignments and conditions per method, lowering ABC while improving readability and testability.
✗ Vulnerable
// ❌ High ABC — excessive state + branching
function processOrder($order, $user, $coupon, $tax) {
    $total = 0; $discount = 0; $shipping = 0;

    if ($order && $user && $coupon) {
        if ($coupon->valid && $coupon->amount > 0) {
            $discount = $coupon->amount;
        }

        $total = $order->subtotal - $discount + $tax + $shipping;
    }

    return $total;
}
✓ Fixed
// ✅ Lower ABC via decomposition and reduced state
function processOrder($order, $user, $coupon, $tax) {
    if (!$this->isProcessable($order, $user, $coupon)) {
        return 0;
    }

    $discount = $this->calculateDiscount($coupon);

    return $this->calculateTotal($order, $discount, $tax);
}

private function isProcessable($order, $user, $coupon): bool {
    return $order && $user && $coupon;
}

private function calculateDiscount($coupon): float {
    return ($coupon->valid && $coupon->amount > 0)
        ? $coupon->amount
        : 0;
}

private function calculateTotal($order, $discount, $tax): float {
    return $order->subtotal - $discount + $tax;
}

Added 15 Mar 2026
Edited 27 Mar 2026
Views 104
Rate this term
5.0 (1 rating)
🤖 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 3 pings F 0 pings S 1 ping S 5 pings M 0 pings T 0 pings W 1 ping T 1 ping F 1 ping 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 1 ping T 0 pings W
No pings yet today
PetalBot 1
Amazonbot 18 Perplexity 16 Google 7 Scrapy 6 Ahrefs 5 ChatGPT 4 Unknown AI 3 Claude 3 SEMrush 3 Majestic 2 Bing 2 Meta AI 1 PetalBot 1
crawler 67 crawler_json 4
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Medium
⚡ Quick Fix
Keep ABC < 20 per method; reduce assignments and condition chains via extraction and delegation.
📦 Applies To
PHP 5.0+ web cli queue-worker
🔍 Detection Hints
function with many assignments (=), conditions (if/&&/||), and method calls
Auto-detectable: ✓ Yes phpmetrics phploc phpmd
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: Function Tests: Update


✓ schema.org compliant