PHP Quality Skill
PHP code quality enforcement: strict types, PSR-12 compliance, modern language features, framework idioms, and static analysis tooling.
Reference Loading Table
| Signal |
Reference |
Size |
| union types, intersection types, DNF, enums, readonly, named arguments, match expression, null-safe operator, PHP 8.0, PHP 8.1, PHP 8.2 |
references/modern-php-features.md |
~160 lines |
| Laravel, Eloquent, Collections, Service Container, Symfony, DI attributes, Event Dispatcher, framework |
references/framework-idioms.md |
~70 lines |
| PHP-CS-Fixer, PHPStan, Psalm, Rector, static analysis, CI, linting, code style, taint analysis |
references/quality-tools.md |
~60 lines |
Load greedily. If the user's question touches any signal keyword, load the matching reference before responding. Multiple signals matching = load all matching references.
Core Rules (Always Apply)
Strict Types Declaration
Every PHP file must begin with declare(strict_types=1). This enforces scalar type coercion rules, catching type errors at call time instead of silently converting values.
<?php
declare(strict_types=1);
// Without strict_types: strlen(123) silently returns 3
// With strict_types: strlen(123) throws TypeError
This is non-negotiable. Omitting it is a code quality defect.
PSR-12 Coding Standard
PSR-12 extends PSR-1 and PSR-2 as the accepted PHP coding style. Key rules:
- 4-space indentation, no trailing whitespace
- One class per file
use statements after namespace with a blank line before and after
- Visibility required on all properties, methods, and constants
- Opening braces on same line for control structures
- Opening braces on next line for classes and methods
Phase 1: ASSESS
Determine what kind of PHP quality review is needed:
| Request type |
Load references |
Action |
| Code review |
All three |
Full quality pass |
| Type system question |
modern-php-features.md |
Feature-specific guidance |
| Framework patterns |
framework-idioms.md |
Idiomatic pattern review |
| Tooling setup |
quality-tools.md |
Config and CI guidance |
Gate: Request classified and relevant references loaded.
Phase 2: REVIEW
Apply loaded reference knowledge to the user's code or question. Every review checks:
declare(strict_types=1) present
- PSR-12 compliance
- Modern PHP features used where appropriate (from references)
- Framework idioms followed (if applicable)
- Quality tooling configured (if applicable)
Gate: Specific, reference-backed feedback provided.
1---2name: php-quality3description: PHP code quality: PSR standards, strict types, framework idioms.4---5
6# PHP Quality Skill
7
8PHP code quality enforcement: strict types, PSR-12 compliance, modern language features, framework idioms, and static analysis tooling.
9
10## Reference Loading Table
11
12| Signal | Reference | Size |
13|--------|-----------|------|
14| union types, intersection types, DNF, enums, readonly, named arguments, match expression, null-safe operator, PHP 8.0, PHP 8.1, PHP 8.2 | `references/modern-php-features.md` | ~160 lines |
15| Laravel, Eloquent, Collections, Service Container, Symfony, DI attributes, Event Dispatcher, framework | `references/framework-idioms.md` | ~70 lines |
16| PHP-CS-Fixer, PHPStan, Psalm, Rector, static analysis, CI, linting, code style, taint analysis | `references/quality-tools.md` | ~60 lines |
17
18**Load greedily.** If the user's question touches any signal keyword, load the matching reference before responding. Multiple signals matching = load all matching references.
19
20---
21
22## Core Rules (Always Apply)
23
24### Strict Types Declaration
25
26Every PHP file must begin with `declare(strict_types=1)`. This enforces scalar type coercion rules, catching type errors at call time instead of silently converting values.
27
28```php
29<?php
30
31declare(strict_types=1);
32
33// Without strict_types: strlen(123) silently returns 3
34// With strict_types: strlen(123) throws TypeError
35```
36
37This is non-negotiable. Omitting it is a code quality defect.
38
39### PSR-12 Coding Standard
40
41PSR-12 extends PSR-1 and PSR-2 as the accepted PHP coding style. Key rules:
42
43- 4-space indentation, no trailing whitespace
44- One class per file
45- `use` statements after namespace with a blank line before and after
46- Visibility required on all properties, methods, and constants
47- Opening braces on same line for control structures
48- Opening braces on next line for classes and methods
49
50---
51
52## Phase 1: ASSESS
53
54Determine what kind of PHP quality review is needed:
55
56| Request type | Load references | Action |
57|-------------|----------------|--------|
58| Code review | All three | Full quality pass |
59| Type system question | `modern-php-features.md` | Feature-specific guidance |
60| Framework patterns | `framework-idioms.md` | Idiomatic pattern review |
61| Tooling setup | `quality-tools.md` | Config and CI guidance |
62
63**Gate**: Request classified and relevant references loaded.
64
65---
66
67## Phase 2: REVIEW
68
69Apply loaded reference knowledge to the user's code or question. Every review checks:
701. `declare(strict_types=1)` present
712. PSR-12 compliance
723. Modern PHP features used where appropriate (from references)
734. Framework idioms followed (if applicable)
745. Quality tooling configured (if applicable)
75
76**Gate**: Specific, reference-backed feedback provided.