squizlabs/php_codesniffer
PHP_CodeSniffer (PHPCS) provides phpcs to detect coding standard violations and phpcbf to automatically fix them. Tokenizes PHP files against defined standards to keep code clean and consistent, suitable for teams and CI.
Start by installing PHP_CodeSniffer via Composer in your project’s require-dev section ("squizlabs/php_codesniffer": "^4.0"), then run ./vendor/bin/phpcs src/ to validate against PSR-12 by default. If violations appear, fix them manually or run ./vendor/bin/phpcbf src/ for automatic corrections. For team use, create a phpcs.xml ruleset file in your project root to define standards, exclude paths, and configure sniffs—this becomes your single source of truth and works seamlessly in CI pipelines.
phpcs in GitHub Actions/GitLab CI with --error-severity=1 --warning-severity=1 to fail jobs only on critical violations. Use parallel scanning (-p flag) for speed.PSR12) in ruleset.xml by adding/removing individual sniffs, overriding properties (e.g., indent width), or defining custom sniff classes.phpcs for live linting—use phpcs:ignore and phpcs:enable annotations in docblocks to suppress per-file/per-line warnings where justified.phpcbf to a pre-commit hook (e.g., via Husky or Git hooks) to auto-fix issues before staging, ensuring commits always conform to style guides.ruleset.xml properties like severity or exclude accept comma-separated values but fail silently if whitespace is included—use <property name="tabIndent" value="true"/> instead of <property name="tabIndent" value= " true " />.phpcs -s --sniffs=Generic.WhiteSpace.ScopeIndent src/MyFile.php to see exact sniff names and token details. Use --runtime-set testVersion 8.3 to simulate PHP version behavior during parsing.AbstractSniff and override process()—place them in YourStandard/Sniffs/ and reference them in ruleset.xml. Test them via phpcs -p to see progress during rule development.git diff --name-only main | grep .php$ | xargs phpcs, or enable parallel_errors for faster reports.How can I help you explore Laravel packages today?