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.zipInstalls 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.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
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, andSNAKE_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
echoin 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.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| php-best-practices (this skill) | 15 | 1mo | No flags | Beginner |
| php-guidelines-from-spatie | 6 | 6mo | No flags | Beginner |
| laravel-architecture | 7 | 1mo | No flags | Intermediate |
| fluent-validation-migrate-messages | 0 | 1mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by HoangNguyen0403
View all by HoangNguyen0403 →You might also like
php-guidelines-from-spatie
freekmurze
Describes PHP and Laravel guidelines provided by Spatie. These rules result in more maintainable, and readable code.
laravel-architecture
HoangNguyen0403
Core architectural standards for scalable Laravel applications.
fluent-validation-migrate-messages
angelgarciasolorzano
Migrate FormRequest `messages(): array` to inline `message:` on fluent chains. Dry-run, then apply. Activates when: user mentions migrate messages, messages array, inline message, remove messages().
php-pro
ngxtm
Use when building PHP applications with modern PHP 8.3+ features, Laravel, or Symfony frameworks. Invoke for strict typing, PHPStan level 9, async patterns with Swoole, PSR standards.
php-pro
sickn33
Write idiomatic PHP code with generators, iterators, SPL data structures, and modern OOP features. Use PROACTIVELY for high-performance PHP applications.
code-refactor-php-mediawiki
SemanticMediaWiki
>