Install the package in your Laravel project:
composer require croct/coding-standard --dev
Run a quick check on your project root:
./vendor/bin/phpcs .
Integrate with CI/CD (e.g., GitHub Actions) by adding the command to your workflow:
- name: Run PHP CodeSniffer
run: ./vendor/bin/phpcs --standard=./vendor/croct/coding-standard/croct .
phpcs to auto-fix or block non-compliant code before commits.
Example with husky:
./vendor/bin/phpcs --standard=./vendor/croct/coding-standard/croct --report=emacs .
Daily Development
phpcs on demand or via IDE integration (e.g., PHPStorm’s CodeSniffer plugin).--diff to check only changed files:
./vendor/bin/phpcs --standard=croct --diff app/Http/Controllers/
Team Enforcement
composer.json scripts:
"scripts": {
"cs-check": "phpcs --standard=croct --report=full ."
}
- name: Enforce Coding Standard
run: ./vendor/bin/phpcs --standard=croct --warning-severity=3 || exit 1
Custom Rulesets
croct standard file (located at ./vendor/croct/coding-standard/croct) to your project’s root and modifying it:
cp ./vendor/croct/coding-standard/croct ./croct-custom
phpcs command to use your custom file:
./vendor/bin/phpcs --standard=croct-custom .
barryvdh/laravel-ide-helper to ensure IDE autocompletion aligns with coding standards.phpstan/extension-installer for static analysis:
./vendor/bin/phpstan analyse --level=max --memory-limit=1G
pre-commit to auto-fix minor issues (e.g., indentation):
./vendor/bin/phpcbf --standard=croct --diff .
Rule Conflicts
./vendor/croct/coding-standard/croct for custom rules (e.g., Croct.Sniffs.*) and override them in your custom ruleset.Performance
phpcs. Use --parallel (PHP 7.4+) for speed:
./vendor/bin/phpcs --standard=croct --parallel=8 .
False Positives
__construct injection) as errors.[PHP]
; Disable rule for constructor injection
Croct.Sniffs.Classes.DisallowConstructorInjection = 0
--verbose to debug rule application:
./vendor/bin/phpcs --standard=croct --verbose app/Models/
Croct.Sniffs.Files.LineLength).Custom Rules
PHP_CodeSniffer:
// app/CodeSniffer/Croct/ExtendedSniff.php
class ExtendedSniff extends \PHP_CodeSniffer\Standards\AbstractSniff {}
Sniff Configuration
[PHP]
line_length = 120
Autofix
phpcbf (PHP Code Beauty Fix) for auto-correction:
./vendor/bin/phpcbf --standard=croct --diff .
--warning-severity to control CI failures:
./vendor/bin/phpcs --standard=croct --warning-severity=5 # Only errors fail
./vendor/bin/phpcs./vendor/croct/coding-standard/croctCODE_STANDARD.md to your repo explaining Croct’s rules and overrides.How can I help you explore Laravel packages today?