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

Fan-In / Fan-Out

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

Closest to 'specialist tool catches it' (d5). The detection_hints list phpmetrics, phpmd, and phpstan — all specialist/SAST-class tools that must be explicitly configured and run. High fan-out god classes and high fan-in utility classes are not caught by the compiler or default linter rules; they require deliberate metric analysis.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix acknowledges that high fan-out signals too many responsibilities (requiring responsibility splitting) and high fan-in signals high-risk change propagation. The common_mistakes note that naively reducing fan-out by merging dependencies worsens things, implying the real fix — splitting responsibilities or introducing stable interfaces — touches multiple files and is a non-trivial refactor within or across components.

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

Closest to 'persistent productivity tax' (b5). The term applies across web, cli, and queue-worker contexts. A high fan-in utility module is load-bearing across the codebase (a bug breaks everything), and high fan-out god classes slow down many work streams as they become coordination hubs. However, it does not quite reach b7 because not every change in the codebase is necessarily shaped by a single fan-in/fan-out decision.

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

Closest to 'notable trap' (t5). The misconception field explicitly states the canonical wrong belief: 'High fan-in is always desirable and high fan-out is always bad.' This is a documented gotcha — high fan-in is good for reuse but risky for change impact — that most developers eventually learn. It contradicts an intuitive but oversimplified reading of the metric, earning a t5 rather than a minor edge-case t3.

About DEBT scoring →

Also Known As

fan-in fan-out module coupling metric call graph metric

TL;DR

Fan-in measures how many modules call a given module; fan-out measures how many modules it calls — high fan-out indicates high coupling.

Explanation

Fan-in (afferent coupling) counts how many modules depend on a given module — high fan-in means the module is widely used and changes to it are high-risk. Fan-out (efferent coupling) counts how many modules a given module depends on — high fan-out means the module is tightly coupled to many others and is fragile to external changes. The Instability metric (fan-out / (fan-in + fan-out)) measures how likely a module is to change. Stable, core domain modules should have low instability (high fan-in, low fan-out); infrastructure adapters should have high instability.

Common Misconception

High fan-in is always desirable and high fan-out is always bad. High fan-in means many modules depend on one — it is good for utility modules but means changes to that module have wide impact. Context determines whether high fan-in is a strength or a risk.

Why It Matters

High fan-in (many callers) means a module is widely reused but changes are high-risk. High fan-out (many dependencies) means a module is fragile and complex. Tracking both guides refactoring priorities.

Common Mistakes

  • Not measuring fan-out when adding dependencies to a class — it gradually becomes a coordination hub.
  • High fan-in utility functions with no tests — a bug there breaks everything that depends on it.
  • Confusing fan-out with coupling — fan-out to stable interfaces is less dangerous than fan-out to concrete implementations.
  • Reducing fan-out by merging dependencies rather than splitting responsibilities — lowers fan-out but increases class size.

Code Examples

✗ Vulnerable
// High fan-out — depends on 7+ classes, fragile to changes in any:
class OrderProcessor {
    public function __construct(
        private DB $db, private Mailer $mail, private Logger $log,
        private Cache $cache, private PaymentGateway $pay,
        private InventoryService $inv, private TaxCalculator $tax
    ) {} // Fan-out of 7 — consider splitting responsibilities
}
✓ Fixed
// High fan-out (too many dependencies) makes a class fragile:
class PaymentService {
    // Fan-out of 6 — breaks when any dependency changes
    public function __construct(
        private StripeClient $stripe,
        private PayPalClient $paypal,
        private Logger $logger,
        private Mailer $mailer,
        private MetricsCollector $metrics,
        private FraudDetector $fraud,
    ) {}
}

// Reduce fan-out — group related dependencies:
class PaymentGatewayRegistry { /* wraps stripe + paypal */ }
class PaymentEventHandler    { /* wraps logger + mailer + metrics */ }

class PaymentService { // fan-out of 3
    public function __construct(
        private PaymentGatewayRegistry $gateways,
        private PaymentEventHandler $events,
        private FraudDetector $fraud,
    ) {}
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 60
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W 0 pings T 2 pings F 1 ping S 3 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 1 ping T 0 pings F 2 pings S 1 ping S 0 pings M 1 ping T 0 pings W
No pings yet today
PetalBot 1
Amazonbot 7 Ahrefs 5 ChatGPT 4 SEMrush 4 Scrapy 4 PetalBot 4 Twitter/X 3 Majestic 2 Perplexity 2 Unknown AI 2 Bing 2 Applebot 2 Google 1 Brave Search 1
crawler 39 crawler_json 4
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
High fan-out (your class depends on many others) indicates too many responsibilities; high fan-in (many classes depend on yours) indicates good reusability but also high risk if it changes
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Class with 10+ constructor dependencies (high fan-out god class); utility class touched by half the codebase (high fan-in change risk)
Auto-detectable: ✓ Yes phpmetrics phpmd phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File Tests: Update


✓ schema.org compliant