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

SOLID Principles (Overview)

Code Quality PHP 5.0+ Intermediate
debt(d7/e7/b7/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 explicitly state automated=no, meaning phpstan/psalm/phpcs can flag surface indicators (500+ line classes, new SomeClass() inside methods) but cannot detect true SOLID violations — those require human architectural review. No tool can confirm whether SRP or OCP is genuinely satisfied.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix describes extracting dependencies into interfaces and injecting them through constructors, but SOLID violations typically compound across many classes and layers. Correcting a codebase that ignored SOLID means restructuring multiple interdependent components — not a single-file change. The common_mistakes reinforce that these are systemic patterns, not isolated fixes.

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

Closest to 'strong gravitational pull' (b7). SOLID applies across web, cli, and queue-worker contexts (full applies_to breadth). The principles shape how every class, interface, and dependency is structured. A codebase that violates or misapplies SOLID imposes a persistent productivity tax on every maintainer — every new feature and refactor is shaped by the existing structural choices. Slightly below b9 because it doesn't literally redefine the system's runtime shape.

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

Closest to 'notable trap — a documented gotcha most devs eventually learn' (t5). The misconception field explicitly states the trap: treating SOLID as a strict ruleset rather than contextual guidelines leads to unnecessary complexity (e.g. interfaces for every class). The common_mistakes reinforce this with over-engineering patterns like premature strategy objects and naming-as-SRP. This is a well-documented pitfall but not a contradiction of a similar concept elsewhere, keeping it at t5.

About DEBT scoring →

Also Known As

SOLID principles object-oriented principles OOP principles

TL;DR

Five object-oriented design principles — SRP, OCP, LSP, ISP, DIP — that together guide towards maintainable, extensible code.

Explanation

SOLID is an acronym for five related OO design principles: Single Responsibility (a class has one reason to change), Open/Closed (open for extension, closed for modification), Liskov Substitution (subclasses substitute for base classes), Interface Segregation (many specific interfaces over one general one), and Dependency Inversion (depend on abstractions, not concretions). Applied together they produce loosely coupled, highly cohesive code that is easy to test and extend. They are guidelines, not rules — apply them where they add value.

Common Misconception

SOLID is a strict ruleset to follow literally. It's a set of guidelines for managing change — over-applying them (e.g. creating an interface for every class) produces unnecessary complexity in small codebases.

Why It Matters

SOLID principles prevent the most expensive class of software problems — code that cannot be changed without cascading breakage. Teams that follow SOLID spend far less time debugging regressions and far more time shipping features.

Common Mistakes

  • Treating SOLID as dogma and applying all five principles to simple utility functions — they target complex, change-prone code.
  • Confusing Interface Segregation with having one method per interface — it means interfaces should match client needs, not be maximally small.
  • Implementing Open/Closed by wrapping everything in strategy objects before there is a real extension need.
  • Naming classes *Service or *Manager and calling it SRP — naming does not guarantee single responsibility.

Avoid When

  • Small scripts and one-off utilities — applying all five principles adds abstraction overhead with no maintenance benefit.
  • Applying SOLID dogmatically — creating interfaces for classes that will never have a second implementation is over-engineering.
  • Using SOLID as a checklist rather than guidelines — understanding the problem each principle solves matters more than compliance.

When To Use

  • Long-lived codebases that will be extended by multiple developers over time.
  • Any class that is becoming hard to test — testability problems usually signal a SOLID violation.
  • When adding a new feature requires modifying many existing classes — open-closed principle applies.
  • Library and framework code where consumers need to extend behaviour without modifying your source.

Code Examples

✗ Vulnerable
class Report {
    public function generate() { /* logic */ }
    public function saveToDatabase() { /* DB */ }
    public function exportToPdf() { /* PDF */ }
    public function sendByEmail() { /* mail */ }
    // Violates SRP, OCP, and DIP simultaneously
}
✓ Fixed
class Report {
    public function generate(): ReportData { /* pure logic */ }
}
class ReportExporter {
    public function __construct(private ExporterInterface $exporter) {}
    public function export(ReportData $data): void {
        $this->exporter->export($data);
    }
}

Added 13 Mar 2026
Edited 25 Mar 2026
Views 70
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 3 pings W 0 pings T 2 pings F 3 pings S 3 pings S 4 pings M 0 pings T 0 pings W 3 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings 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
No pings yet today
PetalBot 1
Scrapy 13 Perplexity 9 Amazonbot 7 Google 7 ChatGPT 5 Ahrefs 4 Unknown AI 3 SEMrush 3 Claude 2 Bing 2 Meta AI 1 Sogou 1 PetalBot 1
crawler 52 crawler_json 5 pre-tracking 1
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
When a class is hard to test, it usually violates SRP or DIP — extract dependencies into interfaces and inject them through the constructor
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Class with new SomeClass() inside methods; class handling both business logic and persistence; 500+ line class
Auto-detectable: ✗ No phpstan psalm phpcs
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant