Installation:
composer require chiiya/laravel-code-style --dev
Publish Configs:
php artisan vendor:publish --tag="code-style-config"
ecs.php, .php-cs-fixer.dist.php, rector.php, and phpstan.neon to your project root.Initialize GrumPHP (if using Git hooks):
php ./vendor/bin/grumphp git:deinit
php ./vendor/bin/grumphp git:init
First Run:
./vendor/bin/php-cs-fixer fix
Run pre-commit checks via GrumPHP to enforce style rules before merging:
./vendor/bin/grumphp run
Daily Development:
php-cs-fixer for quick fixes:
./vendor/bin/php-cs-fixer fix src/
./vendor/bin/ecs check src/
CI Pipeline Integration:
.github/workflows/lint.yml:
- name: Run Code Style Checks
run: |
./vendor/bin/grumphp run
./vendor/bin/phpstan analyse --memory-limit=2G
Team Onboarding:
./vendor/bin/php-cs-fixer fix --dry-run./vendor/bin/ecs check --fixCustom Rules:
ecs.php to add project-specific rules:
return [
'rules' => [
// Custom rule example
Symfony\CS\Fixer\Rule\ArrayNotationRule::class,
// ...
],
];
phpstan) in grumphp.yml and run them separately in CI../vendor/bin/rector process src/ --dry-run
grumphp.yml for TypeScript/Laravel Blade checks:
tasks:
tlint: ~
GrumPHP Initialization:
git:deinit + git:init) causes hooks to fail silently.Performance:
phpstan and rector can be slow. Run them in CI, not pre-commit:
# grumphp.yml
tasks:
phpstan: ~ # Disable in GrumPHP
Config Overrides:
ecs.php may conflict with defaults. Use ! to disable:
return [
'rules' => [
'@Symfony' => false,
Symfony\CS\Fixer\Rule\ClassNotationRule::class,
],
];
--dry-run first:
./vendor/bin/php-cs-fixer fix --dry-run
-v to see skipped files:
./vendor/bin/ecs check -v
Custom Tasks:
Add to grumphp.yml:
tasks:
custom_task:
command: './vendor/bin/your-custom-script.php'
on_failure: [fail]
PHPStan Templates:
Extend phpstan.neon for project-specific checks:
includes:
- vendor/chiiya/laravel-code-style/phpstan.neon
- phpstan-project.neon # Your custom rules
Rector Rulesets:
Create a custom ruleset file (rector.php) and reference it:
return [
'sets' => [
Chiiya\LaravelCodeStyle\Rector\Laravel::LARAVEL_10,
// Add your custom ruleset
],
];
# grumphp.yml
git_hook_variables:
EXEC_GRUMPHP_TASKS_ON_FILES_CHANGED_ONLY: true
How can I help you explore Laravel packages today?