leaphub/phpcs-symfony2-standard
Install via Composer (recommended):
composer require --dev leaphub/phpcs-symfony2-standard
This auto-installs phpcs as a dev dependency.
Run a basic check on your src/ directory:
vendor/bin/phpcs --standard=vendor/leaphub/phpcs-symfony2-standard/leaphub/phpcs/Symfony2 --extensions=php src/
Quick alias (add to composer.json scripts):
"scripts": {
"cs-check": "phpcs --standard=vendor/leaphub/phpcs-symfony2-standard/leaphub/phpcs/Symfony2 --extensions=php src/"
}
Then run:
composer cs-check
Integrate with pre-commit (e.g., via husky or pre-commit hooks) to enforce standards before merging:
# Example .huskyrc
"pre-commit": "composer cs-check"
CI/CD Pipeline:
- name: Run PHP_CodeSniffer
run: composer cs-check || exit 1
--report=full for detailed output in PRs.IDE Integration:
vendor/leaphub/phpcs-symfony2-standard/leaphub/phpcs/Symfony2.Custom Rulesets:
phpcs.xml file:
<config name="installedPaths" value="vendor/leaphub/phpcs-symfony2-standard/leaphub/phpcs/Symfony2"/>
<rule ref="Symfony2">
<exclude name="Symfony2.Files.LineEndings" /> <!-- Disable line-ending checks -->
</rule>
Fix Automatically:
--fix to auto-correct simple issues (e.g., indentation):
vendor/bin/phpcbf --standard=Symfony2 src/
| Scenario | Command |
|---|---|
| Check entire project | composer cs-check |
| Check a single file | phpcs app/Controller/UserController.php |
| Check tests | phpcs --extensions=php tests/ --ignore=*/migrations/* |
| Generate report | phpcs --report=checkstyle src/ > phpcs.xml |
Path Confusion:
phpcs fails with Standard not found.vendor/bin/phpcs --standard=vendor/leaphub/phpcs-symfony2-standard/leaphub/phpcs/Symfony2 ...
~/.bashrc:
alias phpcs-sf="vendor/bin/phpcs --standard=vendor/leaphub/phpcs-symfony2-standard/leaphub/phpcs/Symfony2"
False Positives:
core.autocrlf.User_Manager). Disable if legacy code exists.Performance:
vendor/, node_modules/) to speed up checks:
phpcs --ignore=vendor/,node_modules/ src/
Verbose Output:
-v to debug rule application:
phpcs -v --standard=Symfony2 src/Controller/UserController.php
Unit Tests:
cd vendor/leaphub/phpcs-symfony2-standard
phpunit --filter Symfony2_* tests/AllTests.php
Custom Sniffs:
mkdir -p vendor/leaphub/phpcs/Symfony2/Sniffs/YourCompany
YourCompany/Sniffs/Files/ProhibitedFilenameSniff.php to block config_local.php.Override Rules:
app/CodeSniffer/ and reference them in phpcs.xml:
<rule ref="Symfony2">
<exclude name="Symfony2.NamingConventions.ValidClassName.NotCamelCaps"/>
</rule>
<rule ref="app/CodeSniffer/Sniffs/YourCompany/">
<active>true</active>
</rule>
Symfony-Specific Tips:
--ignore=src/Entity/* if entity naming conventions conflict..twig files unless you’ve added Twig-specific sniffs.Caching:
rm -rf ~/.phpcs.cache
Composer Updates:
leaphub/phpcs-symfony2-standard, re-run checks to catch new rules.PHP Version:
.phpcs.dist file to lock the standard version:
<config name="installedPaths" value="vendor/leaphub/phpcs-symfony2-standard/leaphub/phpcs/Symfony2"/>
<config name="standard" value="Symfony2"/>
How can I help you explore Laravel packages today?