skills/smithery.ai/hoangnguyen0403-php-best-practices

hoangnguyen0403-php-best-practices

SKILL.md

PHP Best Practices

Priority: P1 (HIGH)

Structure

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

Implementation Guidelines

  • PSR-12: Follow PSR-12 for coding style (indent, braces, space).
  • Autoloading: Use PSR-4 via Composer.
  • Namespacing: Map namespaces to directory structure.
  • PascalCase: Use for all class names.
  • camelCase: Use for methods and variables.
  • SNAKE_CASE: Use for class constants.
  • DRY Logic: Extract repetitive logic into traits/methods.
  • SOLID: Use interfaces for decoupling and SRP adherence.

Anti-Patterns

  • God Classes: No Monoliths: Avoid classes with multiple responsibilities.
  • Magic Numbers: No Hardcoding: Use class constants for config values.
  • Deep Nesting: No Nesting: Guard clauses over nested if/else.
  • Direct Output: No Echo: Return data; let controller handle response.

References

Weekly Installs
3
First Seen
Mar 1, 2026
Installed on
cursor2
github-copilot1