> php-best-practices
Write PHP following best practices, PSR standards, and code quality guidelines. Use when writing PHP following PSR standards, SOLID principles, or improving code quality. (triggers: **/*.php, psr-12, camelCase, PascalCase, dry, solid)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/php-best-practices?format=md"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 the namespace. Run PHP CS Fixer with the 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 has 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 the controller output.
References
> related_skills --same-repo
> common-store-changelog
Generate user-facing release notes for the Apple App Store and Google Play Store by collecting git history, triaging user-impacting changes, and drafting store-compliant changelogs. Enforces character limits (App Store ≤4000, Google Play ≤500), tone, and bullet format. Use when generating release notes, app store changelog, play store release, what's new, or version release notes for any mobile app. (triggers: generate changelog, app store notes, play store release, what's new, release notes, ve
> golang-tooling
Go developer toolchain — gopls LSP diagnostics, linting, formatting, and vet. Use when setting up Go tooling, running linters, or integrating gopls with Claude Code. (triggers: gopls, golangci-lint, golangci.yml, go vet, goimports, staticcheck, go tooling, go lint)
> common-ui-design
Design distinctive, production-grade frontend UI with bold aesthetic choices. Use when building web components, pages, interfaces, dashboards, or applications in any framework (React, Next.js, Angular, Vue, HTML/CSS). (triggers: build a page, create a component, design a dashboard, landing page, UI for, build a layout, make it look good, improve the design, build UI, create interface, design screen)
> common-owasp
OWASP Top 10 audit checklist for Web Applications (2021) and APIs (2023). Load during any security review, PR review, or codebase audit touching web, mobile backend, or API code. (triggers: security review, OWASP, broken access control, IDOR, BOLA, injection, broken auth, API review, authorization, access control)