Installation Run:
composer require --dev apnet/coding-standard
Add the package to your project’s phpcs.xml or phpcs.xml.dist:
<config name="standard" value="Apnet"/>
Basic Usage Run PHPCS (PHP Code Sniffer) with the new standard:
vendor/bin/phpcs --standard=Apnet src/
Verify the ruleset loads without errors.
First Use Case Use it to enforce team-wide consistency in a new project or refactor an existing one. Start with a single file or directory to test:
vendor/bin/phpcs --standard=Apnet --report=full src/App/Services/
Pre-Commit Hooks
Integrate with tools like php-cs-fixer or husky to auto-check code before commits:
composer require --dev php-cs-fixer
Add a script to package.json:
"scripts": {
"test:cs": "phpcs --standard=Apnet src/ && php-cs-fixer fix src/"
}
CI/CD Pipeline Add a step in GitHub Actions/GitLab CI to enforce standards:
- name: Run PHPCS
run: vendor/bin/phpcs --standard=Apnet --warning-severity=0 src/
Custom Rule Overrides
Extend or override rules in phpcs.xml:
<rule ref="Apnet">
<exclude name="Generic.Files.LineEndings"/>
<arg name="lineEndings" value="unix"/>
</rule>
Team Onboarding
Document the coding standard in CONTRIBUTING.md and include a quick-start guide:
## Coding Standards
Run `composer test:cs` to check your code against our standard.
Rule Conflicts
If rules clash with other standards (e.g., PSR-12), explicitly exclude or override them in phpcs.xml:
<rule ref="Apnet">
<exclude name="Apnet.Spaces.BlankLineBeforeNamespace"/>
</rule>
Performance
Avoid running PHPCS on large codebases without caching. Use --cache:
vendor/bin/phpcs --standard=Apnet --cache=/tmp/phpcs-cache src/
Undocumented Rules
The package lacks a README or changelog. Inspect the source ruleset (if available) or use:
vendor/bin/phpcs --standard=Apnet --list-rules
PHP Version Compatibility Test with your project’s PHP version (e.g., 8.0+). Some rules may fail silently.
php-cs-fixer
Auto-fix issues where possible:
vendor/bin/php-cs-fixer fix --rules=@Apnet src/
app/Ruleset/Apnet/..vscode/settings.json:
"php.validate.executablePath": "vendor/bin/phpcs",
"php.validate.run": "onType",
"php.validate.args": ["--standard=Apnet"]
phpcs.xml:
<file>vendor/</file>
<file>tests/</file>
How can I help you explore Laravel packages today?