agentleFS
peakdong68peakdong68/my-skills/skills/php-specialist/SKILL.md

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.

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
  1. Very specific:

    Check for static analysis configuration (phpstan.neon, psalm.xml)

    line 26
  2. Distinctive:

    Write interfaces first — contracts before concrete classes

    line 44
  3. Distinctive:

    Use match expressions over switch.

    line 46
  4. Distinctive:

    Run PHPStan at maximum achievable level (target level 9)

    line 54
  5. Very specific:

    Verify type coverage — no mixed without justification

    line 56
  6. Very specific:

    Always commit composer.lock — reproducible installs across environments

    line 134
  7. Very specific:

    Use ^ (caret) constraints: "laravel/framework": "^12.0" allows minor/patch updates

    line 135
  8. Very specific:

    Run composer audit in CI to catch known vulnerabilities

    line 137
  9. Very specific:

    Use composer dump-autoload --classmap-authoritative in production for speed

    line 138
  10. Very specific:

    Do NOT skip declare(strict_types=1) because "it's just a small script" -- add it everywhere.

    line 213
  11. Very specific:

    Do NOT use mixed without a comment justifying why a narrower type is impossible.

    line 214
  12. Distinctive:

    Do NOT suppress PHPStan errors without a written explanation of why the code is correct.

    line 215
  13. Very specific:

    Do NOT use the service locator pattern (app()) in business logic, even in Laravel.

    line 216
  14. Distinctive:

    Do NOT skip interfaces for key boundaries because "there's only one implementation" -- there will be two.

    line 217
  15. Very specific:

    Use mcp__context7__resolve-library-id then mcp__context7__query-docs for up-to-date docs.

    line 221

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. Identify PHP version from composer.json -> require.php
  2. Review composer.json for autoloading strategy (PSR-4 namespaces)
  3. Check for static analysis configuration (phpstan.neon, psalm.xml)
  4. Identify coding standard tool (pint.json, .php-cs-fixer.php)
  5. Catalog existing patterns: enums, DTOs, value objects, interfaces

STOP — Do NOT write code without knowing the PHP version and autoloading strategy.

Phase 2: Design

  1. Define interfaces and contracts before implementations
  2. Design value objects and DTOs with readonly properties
  3. Map domain concepts to backed enums where applicable
  4. Plan exception hierarchy for the domain
  5. Identify seams for dependency injection

STOP — Do NOT implement without interfaces defined for key boundaries.

Phase 3: Implementation

  1. Write interfaces first — contracts before concrete classes
  2. Implement with constructor promotion, readonly properties, union/intersection types
  3. Use match expressions over switch; named arguments for clarity
  4. Leverage first-class callable syntax for functional composition
  5. Apply SOLID principles at every class boundary

STOP — Do NOT skip strict_types declaration in any PHP file.

Phase 4: Quality Assurance

  1. Run PHPStan at maximum achievable level (target level 9)
  2. Enforce coding style with PHP CS Fixer or Laravel Pint
  3. Verify type coverage — no mixed without justification
  4. Review for SOLID violations and code smells
  5. Confirm Composer autoload is optimized (--classmap-authoritative)

PHP Version Feature Decision Table

FeatureMinimum VersionUse When
Constructor promotion8.0Any class with constructor parameters
Named arguments8.0Functions with 3+ params or boolean flags
Match expressions8.0Any switch statement (strict, returns value)
Union types8.0Parameter accepts multiple types
Backed enums8.1Any set of named constants with values
Readonly properties8.1Immutable DTOs, value objects
Fibers8.1Async frameworks (rarely used directly)
First-class callables8.1Functional composition, array_map/filter
Readonly classes8.2All-readonly DTOs (shorthand)
DNF types8.2Complex union + intersection combinations
Override attribute8.3Overriding parent methods (safety check)
Property hooks8.4Computed 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

PSRNameRelevance
PSR-1Basic Coding StandardBaseline: <?php tag, UTF-8, namespace/class conventions
PSR-4AutoloadingMap namespaces to directories in composer.json — mandatory
PSR-7HTTP Message InterfacesImmutable request/response objects for middleware pipelines
PSR-11Container InterfaceDependency injection container interoperability
PSR-12Extended Coding StyleSupersedes PSR-2: formatting, spacing, declarations
PSR-15HTTP Server MiddlewareMiddlewareInterface and RequestHandlerInterface
PSR-17HTTP FactoriesCreate PSR-7 objects (RequestFactory, ResponseFactory)
PSR-18HTTP ClientClientInterface for interoperable HTTP clients

PSR-4 Autoloading

See REFERENCE.md for code examples and the directory-mapping rule.

Composer Dependency Management

Essential Commands

CommandPurpose
composer require package/nameAdd production dependency
composer require package/name --devAdd development dependency
composer update --dry-runPreview what would change
composer why package/nameShow why a package is installed
composer auditCheck for known security vulnerabilities
composer bumpUpdate version constraints to installed versions
composer validate --strictValidate 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 audit in CI to catch known vulnerabilities
  • Use composer dump-autoload --classmap-authoritative in production for speed

Static Analysis

PHPStan Levels

LevelWhat It Checks
0Basic: 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

PrincipleGuidelinePHP Mechanism
S — Single ResponsibilityOne reason to change per classAction classes, small services
O — Open/ClosedExtend behavior without modifying sourceInterfaces, strategy pattern, enums
L — Liskov SubstitutionSubtypes must be substitutable for base typesCovariant returns, contravariant params
I — Interface SegregationClients depend only on methods they useSmall, focused interfaces
D — Dependency InversionDepend on abstractions, not concretionsConstructor 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-PatternWhy It FailsWhat To Do Instead
Using mixed as escape hatchHoles in type safety netNarrow with union types or generics
Stringly-typed codeRuntime errors from typosUse backed enums for named constants
God classes (many responsibilities)Untestable, high couplingSplit into Action classes
Suppressing static analysisHides real bugsFix the issue, add @phpstan-ignore only with explanation
Missing declare(strict_types=1)Silent type coercion bugsAdd to every PHP file
Array-shaped domain dataNo IDE support, no type safetyUse readonly DTOs or value objects
Service locator (app() in logic)Hidden dependencies, untestableConstructor injection
Catching \Exception broadlySwallows unexpected errorsCatch specific exception types
Mutable value objectsShared state bugsUse readonly classes, return new instances
Ignoring composer auditKnown vulnerabilities in productionRun in CI, treat as build failure
Deep inheritance (3+ levels)Fragile base class problemPrefer composition and interfaces
Classes not marked finalUnintended extensionDefault 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 mixed without 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 syntax
  • composer — for package management, autoloading, or scripts configuration

Integration Points

SkillHow It Connects
laravel-specialistPHP 8.x features power Eloquent casts, enums, readonly DTOs, and typed collections
senior-backendSOLID architecture, interface-driven design, error handling patterns
test-driven-developmentPHPUnit/Pest testing with strong type assertions
clean-codeSOLID, DRY, code smell detection at the PHP level
security-reviewInput validation, type coercion risks, dependency vulnerabilities
laravel-boostAI-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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.