php-specialist
Skill0 starsChanged 3 months agoMITView on GitHub
Use when writing modern PHP 8.x code — enums, fibers, readonly properties, PSR standards, Composer, static analysis, SOLID patterns. Trigger conditions: PHP code authoring, enum design, readonly DTO creation, PSR-4 autoloading setup, PHPStan or Psalm configuration, PHP CS Fixer or Pint setup, Composer dependency management, SOLID principle application, type safety improvements, custom exception hierarchies, interface-driven design.
In this repository24 other files it gives its agents.
- in-progress/AGENTS.mdAGENTS.md
- test-skills/AGENTS.mdAGENTS.md
- docx-processingSkill
- email-composerSkill
- fastapi-expertSkill
- fastapiSkill
- frontend-code-reviewSkill
- frontend-testingSkill
- laravel-boostSkill
- laravel-specialistSkill
- migrate-radix-to-baseSkill
- pdf-processingSkill
- python-proSkill
- react-expertSkill
- rust-engineerSkill
- seo-optimizerSkill
- shadcn-code-reviewSkill
- shadcnSkill
- tailwind-v4Skill
- tauri-developmentSkill
- tauri-v2Skill
- typescript-proSkill
- xlsx-processingSkill
- zustand-stateSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 5 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Check for static analysis configuration (phpstan.neon, psalm.xml)
- Distinctive: line 44
Write interfaces first — contracts before concrete classes
- Distinctive: line 46
Use match expressions over switch.
- Distinctive: line 54
Run PHPStan at maximum achievable level (target level 9)
- Very specific: line 56
Verify type coverage — no mixed without justification
- Very specific: line 134
Always commit composer.lock — reproducible installs across environments
- Very specific: line 135
Use ^ (caret) constraints: "laravel/framework": "^12.0" allows minor/patch updates
- Very specific: line 137
Run composer audit in CI to catch known vulnerabilities
- Very specific: line 138
Use composer dump-autoload --classmap-authoritative in production for speed
- Very specific: line 213
Do NOT skip declare(strict_types=1) because "it's just a small script" -- add it everywhere.
- Very specific: line 214
Do NOT use mixed without a comment justifying why a narrower type is impossible.
- Distinctive: line 215
Do NOT suppress PHPStan errors without a written explanation of why the code is correct.
- Very specific: line 216
Do NOT use the service locator pattern (app()) in business logic, even in Laravel.
- Distinctive: line 217
Do NOT skip interfaces for key boundaries because "there's only one implementation" -- there will be two.
- Very specific: line 221
Use mcp__context7__resolve-library-id then mcp__context7__query-docs for up-to-date docs.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PHP Specialist
Overview
Write modern, type-safe, and maintainable PHP 8.x code adhering to PSR standards and SOLID principles. This skill covers the full modern PHP toolchain: language features introduced in PHP 8.0 through 8.4, PSR interoperability standards, Composer dependency management, static analysis with PHPStan and Psalm, coding style enforcement with PHP CS Fixer and Pint, and architectural patterns that leverage the type system for correctness at compile time rather than runtime.
Apply this skill whenever PHP code is being written, reviewed, or refactored in any framework or standalone context.
Multi-Phase Process
Phase 1: Environment Assessment
- Identify PHP version from
composer.json->require.php - Review
composer.jsonfor autoloading strategy (PSR-4 namespaces) - Check for static analysis configuration (
phpstan.neon,psalm.xml) - Identify coding standard tool (
pint.json,.php-cs-fixer.php) - Catalog existing patterns: enums, DTOs, value objects, interfaces
STOP — Do NOT write code without knowing the PHP version and autoloading strategy.
Phase 2: Design
- Define interfaces and contracts before implementations
- Design value objects and DTOs with readonly properties
- Map domain concepts to backed enums where applicable
- Plan exception hierarchy for the domain
- Identify seams for dependency injection
STOP — Do NOT implement without interfaces defined for key boundaries.
Phase 3: Implementation
- Write interfaces first — contracts before concrete classes
- Implement with constructor promotion, readonly properties, union/intersection types
- Use match expressions over switch; named arguments for clarity
- Leverage first-class callable syntax for functional composition
- Apply SOLID principles at every class boundary
STOP — Do NOT skip strict_types declaration in any PHP file.
Phase 4: Quality Assurance
- Run PHPStan at maximum achievable level (target level 9)
- Enforce coding style with PHP CS Fixer or Laravel Pint
- Verify type coverage — no
mixedwithout justification - Review for SOLID violations and code smells
- Confirm Composer autoload is optimized (
--classmap-authoritative)
PHP Version Feature Decision Table
| Feature | Minimum Version | Use When |
| Constructor promotion | 8.0 | Any class with constructor parameters |
| Named arguments | 8.0 | Functions with 3+ params or boolean flags |
| Match expressions | 8.0 | Any switch statement (strict, returns value) |
| Union types | 8.0 | Parameter accepts multiple types |
| Backed enums | 8.1 | Any set of named constants with values |
| Readonly properties | 8.1 | Immutable DTOs, value objects |
| Fibers | 8.1 | Async frameworks (rarely used directly) |
| First-class callables | 8.1 | Functional composition, array_map/filter |
| Readonly classes | 8.2 | All-readonly DTOs (shorthand) |
| DNF types | 8.2 | Complex union + intersection combinations |
| Override attribute | 8.3 | Overriding parent methods (safety check) |
| Property hooks | 8.4 | Computed properties without separate methods |
Modern PHP 8.x Features
Enums (PHP 8.1+)
See REFERENCE.md for code examples.
Readonly Properties and Classes (PHP 8.1 / 8.2)
See REFERENCE.md for code examples.
Constructor Promotion
See REFERENCE.md for code examples.
Named Arguments
See REFERENCE.md for code examples.
Match Expressions
See REFERENCE.md for code examples.
Union and Intersection Types
See REFERENCE.md for code examples.
First-Class Callable Syntax (PHP 8.1+)
See REFERENCE.md for code examples.
Fibers (PHP 8.1+)
See REFERENCE.md for code examples.
PSR Standards
| PSR | Name | Relevance |
| PSR-1 | Basic Coding Standard | Baseline: <?php tag, UTF-8, namespace/class conventions |
| PSR-4 | Autoloading | Map namespaces to directories in composer.json — mandatory |
| PSR-7 | HTTP Message Interfaces | Immutable request/response objects for middleware pipelines |
| PSR-11 | Container Interface | Dependency injection container interoperability |
| PSR-12 | Extended Coding Style | Supersedes PSR-2: formatting, spacing, declarations |
| PSR-15 | HTTP Server Middleware | MiddlewareInterface and RequestHandlerInterface |
| PSR-17 | HTTP Factories | Create PSR-7 objects (RequestFactory, ResponseFactory) |
| PSR-18 | HTTP Client | ClientInterface for interoperable HTTP clients |
PSR-4 Autoloading
See REFERENCE.md for code examples and the directory-mapping rule.
Composer Dependency Management
Essential Commands
| Command | Purpose |
composer require package/name | Add production dependency |
composer require package/name --dev | Add development dependency |
composer update --dry-run | Preview what would change |
composer why package/name | Show why a package is installed |
composer audit | Check for known security vulnerabilities |
composer bump | Update version constraints to installed versions |
composer validate --strict | Validate composer.json and composer.lock |
Best Practices
- Always commit
composer.lock— reproducible installs across environments - Use
^(caret) constraints:"laravel/framework": "^12.0"allows minor/patch updates - Separate dev dependencies: testing, static analysis, and debug tools go in
require-dev - Run
composer auditin CI to catch known vulnerabilities - Use
composer dump-autoload --classmap-authoritativein production for speed
Static Analysis
PHPStan Levels
| Level | What It Checks |
| 0 | Basic: undefined variables, unknown classes, wrong function calls |
| 1 | + possibly undefined variables, unknown methods on $this |
| 2 | + unknown methods on all expressions (not just $this) |
| 3 | + return types verified |
| 4 | + dead code, always-true/false conditions |
| 5 | + argument types of function calls |
| 6 | + missing typehints reported |
| 7 | + union types checked exhaustively |
| 8 | + nullable types checked strictly |
| 9 | + mixed type is forbidden without explicit handling |
PHPStan Configuration
See REFERENCE.md for code examples.
PHP CS Fixer / Pint
See REFERENCE.md for code examples.
For Laravel projects, use Pint with a pint.json preset — it wraps PHP CS Fixer with Laravel-specific defaults.
SOLID Principles in PHP
| Principle | Guideline | PHP Mechanism |
| S — Single Responsibility | One reason to change per class | Action classes, small services |
| O — Open/Closed | Extend behavior without modifying source | Interfaces, strategy pattern, enums |
| L — Liskov Substitution | Subtypes must be substitutable for base types | Covariant returns, contravariant params |
| I — Interface Segregation | Clients depend only on methods they use | Small, focused interfaces |
| D — Dependency Inversion | Depend on abstractions, not concretions | Constructor injection, interface bindings |
Dependency Inversion Example
See REFERENCE.md for code examples.
Error Handling Patterns
Custom Exception Hierarchy
See REFERENCE.md for code examples.
Result Pattern (Error as Value)
See REFERENCE.md for code examples.
Type Safety Patterns
Branded / Opaque Types via Readonly Classes
See REFERENCE.md for code examples.
Generic Collections via PHPStan Annotations
See REFERENCE.md for code examples.
Anti-Patterns / Common Mistakes
| Anti-Pattern | Why It Fails | What To Do Instead |
Using mixed as escape hatch | Holes in type safety net | Narrow with union types or generics |
| Stringly-typed code | Runtime errors from typos | Use backed enums for named constants |
| God classes (many responsibilities) | Untestable, high coupling | Split into Action classes |
| Suppressing static analysis | Hides real bugs | Fix the issue, add @phpstan-ignore only with explanation |
Missing declare(strict_types=1) | Silent type coercion bugs | Add to every PHP file |
| Array-shaped domain data | No IDE support, no type safety | Use readonly DTOs or value objects |
Service locator (app() in logic) | Hidden dependencies, untestable | Constructor injection |
Catching \Exception broadly | Swallows unexpected errors | Catch specific exception types |
| Mutable value objects | Shared state bugs | Use readonly classes, return new instances |
Ignoring composer audit | Known vulnerabilities in production | Run in CI, treat as build failure |
| Deep inheritance (3+ levels) | Fragile base class problem | Prefer composition and interfaces |
Classes not marked final | Unintended extension | Default to final, open only when designed for it |
Anti-Rationalization Guards
- Do NOT skip
declare(strict_types=1)because "it's just a small script" -- add it everywhere. - Do NOT use
mixedwithout a comment justifying why a narrower type is impossible. - Do NOT suppress PHPStan errors without a written explanation of why the code is correct.
- Do NOT use the service locator pattern (
app()) in business logic, even in Laravel. - Do NOT skip interfaces for key boundaries because "there's only one implementation" -- there will be two.
Documentation Lookup (Context7)
Use mcp__context7__resolve-library-id then mcp__context7__query-docs for up-to-date docs. Returned docs override memorized knowledge.
php— for language features, built-in functions, or PHP 8.x syntaxcomposer— for package management, autoloading, or scripts configuration
Integration Points
| Skill | How It Connects |
laravel-specialist | PHP 8.x features power Eloquent casts, enums, readonly DTOs, and typed collections |
senior-backend | SOLID architecture, interface-driven design, error handling patterns |
test-driven-development | PHPUnit/Pest testing with strong type assertions |
clean-code | SOLID, DRY, code smell detection at the PHP level |
security-review | Input validation, type coercion risks, dependency vulnerabilities |
laravel-boost | AI-generated PHP code quality via guidelines and MCP tools |
Skill Type
FLEXIBLE — Adapt the process phases to the scope of work. A single function may need only Phase 3 and 4. A new module or package should follow all four phases. Non-negotiable regardless of scope: declare(strict_types=1), PHPStan compliance at the project's configured level, and PSR-4 autoloading.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

