dosfarma/coding-standard
Opinionated PHP/Laravel coding standard and tooling preset for DosFarma projects. Includes rules and configuration for consistent formatting and static analysis across repositories, helping keep code style unified in CI and local development.
Installation Add the package via Composer in your Laravel project:
composer require --dev dosfarma/coding-standard
First Use Case Run PHP_CodeSniffer against your project to enforce the DosFarma coding standard:
./vendor/bin/phpcs -s --standard=./vendor/dosfarma/coding-standard/src/DosFarma ./app
Where to Look First
./vendor/dosfarma/coding-standard/src/DosFarma for the ruleset file..phpcs.xml or .phpcs.xml.dist in your project root for configuration.CI/CD Pipeline Add a step in your GitHub Actions, GitLab CI, or Jenkins pipeline to run the coding standard checks:
# Example GitHub Actions step
- name: Run PHP_CodeSniffer
run: ./vendor/bin/phpcs -s --standard=./vendor/dosfarma/coding-standard/src/DosFarma ./app --report=checkstyle | tee phpcs.xml
Pre-Commit Hook Use tools like Husky or Pre-Commit to run checks before commits:
echo 'vendor/bin/phpcs -s --standard=./vendor/dosfarma/coding-standard/src/DosFarma ./app' >> .git/hooks/pre-commit
IDE Integration Configure your IDE (PHPStorm, VSCode) to use this standard for real-time feedback:
Settings > Editor > Inspections > PHP > PHP_CodeSniffer and set the standard path.Custom Configuration
Extend the standard by creating a custom .phpcs.xml file:
<?xml version="1.0"?>
<ruleset name="Project Coding Standard">
<config name="installed_paths" value="./vendor/dosfarma/coding-standard/src/DosFarma"/>
<arg name="extensions" value="php"/>
<arg name="tab-width" value="4"/>
<arg name="encoding" value="utf-8"/>
<file>./app</file>
</ruleset>
Fixing Issues Automatically Use PHP_CodeSniffer’s auto-fixer to correct minor issues:
./vendor/bin/phpcbf -s --standard=./vendor/dosfarma/coding-standard/src/DosFarma ./app
Rule Conflicts
.phpcs.xml overrides conflicting rules explicitly.<rule ref="DosFarma">
<exclude name="Generic.Files.LineEndings"/>
</rule>
Performance
phpcs on large codebases can be slow. Use --parallel (if supported) or limit the scope:
./vendor/bin/phpcs ./app/Http/Controllers --standard=./vendor/dosfarma/coding-standard/src/DosFarma
False Positives
<exclude> or <ignore> in your config:
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
Outdated Rules
Verbose Output
Use -v or --verbose to debug rule application:
./vendor/bin/phpcs -v --standard=./vendor/dosfarma/coding-standard/src/DosFarma ./app
Dry Run Test changes without modifying files:
./vendor/bin/phpcbf --dry-run --standard=./vendor/dosfarma/coding-standard/src/DosFarma ./app
Rule-Specific Help Check which rules are being applied:
./vendor/bin/phpcs --list-targets --standard=./vendor/dosfarma/coding-standard/src/DosFarma
Custom Rules Extend the standard by adding custom rules in a separate file and including it:
<rule ref="./custom-ruleset.xml"/>
Team Alignment
CONTRIBUTING.md or README.md.## Coding Standards
We enforce the [DosFarma PHP Coding Standard](https://github.com/dosfarma/coding-standard).
Run `./vendor/bin/phpcs ./app` before submitting PRs.
Partial Adoption
Start with critical paths (e.g., ./app/Http/Controllers) before enforcing it project-wide.
Integration with Laravel Tools
laravel-shift/laravel-coding-standard as a fallback if DosFarma’s rules are too restrictive.<config name="installed_paths">
./vendor/dosfarma/coding-standard/src/DosFarma,
./vendor/laravel-shift/laravel-coding-standard
</config>
Automated Reporting
Generate reports for stakeholders (e.g., Jira, Slack) using --report=json or --report=xml.
How can I help you explore Laravel packages today?