
Php Best Practices
Run a structured PHP 8.x review against 51 PSR/SOLID/type-safety rules matched to the project's Composer PHP constraint.
Overview
PHP Best Practices is an agent skill most often used in Ship (also Build backend edits) that audits PHP code against 51 version-aware rules for PSR standards, SOLID design, and PHP 8.x type safety.
Install
npx skills add https://github.com/asyrafhussin/agent-skills --skill php-best-practicesWhat is this skill?
- 51 rules for modern PHP 8.0–8.5 with version-gated feature tables (union types, enums, readonly classes, etc.)
- Requires detecting PHP version from composer.json and php -v before suggesting syntax
- Covers PSR standards, SOLID principles, and type-system best practices
- Triggers on review PHP, audit PHP, check PHP code, and PHP best practices requests
- Rule prefixes map features to minimum PHP versions (type-, modern-)
- 51 rules for clean maintainable PHP
- PHP 8.0 through 8.5 feature availability matrix
Adoption & trust: 1.9k installs on skills.sh; 42 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are shipping PHP without a consistent checklist for PSR compliance, strict typing, and features that only exist in your locked PHP minor version.
Who is it for?
Solo builders reviewing PHP APIs, WordPress plugins, or Laravel services who want PSR- and SOLID-aware feedback tied to composer.json.
Skip if: Greenfield scaffolding from zero or teams that only need php-cs-fixer/PHPStan CLI runs without agent-guided interpretation.
When should I use this skill?
Reviewing PHP code, checking type safety, auditing code quality, or when the user says review PHP, check PHP code, audit PHP, or PHP best practices.
What do I get? / Deliverables
You get a version-scoped review aligned to fifty-one rules so refactors and PRs fix real PHP issues instead of generic style nitpicks.
- Version-scoped review findings mapped to rule categories
- Concrete refactor suggestions respecting minimum PHP version
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Code review and quality audits sit in Ship; PHP apps are most often reviewed before merge or release. Canonical shelf is review—systematic checks for type safety, PSR alignment, and maintainability.
Where it fits
Refactor a service class toward readonly properties and match expressions while staying within ^8.2.
Pre-merge pass on a PR that adds union types and constructor promotion.
Harden a legacy module incrementally with version-correct modernization rules.
How it compares
Use as a procedural PHP audit playbook—not a drop-in replacement for PHPStan, Rector, or Pint without running those tools.
Common Questions / FAQ
Who is php-best-practices for?
Indie PHP backend developers and agent users who want structured reviews when merging or hardening existing codebases.
When should I use php-best-practices?
During Ship review before release, after large Build backend refactors, or whenever you ask to review, check, or audit PHP code or PHP best practices.
Is php-best-practices safe to install?
Treat it like any community skill: read the Security Audits panel on this Prism page and confirm the SKILL.md source before enabling it in production repos.
SKILL.md
READMESKILL.md - Php Best Practices
# PHP Best Practices Modern PHP 8.x patterns, PSR standards, type system best practices, and SOLID principles. Contains 51 rules for writing clean, maintainable PHP code. ## Step 1: Detect PHP Version **Always check the project's PHP version before giving any advice.** Features vary significantly across 8.0 - 8.5. Never suggest syntax that doesn't exist in the project's version. Check `composer.json` for the required PHP version: ```json { "require": { "php": "^8.1" } } // -> 8.1 rules and below { "require": { "php": "^8.3" } } // -> 8.3 rules and below { "require": { "php": ">=8.4" } } // -> 8.4 rules and below ``` Also check the runtime version: ```bash php -v # e.g. PHP 8.3.12 ``` ### Feature Availability by Version | Feature | Version | Rule Prefix | |---------|---------|-------------| | Union types, match, nullsafe, named args, constructor promotion, attributes | 8.0+ | `type-`, `modern-` | | Enums, readonly properties, intersection types, first-class callables, never, fibers | 8.1+ | `modern-` | | Readonly classes, DNF types, true/false/null standalone types | 8.2+ | `modern-` | | Typed class constants, `#[\Override]`, `json_validate()` | 8.3+ | `modern-` | | Property hooks, asymmetric visibility, `#[\Deprecated]`, `new` without parens | 8.4+ | `modern-` | | Pipe operator `|>` | 8.5+ | `modern-` | **Only suggest features available in the detected version.** If the user asks about upgrading or newer features, mention what becomes available at each version. ## When to Apply Reference these guidelines when: - Writing or reviewing PHP code - Implementing classes and interfaces - Using PHP 8.x modern features - Ensuring type safety - Following PSR standards - Applying design patterns ## Rule Categories by Priority | Priority | Category | Impact | Prefix | Rules | |----------|----------|--------|--------|-------| | 1 | Type System | CRITICAL | `type-` | 9 | | 2 | Modern PHP Features | CRITICAL | `modern-` | 16 | | 3 | PSR Standards | HIGH | `psr-` | 6 | | 4 | SOLID Principles | HIGH | `solid-` | 5 | | 5 | Error Handling | HIGH | `error-` | 5 | | 6 | Performance | MEDIUM | `perf-` | 5 | | 7 | Security | CRITICAL | `sec-` | 5 | ## Quick Reference ### 1. Type System (CRITICAL) — 9 rules - `type-strict-mode` - Declare strict types in every file - `type-return-types` - Always declare return types - `type-parameter-types` - Type all parameters - `type-property-types` - Type class properties - `type-union-types` - Use union types effectively - `type-intersection-types` - Use intersection types - `type-nullable-types` - Handle nullable types properly - `type-void-never` - Use void/never for appropriate return types - `type-mixed-avoid` - Avoid mixed type when possible ### 2. Modern PHP Features (CRITICAL) — 16 rules **8.0+:** - `modern-constructor-promotion` - Constructor property promotion - `modern-match-expression` - Match over switch - `modern-named-arguments` - Named arguments for clarity - `modern-nullsafe-operator` - Nullsafe operator (?->) - `modern-attributes` - Attributes for metadata **8.1+:** - `modern-enums` - Enums instead of constants - `modern-enums-methods` - Enums with methods and interfaces - `modern-readonly-properties` - Readonly for immutable data - `modern-first-class-callables` - First-class callable syntax - `modern-arrow-functions` - Arrow functions (7.4+, pairs well with 8.1 features) **8.2+:** - `modern-readonly-classes` - Readonly classes **8.3+:** - `modern-typed-constants` - Typed class constants (`const string NAME = 'foo'`) - `modern-override-attribute` - `#[\Override]` to catch parent method t