Coding Standards
This document outlines the coding standards and signatures used in the project. Following these standards ensures clean, readable, and consistent code across the entire codebase.
General Guidelines
- Follow PSR-12 coding standards for PHP code
- Use meaningful variable and function names
- Keep functions small and focused on a single responsibility
- Add appropriate comments to explain complex logic
- Use consistent indentation (spaces, not tabs)
- Limit line length to 120 characters
- Use type hints for parameters and return types
- Write unit tests for all new functionality
Code Organization
The project follows a standard Laravel structure with some additional conventions:
- Controllers should be thin and delegate business logic to services
- Use repositories for database interactions
- Place validation logic in dedicated Form Request classes
- Use enums for representing fixed sets of values
- Implement interfaces for all services that might have multiple implementations
Naming Conventions
- Classes: PascalCase (e.g.,
UserService) - Methods/Functions: camelCase (e.g.,
getUserById) - Variables: camelCase (e.g.,
$userCount) - Constants: UPPER_SNAKE_CASE (e.g.,
MAX_LOGIN_ATTEMPTS) - Database Tables: snake_case, plural (e.g.,
user_profiles) - Database Columns: snake_case (e.g.,
first_name) - Enums: PascalCase for enum name, PascalCase for cases (e.g.,
ProductAccessType::Subscriber)
File Structure
- One class per file
- Filename should match the class name
- Group related files in appropriate directories
- Follow Laravel's convention for file locations
Code Reviews
All code must go through a review process before being merged:
- Each merge request must be reviewed by the code owner
- If the code owner doesn't approve it, it won't be reviewed by the CTO
- Follow the established pull request template
- Address all review comments before requesting a re-review
Documentation
- Document all public methods and functions
- Update the README when adding new commands or features
- Include examples for complex functionality
- Document any non-obvious behavior or edge cases
Following these standards will help maintain a high-quality codebase and make collaboration easier for all team members.