wyrihaximus/coding-standard
PHP coding standard package for consistent formatting and style in PHP projects. Provides ready-to-use rulesets and configuration to streamline linting, code style checks, and enforcement across teams and CI pipelines.
Install the package via Composer:
composer require --dev wyrihaximus/coding-standard
Run the coding standard against your project:
vendor/bin/phpcs
(Ensure phpcs is installed globally or via Composer.)
First Use Case: Integrate into your CI pipeline (e.g., GitHub Actions) to enforce standards on every commit:
# .github/workflows/php-cs-fixer.yml
- name: PHP Coding Standards
run: vendor/bin/phpcs --standard=WyriHaximus src/
phpcs.xml.dist: Default configuration file (auto-generated by the package).composer.json: Ensure require-dev includes wyrihaximus/coding-standard.Local Development:
phpcbf (auto-fixer) for quick fixes:
vendor/bin/phpcbf --standard=WyriHaximus src/
--diff to preview changes:
vendor/bin/phpcs --standard=WyriHaximus --diff src/
CI/CD Integration:
- name: Run PHP Coding Standard
run: |
composer install --dev
vendor/bin/phpcs --standard=WyriHaximus --report=json src/ > phpcs-results.json
# Fail if issues exist
test -s phpcs-results.json && exit 1 || exit 0
test:phpcs:
script:
- composer install --dev
- vendor/bin/phpcs --standard=WyriHaximus --warning-severity=0 src/
Custom Rules:
phpcs.xml:
<config name="installedPaths" value="WyriHaximus,./ruleset.xml"/>
ruleset.xml:
<rule ref="WyriHaximus">
<exclude name="Generic.Files.LineEndings"/>
</rule>
phpcs.xml:
<arg name="exclude" value="vendor,node_modules"/>
vendor/bin/phpcs --standard=WyriHaximus app/Http/
False Positives:
match expressions) as errors.phpcs.xml to include @phpstan-ignore-next-line or suppress rules:
<rule ref="WyriHaximus">
<exclude name="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint"/>
</rule>
Performance:
phpcs. Use --parallel (PHP 8.1+) for speed:
vendor/bin/phpcs --standard=WyriHaximus --parallel=4 src/
Outdated Rules:
squizlabs/php_codesniffer (v4+) and slevomat/coding-standard (v8+).composer.json to avoid breaking changes:
"require-dev": {
"slevomat/coding-standard": "^8.25.0",
"squizlabs/php_codesniffer": "^3.13.5"
}
--verbose to diagnose rule failures:
vendor/bin/phpcs --standard=WyriHaximus --verbose app/Models/User.php
Custom Sniffs:
Custom/Sniffs directory and reference it in phpcs.xml:
<config name="installedPaths" value="WyriHaximus,./Custom/Sniffs"/>
use statements alphabetization.Autoloading:
composer.json autoloads custom sniffs:
"autoload-dev": {
"psr-4": {
"Custom\\Sniffs\\": "Custom/Sniffs/"
}
}
Integration with PHPStan:
phpstan for static analysis:
vendor/bin/phpstan analyse --level=5 && vendor/bin/phpcs --standard=WyriHaximus src/
bootstrap/cache/) in phpcs.xml:
<file>.</file>
<exclude-pattern>.*/bootstrap/cache/.*</exclude-pattern>
<rule ref="WyriHaximus">
<exclude name="Generic.Files.DisallowBlankLines"/>
</rule>
How can I help you explore Laravel packages today?