PHP Quality & Security Tools

Statische Analyse, Code-Style-Prüfung und Security-Scanning für PHP. Stellt Codequalität, PSR-12 Konformität, Typsicherheit und OWASP-Compliance sicher.

PHPStan2.1.33 + Strict Rules
PHP-CS-Fixer3.92.3
Semgrep1.146.0 (OWASP Scanner)
PHPUnit12.5.4
Composer AuditCVE-Check für Dependencies
Installation/opt/php-tools/
Scriptsphp-check.sh, php-style-check.sh, php-test.sh, fix-permissions.sh

Verwendung

# Prüfung (dev)
/opt/scripts/php-check.sh

# Prüfung (beliebiges Projekt)
/opt/scripts/php-check.sh /pfad/zum/projekt

# Mit automatischer Korrektur
/opt/scripts/php-check.sh /pfad/zum/projekt --fix

PHPStan + Strict Rules

Statische Analyse für Typsicherheit, Null-Safety und Bug-Erkennung.

Level5 (von 10)
Strict Rulesphpstan-strict-rules 2.0.7
Konfig/opt/php-tools/phpstan.neon
Scopesrc/, app/ (ohne View/)

PHP-CS-Fixer

Automatische Code-Formatierung nach PSR-12 Standard.

StandardPSR-12
Konfig/opt/php-tools/.php-cs-fixer.php

Regeln

Semgrep (OWASP Security)

Pattern-basierter Security Scanner für OWASP-Vulnerabilities.

Version1.146.0
Konfig/opt/php-tools/semgrep-security.yml
Installation/root/.local/bin/semgrep (pipx)

Erkannte Vulnerabilities

TypOWASPCWE
Cross-Site Scripting (XSS)A03:2021CWE-79
XML External Entity (XXE)A05:2021CWE-611
Server-Side Template Injection (SSTI)A03:2021CWE-1336
Server-Side Request Forgery (SSRF)A10:2021CWE-918
Cross-Site Request Forgery (CSRF)A01:2021CWE-352
Command InjectionA03:2021CWE-78
SQL InjectionA03:2021CWE-89
File InclusionA03:2021CWE-98
Path TraversalA01:2021CWE-22
Eval/Code InjectionA03:2021CWE-94
Unsafe DeserializationA08:2021CWE-502
Header InjectionA03:2021CWE-113
LDAP InjectionA03:2021CWE-90

Direkt ausführen

/root/.local/bin/semgrep scan \
    --config /opt/php-tools/semgrep-security.yml \
    src app

Composer Audit

Prüft Composer-Dependencies auf bekannte CVEs.

composer audit --working-dir=/var/www/dev.campus.systemische-tools.de

PHPUnit

Unit-Testing Framework für PHP mit PHP 8 Attributen.

Version12.5.4
Konfig/opt/php-tools/phpunit.xml
Bootstrap/opt/php-tools/bootstrap.php
Script/opt/scripts/php-test.sh

Verwendung

# Tests ausführen (dev)
/opt/scripts/php-test.sh

# Tests ausführen (beliebiges Projekt)
/opt/scripts/php-test.sh /pfad/zum/projekt

# Mit Coverage-Report
/opt/scripts/php-test.sh /pfad/zum/projekt --coverage

Test-Struktur

tests/
└── Unit/
    └── Domain/
        └── ValueObject/
            └── TaskStatusTest.php

Beispiel-Test

#[CoversClass(TaskStatus::class)]
class TaskStatusTest extends TestCase
{
    #[DataProvider('terminalStatusProvider')]
    public function testIsTerminal(TaskStatus $status, bool $expected): void
    {
        $this->assertSame($expected, $status->isTerminal());
    }
}

Automatisierung

PostToolUse Hook (nach jeder Dateiänderung)

TriggerEdit, Write auf *.php
Script/opt/scripts/php-style-hook.py
PrüfungPHP-CS-Fixer (nur Style)
VerhaltenWarnung, kein Block

Pre-Sync Check (vor Deployment)

Trigger/opt/scripts/sync-dev-prod.sh
PrüfungPHPStan + PHP-CS-Fixer + Composer Audit + Semgrep + PHPUnit
VerhaltenBlockiert bei Fehlern oder fehlgeschlagenen Tests

Prinzipien & Prüfungen

PrinzipBedeutungTool
PSR-12Code StylePHP-CS-Fixer
Type SafetyTypsicherheitPHPStan + Strict Rules
OWASPSecurity VulnerabilitiesSemgrep
CVEDependency VulnerabilitiesComposer Audit
Unit TestsVerhaltens-VerifikationPHPUnit
DRY/KISS/YAGNIClean CodeManuell / Review

Scripts im Detail

php-check.sh

