Consistent coding standards are the difference between a codebase you enjoy working in and one you dread. They matter even more when you're working remotely with international clients or collaborating across time zones — your code needs to speak clearly without you being present to explain it.
PSR Standards — The Foundation
PHP-FIG (Framework Interop Group) PSR standards are the universal baseline for PHP code. Laravel follows them, and so should you.
PSR-1: Basic Coding Standard
- Use only opening tags
<?php - Files must use UTF-8 without BOM
- Class names in PascalCase
- Method names in camelCase
- Constants in UPPER_CASE
PSR-12: Extended Coding Style
- 4 spaces for indentation — never tabs
- Lines should be 120 characters or fewer
- One blank line between methods
- Type declarations on all method signatures
Laravel-Specific Conventions
Naming Conventions
Always Type-Hint Your Methods
Document Non-Obvious Methods
Automated Quality Tools
PHP CS Fixer — Auto-format your code
PHP CodeSniffer — Check standards compliance
Team Practices
- Add a
.editorconfigto your repo — enforces consistent indentation and line endings across all editors automatically - Set up a Git pre-commit hook to run PHP CS Fixer before every commit
- Write code and comments in English — it's universal and expected by international clients and open source contributors
- Run code reviews on every PR — the act of explaining your code to a colleague is itself a quality filter
Conclusion
Start with PSR-12 and Laravel's own conventions — they cover 90% of the decisions you'll face. Add PHP CS Fixer to your workflow to automate formatting entirely so you never have to think about it again. The goal isn't perfect code, it's consistent code that any developer can read and modify confidently.