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 |
Loading rule. Read the references whose signals match the task before responding.
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: php3description: "PHP development: code quality, PSR standards, testing with PHPUnit."4user-invocable: false5context: fork6agent: php-general-engineer7routing:8 triggers:9 - "php quality"10 - "php code review"11 - "PSR standards"12 - "phpstan"13 - "php-cs-fixer"14 - "php testing"15 - "phpunit"16 - "pest php"17 - "php mock"18 category: php19 pairs_with:20 - code-linting21 - test-driven-development22---2324# PHP Skill2526PHP code quality and testing: strict types, PSR-12 compliance, modern language features, framework idioms, static analysis tooling, and PHPUnit testing patterns.2728## Reference Loading Table2930| Signal | Reference | Size |31|--------|-----------|------|32| 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 |33| Laravel, Eloquent, Collections, Service Container, Symfony, DI attributes, Event Dispatcher, framework | `references/framework-idioms.md` | ~70 lines |34| PHP-CS-Fixer, PHPStan, Psalm, Rector, static analysis, CI, linting, code style, taint analysis | `references/quality-tools.md` | ~60 lines |35| PHPUnit tests, data providers, mocks, stubs, database testing, HTTP testing, coverage | `references/testing-patterns.md` | ~120 lines |36| quality review process, phases, PSR-12 enforcement | `references/php-quality.md` | ~60 lines |37| test writing process, test doubles, Prophecy, database fixtures | `references/php-testing.md` | ~50 lines |3839**Loading rule.** Read the references whose signals match the task before responding.4041---4243## Core Rules (Always Apply)4445### Strict Types Declaration4647Every 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.4849### PSR-12 Coding Standard5051PSR-12 extends PSR-1 and PSR-2 as the accepted PHP coding style:5253- 4-space indentation, no trailing whitespace54- One class per file55- `use` statements after namespace with a blank line before and after56- Visibility required on all properties, methods, and constants57- Opening braces on same line for control structures58- Opening braces on next line for classes and methods5960---6162## Phase 1: ASSESS6364Determine what kind of PHP work is needed:6566| Request type | Load references | Action |67|-------------|----------------|--------|68| Code review | quality refs + quality-tools | Full quality pass |69| Type system question | modern-php-features | Feature-specific guidance |70| Framework patterns | framework-idioms | Idiomatic pattern review |71| Tooling setup | quality-tools | Config and CI guidance |72| Write tests | testing-patterns + php-testing | PHPUnit test authoring |73| Test review | testing-patterns | Test quality review |7475**Gate**: Request classified and relevant references loaded.7677---7879## Phase 2: EXECUTE8081Apply loaded reference knowledge to the user's code or question.8283For quality reviews, check:841. `declare(strict_types=1)` present852. PSR-12 compliance863. Modern PHP features used where appropriate874. Framework idioms followed (if applicable)885. Quality tooling configured (if applicable)8990For testing work:911. Use PHPUnit `TestCase` with `test` prefix or `@test` annotation922. Use `@dataProvider` for table-driven cases933. Use `createStub()` for return values, `createMock()` for interaction assertions944. Use `DatabaseTransactions` (Laravel) or `KernelTestCase` (Symfony) for database tests955. Call `parent::setUp()` first in every `setUp()` method9697**Gate**: Specific, reference-backed feedback or code provided.9899---100101## Phase 3: VERIFY102103Run the test suite and confirm:104105```bash106./vendor/bin/phpunit107# For coverage enforcement:108XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text --coverage-min=80109```110111**Gate**: All tests pass. Coverage threshold met if configured.