Hauptscript für vollständige Qualitäts- und Sicherheitsprüfung. Führt alle 4 Checks sequentiell aus.

Pfad/opt/scripts/php-check.sh
Default-Projekt/var/www/dev.campus.systemische-tools.de
Exit-Code0 = alle OK, 1 = mindestens ein Fehler

Checks

#CheckPrüftBlockiert bei
1PHPStanTypen, Null-Safety, BugsErrors
2PHP-CS-FixerPSR-12 Code StyleStyle Issues
3Composer AuditDependency CVEsVulnerabilities
4SemgrepOWASP SecuritySecurity Findings

Verwendung

# Dev-Projekt prüfen
/opt/scripts/php-check.sh

# Beliebiges Projekt prüfen
/opt/scripts/php-check.sh /var/www/anderes-projekt

# Mit automatischer Style-Korrektur
/opt/scripts/php-check.sh /var/www/dev.campus.systemische-tools.de --fix

Ausgabe

=== PHP Quality & Security Check: Fri Dec 20 12:00:00 CET 2025 ===
Project: /var/www/dev.campus.systemische-tools.de

[1/4] PHPStan - Static Analysis + Strict Rules
✓ PHPStan: OK

[2/4] PHP-CS-Fixer - Code Style (PSR-12)
✓ PHP-CS-Fixer: OK

[3/4] Composer Audit - Dependency Vulnerabilities
✓ Composer Audit: No vulnerabilities

[4/4] Semgrep - OWASP Security Scan
✓ Semgrep: No vulnerabilities

=== Summary ===
All checks passed!

php-style-check.sh

Schnelle Style-Prüfung für einzelne Dateien. Wird vom PostToolUse Hook verwendet.

Pfad/opt/scripts/php-style-check.sh
VerwendungPostToolUse Hook (nach Edit/Write)
Exit-Code0 = OK, 1 = Style Issues (Warnung)

Verhalten

Verwendung

# Einzelne Datei prüfen
/opt/scripts/php-style-check.sh /var/www/dev.campus.systemische-tools.de/src/Controller/HomeController.php

php-test.sh

PHPUnit Test-Runner für Unit-Tests.

Pfad/opt/scripts/php-test.sh
Default-Projekt/var/www/dev.campus.systemische-tools.de
Tests-Verzeichnistests/
Coverage-Outputcoverage/ (HTML)

Verwendung

# Tests im dev-Projekt
/opt/scripts/php-test.sh

# Tests in anderem Projekt
/opt/scripts/php-test.sh /var/www/anderes-projekt

# Mit Coverage-Report
/opt/scripts/php-test.sh /var/www/dev.campus.systemische-tools.de --coverage

Ausgabe

=== PHP Unit Tests: Fri Dec 20 12:00:00 CET 2025 ===
Project: /var/www/dev.campus.systemische-tools.de

Found 3 test file(s)

PHPUnit 12.5.4

TaskStatus
 ✓ Is terminal with completed returns true
 ✓ Is terminal with failed returns true
 ✓ Is terminal with pending returns false

✓ All tests passed!

fix-permissions.sh

Setzt Dateiberechtigungen für Web-Verzeichnisse zurück.

Pfad/opt/scripts/fix-permissions.sh
Ownerwww-data:www-data
Permissions755 (rwxr-xr-x)

Betroffene Verzeichnisse

Verwendung

# Als root ausführen
sudo /opt/scripts/fix-permissions.sh

Wann verwenden

Script-Übersicht

ScriptZweckWann verwenden
php-check.shVollständige PrüfungVor Deployment, nach größeren Änderungen
php-style-check.shSchnelle Style-PrüfungAutomatisch via Hook
php-test.shUnit-TestsVor Deployment, nach Code-Änderungen
fix-permissions.shBerechtigungenBei Permission-Problemen
python-check.shPython Linting + TypesNach Änderungen an Pipeline-Scripts

Python Quality Tools

Für die KI-Pipeline unter /opt/scripts/pipeline/ stehen zusätzliche Python-Tools bereit.

ToolVersionFunktion
Ruff0.14.10Linting + Formatting (All-in-One)
mypy1.19.1Type Checking

python-check.sh

Prüfscript für Python-Code.

Pfad/opt/scripts/python-check.sh
Default-Verzeichnis/opt/scripts/pipeline
Konfiguration/opt/scripts/pipeline/ruff.toml

Checks

#CheckTool
1Linting (PEP 8, Bugs, Best Practices)Ruff
2FormattingRuff
3Type Checkingmypy

Verwendung

# Prüfung
/opt/scripts/python-check.sh

# Auto-Fix Linting
/opt/scripts/pipeline/venv/bin/ruff check /opt/scripts/pipeline --fix

# Auto-Format
/opt/scripts/pipeline/venv/bin/ruff format /opt/scripts/pipeline