PH

php-best-practices

Get guidance on PHP development, ensuring code follows PSR standards and modern quality guidelines.

Install

mkdir -p .claude/skills/php-best-practices && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1422" && unzip -o skill.zip -d .claude/skills/php-best-practices && rm skill.zip

Installs to .claude/skills/php-best-practices

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Write PHP following PSR coding standards, SOLID principles, and code-quality guidelines. Use for PHP style, design, refactoring, naming, and guard clauses—not Composer/PSR-4 project configuration.
196 chars✓ has a “when” trigger
Beginner

Key capabilities

  • Enforce PSR-12 coding standards
  • Apply SOLID principles to PHP classes
  • Implement guard clauses to reduce nesting
  • Structure code using domain-driven organization
  • Define constants for magic numbers

How it works

It applies industry-standard PHP coding conventions and structural guidelines to improve maintainability and readability.

Inputs & outputs

You give it
Non-compliant or monolithic PHP code
You get back
PSR-12 compliant, modular PHP code

When to use php-best-practices

  • Refactoring legacy PHP code
  • Validating code against PSR standards
  • Implementing clean architecture in PHP

About this skill

PHP Best Practices

Priority: P1 (HIGH)

Structure

src/
├── {Domain}/             # e.g., Services, Repositories
└── Helpers/              # Pure functions/Traits

Implementation Guidelines

Coding Style (PSR Standards)

  • PSR-12: Enforce 4-space indentation and opening braces on same line for functions/methods.
  • Organization: One class per file; use statements follow namespace. Run PHP CS Fixer with PSR-12 preset.
  • Naming Conventions: Use PascalCase (UserService) for classes, camelCase (getUserById) for methods/variables, and SNAKE_CASE (MAX_RETRIES) for class constants.

SOLID Principles in PHP

  • SRP: Single Responsibility Principle — extract each into its own focused class; keep classes under ~200 lines.
  • Dependency Inversion: inject via constructor with interface type-hints. Inject dependencies via constructor for testability. Favor composition over deep inheritance chains.
  • Separation of Concerns: Use Interfaces for decoupling integrations and logic.

Logic & Performance

  • Guard Clauses: Return early for error conditions (e.g., if (!$user) return null); no else after return to reduce nesting depth.
  • Traits: Define trait HasTimestamps (e.g., use HasTimestamps) for cross-cutting behavior. Keep traits focused and lightweight.
  • Helper Functions: Avoid global-namespace logic; organize in classes.

Anti-Patterns

  • No monolithic classes: Each class one responsibility (SRP).
  • No hardcoded magic numbers: Define as named class constants.
  • No deep nesting: Use guard clauses to return early.
  • No echo in services: Return data; let controller output.

References

Canonical response anchors

When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:

  • SRP:,single responsibility,one responsibility
  • PascalCase
  • no else after return,else after a return,reduce nesting,reducing nesting,deeply nested
  • same-line opening braces,opening braces on same line,Braces on the same line

When not to use it

  • When configuring Composer or PSR-4 project settings

Limitations

  • Limited to code style and design patterns
  • Does not handle infrastructure or server configuration

How it compares

It focuses on structural PHP best practices and PSR standards rather than project-level dependency management.

Compared to similar skills

php-best-practices side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
php-best-practices (this skill)151moNo flagsBeginner
php-guidelines-from-spatie66moNo flagsBeginner
laravel-architecture71moNo flagsIntermediate
fluent-validation-migrate-messages01moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry