flyeralarm/php-code-validator
FLYERALARM PHP coding guideline validator: a PSR-12 based PHP_CodeSniffer ruleset with extra standards like lowerCamelCase variables, no Yoda conditions, bans on eval/goto, namespace underscores, and certain class suffixes. Easy Composer embed via ruleset.xml.
lowerCamelCase variables, no Interface suffixes) may clash with Laravel conventions (e.g., UserRepositoryInterface, AppServiceProvider). A strategic override (via phpcs.xml) will be required to exclude or modify conflicting rules.phpcs into local/dev environments.snake_case for database columns.vendor/bin/phpcs app/ tests/).--cache flag reduces CI/CD runtime.| Risk | Impact | Mitigation Strategy |
|---|---|---|
| Rule Conflicts | High (e.g., Interface suffixes) |
Override rules in phpcs.xml or exclude paths (e.g., <exclude-pattern>*/Interfaces/*.php</exclude-pattern>). |
| Performance in CI/CD | Medium (slower pipelines) | Cache results (--cache), parallelize checks, or run only on changed files (git diff). |
| Maintenance Overhead | Low-Medium | Monitor Laravel’s coding standards and update rules annually. |
| False Positives/Negatives | Low | Test against Laravel’s core codebase to validate rule accuracy. |
| Dependency Bloat | Low | Dev-only dependency; no impact on production. |
Rule Customization:
Interface suffixes, exception message formatting)?app/Interfaces/)?CI/CD Strategy:
sniff-fix for safe changes)?IDE vs. CLI:
Laravel-Specific Extensions:
PHP Version Support:
Onboarding Impact:
php artisan, Valet, Sail).phpcs commands.pre-commit (e.g., via husky or laravel/git-hooks).make sniff # Validate
make sniff-fix # Auto-fix safe issues
laravel-pint # Auto-format remaining style
| Phase | Action | Tools/Commands |
|---|---|---|
| Assessment | Audit existing codebase for conflicts with custom rules (e.g., Interface suffixes). |
vendor/bin/phpcs --report=xml --standard=vendor/flyeralarm/php-code-validator/ruleset.xml app/ |
| Configuration | Create phpcs.xml to override/extend rules. |
Example: Custom Ruleset Template |
| CI/CD Integration | Add phpcs to CI pipeline (e.g., GitHub Actions). |
.github/workflows/phpcs.yml |
| IDE Setup | Configure PHPStorm/VSCode for real-time validation. | PHPStorm Guide |
| Developer Onboarding | Document rules and provide sniff-fix workflow examples. |
README.md section on coding standards. |
| Retroactive Enforcement | Decide: Enforce on new code only, or apply to legacy code with exceptions. | Use <exclude-pattern> in phpcs.xml for legacy paths. |
composer.phar updates).phpcs into CI/CD as a warning-only check.- name: PHP Code Sniffer
run: vendor/bin/phpcs --standard=vendor/flyeralarm/php-code-validator/ruleset.xml --warning-severity=0 app/ tests/
sniff-fix to pre-commit hooks or CI (for safe changes).ReturnTypeSniff was dropped in favor of PHPStan).How can I help you explore Laravel packages today?