pluswerk/grumphp-config
Dev-only Composer package that generates a ready-to-use GrumPHP setup for your project: creates grumphp.yml, rector.php, phpstan.neon and phpstan-baseline.neon, and pulls in project-specific resources when needed. Customize via the generated grumphp.yml.
Installation:
composer require --dev pluswerk/grumphp-config
This auto-generates:
grumphp.yml (GrumPHP configuration)rector.php (Rector rules)phpstan.neon (PHPStan configuration)phpstan-baseline.neon (Baseline for existing code)First Use Case: Run GrumPHP on your Laravel project to catch issues early:
./vendor/bin/grumphp run
Where to Look First:
grumphp.yml: Override tasks/rules (e.g., exclude vendor/ or add Laravel-specific paths).rector.php: Adjust Rector rules (e.g., skip BooleanInTernaryOperatorRule if needed)..phpstan-baseline.neon: Update baselines after running Rector.Laravel-Specific Customization:
# grumphp.yml
exclude_file_patterns:
- "vendor/"
- "bootstrap/cache/*"
- "storage/framework/*"
tasks:
phpcsfixer:
config: ".php-cs-fixer.dist.php" # Replace with Laravel Pint config
Integration with Laravel CI:
.github/workflows/laravel.yml:
- name: Run GrumPHP
run: ./vendor/bin/grumphp run
- uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Rector Workflow for Laravel:
tasks:
rector:
config: "rector.php"
dry_run: false # Auto-fix on commit
--parallel:
./vendor/bin/rector process src --parallel
PHPStan for Laravel:
phpstan.neon to include Laravel-specific rules:
includes:
- vendor/laravel/phpstan/src/Ruleset/LaravelRuleset.neon
tasks:
phpstan:
configuration: "phpstan.neon"
triggered_by: ["php"]
ignore_patterns: ["tests/*"]
Daily Development:
git add . && ./vendor/bin/grumphp run
grumphp it for interactive mode (fixes issues on the fly).Pre-Release:
./vendor/bin/rector process src --dry-run
./vendor/bin/phpstan analyse --generate-baseline
Onboarding New Devs:
grumphp.yml overrides in CONTRIBUTING.md:
## Code Quality
Run `composer require --dev pluswerk/grumphp-config` to set up GrumPHP.
Override rules in `grumphp.yml` as needed.
Path Issues:
__DIR__ (fixed in v10.2.7+), but older versions may break in subdirectories.getcwd() or update paths manually:
# grumphp.yml
paths:
- "src/"
- "app/"
PHPStan Conflicts:
PSR-4 autoloading may cause PHPStan to miss files.# phpstan.neon
include_files:
- "app/**/*.php"
- "src/**/*.php"
Rector Over-Aggressiveness:
config('app.name') to config('app.name')).// rector.php
return static::configureRules([
\Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorRector::class => false,
]);
DDEV Environments:
DDEV_EXEC rule (enabled by default in v10.2.6+):
# grumphp.yml
parameters:
tasks.phpunit.env:
- "DDEV_EXEC"
Baseline Management:
phpstan-baseline.neon after Rector runs.composer.json:
"scripts": {
"post-rector": "phpstan analyse --generate-baseline"
}
GrumPHP Fails Silently:
--verbose:
./vendor/bin/grumphp run --verbose
~/.cache/grumphp/.PHPStan Errors:
./vendor/bin/phpstan analyse --level=max src/Controller/HomeController.php
Rector Hangs:
--parallel or limit files:
./vendor/bin/rector process src/ --parallel --max-processes=4
Custom Tasks:
laravel-pint):
# grumphp.yml
tasks:
laravel-pint:
command: "php artisan pint"
on_fail: fail
Dynamic Configs:
grumphp.yml:
parameters:
tasks.phpunit.env:
- "DB_CONNECTION=${DB_CONNECTION:-mysql}"
Git Hooks:
post-commit:
composer require --dev laravel/git-hooks
echo "php artisan grumphp" >> .git/hooks/post-commit
CI-Specific Overrides:
grumphp.yml.dist for CI-only rules:
# grumphp.yml (local)
tasks:
phpstan: ~
# grumphp.ci.yml (CI-only)
tasks:
phpstan:
level: max
Start Strict, Then Relax:
level: max in PHPStan, then adjust baselines incrementally.Leverage grumphp it:
./vendor/bin/grumphp it
Exclude Tests:
# grumphp.yml
exclude_file_patterns:
- "tests/*"
Monitor Performance:
# .github/workflows/laravel.yml
- uses: actions/cache@v3
with:
path: ~/.cache/grumphp
key: ${{ runner.os }}-grumphp-${{ hashFiles('**/composer.lock') }}
Document Overrides:
CODE_QUALITY.md file to explain custom rules for new devs.How can I help you explore Laravel packages today?