skillfed

php-best-practices

PHP Best Practices audits your code against 51 rules covering type systems, modern PHP 8.x features, PSR standards, SOLID principles, error handling, performance, and security. It detects your project's PHP version and applies only relevant guidance, from union types and match expressions in 8.0 through property hooks and the pipe operator in 8.4+.

PHP Best Practices reviews your code against modern PHP 8.x standards and SOLID principles.

AI-generated summary based on this skill's SKILL.md

58 9 MIT updated by AsyrafHussin

Install

AsyrafHussin/agent-skills/php-best-practices

git clone https://github.com/AsyrafHussin/agent-skills
cp -r agent-skills/skills/php-best-practices ~/.claude/skills/php-best-practices
npx skillfed install AsyrafHussin/agent-skills/php-best-practices

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How does PHP Best Practices review my PHP code for best practices?

PHP Best Practices audits your code against 51 rules covering type systems, modern PHP 8.x features, PSR standards, SOLID principles, error handling, performance, and security. It detects your project's PHP version and applies only relevant guidance, from union types and match expressions in 8.0 through property hooks and the pipe operator in 8.4+.

Can PHP Best Practices check PHP 8 type safety in my code?

Yes. PHP Best Practices ensures type safety and strict typing in PHP 8.x code by validating union types, nullable types, strict types declarations, and constructor promotion syntax. It verifies that your type hints align with PHP 8.x standards and flags unsafe type coercion patterns.

What SOLID principles does PHP Best Practices audit for?

PHP Best Practices audits code for SOLID principles and design pattern compliance, helping you identify violations of Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles. It reviews class structure, inheritance hierarchies, and dependency injection patterns.

Does PHP Best Practices validate PSR standards and coding style?

Yes. PHP Best Practices validates PSR standards and coding style conformance, checking your code against established PHP Standards Recommendations. It reviews naming conventions, formatting, and structural guidelines to ensure consistency with industry-standard practices.

What PHP 8.x modern features can PHP Best Practices help me learn?

PHP Best Practices guides you through PHP 8.x modern features and version-specific syntax including match expressions, enums, readonly properties, constructor promotion, union and intersection types, attributes, and named arguments. It provides examples and best-practice guidance for each feature.

Does PHP Best Practices detect security issues in my code?

PHP Best Practices reviews code quality across multiple dimensions including error handling best practices, performance optimization, and security considerations. While primarily focused on code standards and modern PHP practices, it helps identify patterns that may impact security and reliability.

SKILL.md

rendered from the published skill — quoted content, verbatim

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:

{ "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:

php -v   # e.g. PHP 8.3.12
Feature Availability by Version

| Feature | Version | Rule Prefix

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 15 files
skills/php-best-practices/AGENTS.md
skills/php-best-practices/README.md
skills/php-best-practices/SKILL.md
skills/php-best-practices/metadata.json
skills/php-best-practices/rules/_sections.md
skills/php-best-practices/rules/_template.md
skills/php-best-practices/rules/error-custom-exceptions.md
skills/php-best-practices/rules/error-exception-hierarchy.md
skills/php-best-practices/rules/error-finally-cleanup.md
skills/php-best-practices/rules/error-never-suppress.md
skills/php-best-practices/rules/error-try-catch-specific.md
skills/php-best-practices/rules/modern-arrow-functions.md
skills/php-best-practices/rules/modern-asymmetric-visibility.md
skills/php-best-practices/rules/modern-attributes.md
skills/php-best-practices/rules/modern-constructor-promotion.md

Related skills

Tags

code-quality type-safety modern-syntax design-patterns static-analysis php-standards immutability functional-programming version-aware security-audit