PHP Best Practices

Enforce PHP best practices, PSR-12 coding style, and PSR-4 autoloading.

51|6|Updated Mar 28, 2019
One-click install
npx skills add https://github.com/Mte90/dotfiles --skill php-best-practices-mte90
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: PHP Best Practices
Source: https://github.com/Mte90/dotfiles/tree/main/.config/opencode/skills/php/best-practices
Command: npx skills add https://github.com/Mte90/dotfiles --skill php-best-practices-mte90

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill enforces high standards in PHP development by providing clear guidelines on code structure, naming conventions, and best practices, leading to more maintainable and robust codebases.

Core Features & Use Cases

  • PSR Standards Adherence: Ensures compliance with PSR-12 for consistent coding style.
  • Code Quality Enforcement: Guides developers on naming conventions (PascalCase, camelCase, SNAKE_CASE), autoloading, and namespacing.
  • Maintainability Focus: Promotes DRY principles and SOLID design to reduce complexity and improve testability.
  • Use Case: A team is onboarding a new developer to a PHP project. This Skill provides a quick reference to ensure the new developer's code aligns with the established project standards from day one.

Quick Start

Review the PHP best practices for naming conventions and code structure.

Frequently Asked Questions about PHP Best Practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What are the PHP PSR standards for coding style and autoloading?

PHP PSR standards include PSR-12 for consistent coding style and PSR-4 for autoloading, ensuring code is structured predictably. Adhering to these standards improves code maintainability and interoperability across PHP projects.

How do I enforce DRY principles and SOLID design in PHP?

Enforcing DRY principles and SOLID design in PHP involves structuring code to reduce duplication and complexity. Applying these design principles improves testability and ensures a robust, maintainable PHP codebase.

What are the naming conventions for PHP code structure?

PHP naming conventions typically use PascalCase for classes, camelCase for methods and variables, and SNAKE_CASE for constants. Applying these conventions ensures code consistency and aligns with PSR-12 standards.

Can I use these PHP best practices for onboarding new developers?

Yes, these PHP best practices are ideal for onboarding new developers to a project. They provide a quick reference for coding standards, naming conventions, and code structure, ensuring new code aligns with established project guidelines from day one.

Does PHP autoloading require specific namespacing rules?

Yes, PHP autoloading requires strict namespacing rules according to PSR-4. This standard maps namespace paths to directory structures, ensuring classes are loaded automatically and code remains maintainable.

Why should I follow PHP coding standards instead of custom styles?

Following PHP coding standards like PSR-12 instead of custom styles ensures consistency across the codebase. This consistency reduces complexity, improves maintainability, and makes it easier for teams to collaborate and understand the code.