sunrise/coding-standard
Sunrise PHP Coding Standard provides a ready-to-use PHPCS ruleset (ruleset.xml) you can reference in your project to enforce consistent code style across src and tests, aligned with PSR-1 and PSR-2.
Installation
composer require --dev sunrise/coding-standard
Add the package to your project's require-dev dependencies.
Configure PHPCS
Create a phpcs.xml (or phpcs.xml.dist) in your project root:
<?xml version="1.0"?>
<ruleset name="Project Coding Standard">
<rule ref="./vendor/sunrise/coding-standard/ruleset.xml"/>
<file>src</file>
<file>tests</file>
</ruleset>
First Run Validate your codebase:
vendor/bin/phpcs --standard=./phpcs.xml src tests
.git/hooks/pre-commit):
#!/bin/sh
vendor/bin/phpcs --standard=./phpcs.xml $1
Team Onboarding
phpcs.xml in your team’s repo.phpcbf (built-in) for auto-fixing:
vendor/bin/phpcbf --standard=./phpcs.xml src
CI/CD Integration
- name: Run PHPCS
run: vendor/bin/phpcs --standard=./phpcs.xml --warning-severity=3 src
Custom Rulesets
<ruleset>
<rule ref="./vendor/sunrise/coding-standard/ruleset.xml"/>
<rule ref="PSR2" />
<rule ref="Generic.Files.LineEndings" />
<exclude name="Generic.Files.LineEndings" from="tests/*" />
</ruleset>
phpcs.xml for real-time feedback.parallel flag for large codebases:
vendor/bin/phpcs --standard=./phpcs.xml --parallel=8 src
slack-notify for alerts.Outdated Ruleset
squizlabs/php_codesniffer for modern rules:
<rule ref="vendor/sunrise/coding-standard/ruleset.xml"/>
<rule ref="PSR12"/>
False Positives
use App; vs. use App\).<exclude-pattern>*/Resources/views/*.php</exclude-pattern>
Performance
phpcs --cache (requires phpcs-cache extension).--verbose to diagnose rule application:
vendor/bin/phpcs --standard=./phpcs.xml --verbose src
vendor/bin/phpcs --help for generic rules).Custom Rules
.php rules (see PHPCS docs).Custom/Sunrise/Rule.php and reference it in phpcs.xml:
<rule ref="Custom/Sunrise/Rule"/>
Sniff Configuration
<config name="warning_severity" value="5"/>
Autofix Limitations
phpcbf may not handle all Sunrise rules. Test fixes manually before committing.--report=summary to track progress:
vendor/bin/phpcs --standard=./phpcs.xml --report=summary src > phpcs-baseline.txt
git blame to identify authors of violations:
vendor/bin/phpcs --standard=./phpcs.xml --report=gitblame src
How can I help you explore Laravel packages today?