PHP Skill
PHP code quality and testing: strict types, PSR-12 compliance, modern language features, framework idioms, static analysis tooling, and PHPUnit testing patterns.
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 |
| PHPUnit tests, data providers, mocks, stubs, database testing, HTTP testing, coverage |
references/testing-patterns.md |
~120 lines |
| quality review process, phases, PSR-12 enforcement |
references/php-quality.md |
~60 lines |
| test writing process, test doubles, Prophecy, database fixtures |
references/php-testing.md |
~50 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. 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:
- 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 work is needed:
| Request type |
Load references |
Action |
| Code review |
quality refs + quality-tools |
Full quality pass |
| Type system question |
modern-php-features |
Feature-specific guidance |
| Framework patterns |
framework-idioms |
Idiomatic pattern review |
| Tooling setup |
quality-tools |
Config and CI guidance |
| Write tests |
testing-patterns + php-testing |
PHPUnit test authoring |
| Test review |
testing-patterns |
Test quality review |
Gate: Request classified and relevant references loaded.
Phase 2: EXECUTE
Apply loaded reference knowledge to the user's code or question.
For quality reviews, check:
declare(strict_types=1) present
- PSR-12 compliance
- Modern PHP features used where appropriate
- Framework idioms followed (if applicable)
- Quality tooling configured (if applicable)
For testing work:
- Use PHPUnit
TestCase with test prefix or @test annotation
- Use
@dataProvider for table-driven cases
- Use
createStub() for return values, createMock() for interaction assertions
- Use
DatabaseTransactions (Laravel) or KernelTestCase (Symfony) for database tests
- Call
parent::setUp() first in every setUp() method
Gate: Specific, reference-backed feedback or code provided.
Phase 3: VERIFY
Run the test suite and confirm:
./vendor/bin/phpunit
# For coverage enforcement:
XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text --coverage-min=80
Gate: All tests pass. Coverage threshold met if configured.
1---2name: php-23description: PHP development: code quality, PSR standards, testing with PHPUnit.4---5
6# PHP Skill
7
8PHP code quality and testing: strict types, PSR-12 compliance, modern language features, framework idioms, static analysis tooling, and PHPUnit testing patterns.
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| PHPUnit tests, data providers, mocks, stubs, database testing, HTTP testing, coverage | `references/testing-patterns.md` | ~120 lines |
18| quality review process, phases, PSR-12 enforcement | `references/php-quality.md` | ~60 lines |
19| test writing process, test doubles, Prophecy, database fixtures | `references/php-testing.md` | ~50 lines |
20
21**Load greedily.** If the user's question touches any signal keyword, load the matching reference before responding. Multiple signals matching = load all matching references.
22
23---
24
25## Core Rules (Always Apply)
26
27### Strict Types Declaration
28
29Every 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. Omitting it is a code quality defect.
30
31### PSR-12 Coding Standard
32
33PSR-12 extends PSR-1 and PSR-2 as the accepted PHP coding style:
34
35- 4-space indentation, no trailing whitespace
36- One class per file
37- `use` statements after namespace with a blank line before and after
38- Visibility required on all properties, methods, and constants
39- Opening braces on same line for control structures
40- Opening braces on next line for classes and methods
41
42---
43
44## Phase 1: ASSESS
45
46Determine what kind of PHP work is needed:
47
48| Request type | Load references | Action |
49|-------------|----------------|--------|
50| Code review | quality refs + quality-tools | Full quality pass |
51| Type system question | modern-php-features | Feature-specific guidance |
52| Framework patterns | framework-idioms | Idiomatic pattern review |
53| Tooling setup | quality-tools | Config and CI guidance |
54| Write tests | testing-patterns + php-testing | PHPUnit test authoring |
55| Test review | testing-patterns | Test quality review |
56
57**Gate**: Request classified and relevant references loaded.
58
59---
60
61## Phase 2: EXECUTE
62
63Apply loaded reference knowledge to the user's code or question.
64
65For quality reviews, check:
661. `declare(strict_types=1)` present
672. PSR-12 compliance
683. Modern PHP features used where appropriate
694. Framework idioms followed (if applicable)
705. Quality tooling configured (if applicable)
71
72For testing work:
731. Use PHPUnit `TestCase` with `test` prefix or `@test` annotation
742. Use `@dataProvider` for table-driven cases
753. Use `createStub()` for return values, `createMock()` for interaction assertions
764. Use `DatabaseTransactions` (Laravel) or `KernelTestCase` (Symfony) for database tests
775. Call `parent::setUp()` first in every `setUp()` method
78
79**Gate**: Specific, reference-backed feedback or code provided.
80
81---
82
83## Phase 3: VERIFY
84
85Run the test suite and confirm:
86
87```bash
88./vendor/bin/phpunit
89# For coverage enforcement:
90XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text --coverage-min=80
91```
92
93**Gate**: All tests pass. Coverage threshold met if configured.