Quality Gates
Automatische Code-Qualitätsprüfung via Claude Code Hooks mit Task-Integration.
| Status | Aktiv |
|---|---|
| Implementiert | 2025-12-23 (Phase 1+2+3: 2025-12-28) |
| Regeln | 31 BLOCK + 50 WARN = 81 total |
| Task-Integration | Automatisch bei Violations |
Architektur
/var/www/tools/ki-protokoll/claude-hook/
├── hook_dispatcher.py ← Stabiler Einstiegspunkt
├── .env ← DB-Credentials
└── quality/
├── pre_rules.py ← BLOCK-Regeln Dispatcher
├── post_rules.py ← WARN-Regeln Dispatcher
├── pre_rules_guard.py ← P1.x SRP, P4.x OOP
├── pre_rules_mvc.py ← P2.x MVC
├── pre_rules_validation.py ← P3.x PSR
├── pre_rules_layers.py ← P6.x SOLID
├── pre_rules_htmx.py ← HTMX-C1-C5
├── pre_rules_constants.py ← P7.x Magic Numbers
├── pre_rules_deterministic.py ← P8.x Deterministic
├── pre_rules_tests.py ← P14.x Test Isolation
├── pre_rules_python.py ← PP1.x Python
├── rules_quality.py ← W1.x-W6.x Quality
├── rules_security.py ← Security Warnings
├── rules_style.py ← Style Warnings
├── rules_constants.py ← W7.x Magic Numbers
├── rules_failfast.py ← W8.x Fail Fast
├── rules_failsafe.py ← W9.x Fail Safe (Phase 3)
├── rules_tradeoffs.py ← W10.x Trade-offs (Phase 3)
├── rules_leastsurprise.py ← W15.x Least Surprise
├── rules_testisolation.py ← W14.x Test Isolation
├── phpmetrics_check.py ← W13.x Cohesion (Phase 3)
└── task_creator.py ← Violations → Tasks
Prüfungen (15 Prinzipien)
| # | Prüfung | Pre-Hook (BLOCK) | Post-Hook (WARN) |
|---|---|---|---|
| 1 | SRP + KISS | P1.1 Header, P1.2 Müllhalden | W1.1-W1.5 Metriken |
| 2 | MVC + CRUD | P2.1-P2.4 SQL, Trans, echo | W2.1-W2.2 Keywords |
| 3 | PSR + Types | P3.1-P3.4 strict, NS, Return | W3.1, W3.3 Params |
| 4 | OOP | P4.1 Public Property | W4.1-W4.4 Anämie |
| 5 | DRY | - | W5.1-W5.2 Duplikate |
| 6 | SOLID + DIP | P6.1-P6.2 Layer-Imports | W6.1-W6.2 Interface |
| 7 | Constants | P7.1-P7.3 Magic Numbers | W7.1-W7.5 Magic Strings |
| 8 | Deterministic | P8.1-P8.9 time, rand, global | W8.1-W8.5 Fail Fast |
| 9 | Fail Safe | - | W9.1-W9.6 try-finally, cleanup |
| 10 | Trade-offs | - | W10.1-W10.6 ADR, Factory, Cache |
| 13 | Cohesion | - | W13.1-W13.6 LCOM, Coupling |
| 14 | Test Isolation | P14.1-P14.6 Prod-DB, TRUNCATE | W14.1-W14.7 tearDown, sleep |
| 15 | Least Surprise | - | W15.1-W15.6 Getter Side Effects |
Fett = Neu in Phase 3 (2025-12-28)
Phase 3: Neue Regeln
W9.x Fail Safe (WARN)
- W9.1: try-Block mit Ressourcen ohne finally
- W9.2: DB-Operationen ohne Exception-Handling
- W9.3: catch ohne Logging oder Rethrow
- W9.4: Ressourcen-Properties ohne __destruct
- W9.5: exit/die ohne Shutdown-Handler
- W9.6: Connection ohne passenden Close
W10.x Trade-off Documentation (WARN)
- W10.1: Factory Pattern ohne ADR-Referenz
- W10.2: Event-Architektur ohne Dokumentation
- W10.3: Caching ohne Invalidation-Strategie
- W10.4: 3+ Traits ohne Kompositions-Doku
- W10.5: External Service ohne Fehlerbehandlungs-Doku
- W10.6: @deprecated ohne Migrations-Hinweis
W13.x Cohesion (via PHPMetrics)
- W13.1: LCOM > 4 (Low Cohesion)
- W13.2: Afferent Coupling > 10
- W13.3: Efferent Coupling > 15
- W13.4: Sehr stabile Klasse mit vielen Dependents
- W13.5: Methoden-Komplexität CCN > 15
- W13.6: WMC > 50 (Class too complex)
PHPMetrics Integration
# Installation
/opt/php-tools/vendor/bin/phpmetrics
# Analyse ausführen
/opt/php-tools/vendor/bin/phpmetrics --report-json=/tmp/phpmetrics.json /var/www/dev.campus.systemische-tools.de/src
# Cohesion-Check (Hook-Integration)
python3 /var/www/tools/ki-protokoll/claude-hook/quality/phpmetrics_check.py
ADR Template
Für Trade-off Dokumentation: /var/www/dev.campus.systemische-tools.de/docs/templates/adr-template.md
Prinzipien-Abdeckung
| Kategorie | Anzahl | Anteil |
|---|---|---|
| ✅ Gut abgedeckt (≥70%) | 12/15 | 80% |
| ⚠️ Teilweise (30-69%) | 2/15 | 13% |
| ❌ Nicht automatisierbar | 1/15 | 7% |
Detaillierte Dokumentation
- Claude Pre-/Post-Hook Prozess
- Python-Erweiterung
/var/www/dev.campus.systemische-tools.de/docs/codequality/ist-soll-analyse.md