Zero-config PHP code quality standards with GrumPHP, PHPStan, and PHP-CS-Fixer. Installs pre-commit hooks that automatically run static analysis and code style fixes on every commit.
- Installs GrumPHP pre-commit hooks automatically on
composer install - Runs PHPStan (level 5, strict rules, deprecation warnings) on every commit
- Runs PHP-CS-Fixer (PSR-12 + sensible rules) on every commit
- Zero-config - works out of the box with sensible defaults
- Only checks changed files for fast pre-commit validation
| Tool | Configuration |
|---|---|
| PHPStan | Level 5, strict rules, deprecation warnings, bleeding edge |
| PHP-CS-Fixer | PER-CS, PHP 8.2 migration, sorted imports, trailing commas, single quotes |
| PHP Version | 8.2+ required |
This package intentionally requires modern versions:
- PHP 8.2+ - Modern PHP only
- PHPStan 2.x - Latest major version
- PHP-CS-Fixer 3.x - Latest stable
Legacy projects requiring older versions should not use this pack.
Note: All dependencies use stable releases. If your project has
"minimum-stability": "stable"(the default), installation will work without issues.
composer require --dev marac19901990/php-quality-packAdd the following to your project's composer.json:
{
"extra": {
"grumphp": {
"config-default-path": "vendor/marac19901990/php-quality-pack/rules/grumphp.yml"
}
},
"config": {
"allow-plugins": {
"phpro/grumphp": true,
"phpstan/extension-installer": true
}
}
}IMPORTANT: This file is required. PHPStan will fail without it.
Create an empty phpstan-baseline.neon in your project root:
echo "parameters:" > phpstan-baseline.neonOr generate one with current errors (recommended for existing codebases):
vendor/bin/phpstan analyse src/ -c vendor/marac19901990/php-quality-pack/rules/phpstan.neon --generate-baselinecomposer installThat's it! GrumPHP hooks are automatically installed.
git add .
git commit -m "Your commit message"PHPStan and PHP-CS-Fixer run automatically on changed files. If there are issues, the commit is blocked until you fix them.
# Run all checks on changed files
vendor/bin/grumphp run
# Run PHPStan on entire codebase (specify your source directory)
vendor/bin/phpstan analyse src/ -c vendor/marac19901990/php-quality-pack/rules/phpstan.neon
# Run PHP-CS-Fixer on entire codebase (dry-run)
vendor/bin/php-cs-fixer fix --config=vendor/marac19901990/php-quality-pack/rules/php-cs-fixer.php --dry-run --diff
# Auto-fix code style issues
vendor/bin/php-cs-fixer fix --config=vendor/marac19901990/php-quality-pack/rules/php-cs-fixer.phpWhen you've fixed PHPStan errors or want to capture existing ones:
vendor/bin/phpstan analyse src/ -c vendor/marac19901990/php-quality-pack/rules/phpstan.neon --generate-baselineFor most projects, the default configuration works out of the box. Only customize if you have specific needs.
Create a local grumphp.yml in your project root:
imports:
- { resource: vendor/marac19901990/php-quality-pack/rules/grumphp.yml }
grumphp:
tasks:
phpcsfixer:
diff: false # Example: disable diff outputThen update config-default-path in composer.json:
"grumphp": {
"config-default-path": "grumphp.yml"
}Create a local phpstan.neon:
includes:
- vendor/marac19901990/php-quality-pack/rules/phpstan.neon
- phpstan-baseline.neon
parameters:
paths:
- src
- lib # Additional paths
ignoreErrors:
- message: "#^Project-specific error to ignore$#"Then create a grumphp.yml that points to your local config.
This package includes only base PHPStan extensions. Add framework-specific extensions to your project:
# For Symfony projects
composer require --dev phpstan/phpstan-symfony
# For PHPUnit
composer require --dev phpstan/phpstan-phpunit
# For Doctrine
composer require --dev phpstan/phpstan-doctrineThe phpstan/extension-installer automatically registers these extensions.
Use directly via composer require if you're happy with:
- PSR-12 coding standards
- PHPStan level 5 with strict rules
- Deprecation warnings enabled
Good for: personal projects, new projects, teams aligned with these standards.
Fork this repo to create your organization's version:
- Fork to
your-org/php-quality-pack - Modify
rules/files to your standards:- Change PHPStan level in
rules/phpstan.neon - Adjust PHP-CS-Fixer rules in
rules/php-cs-fixer.php - Add/remove GrumPHP tasks in
rules/grumphp.yml
- Change PHPStan level in
- Update paths in
rules/grumphp.ymlto your vendor name - Publish to Packagist as your org's package
Good for: organizations with specific coding standards.
- Level 5 (balanced)
- Strict rules enabled
- Deprecation warnings enabled
- Bleeding edge rules enabled
- Includes project's
phpstan-baseline.neon - No hardcoded paths - GrumPHP passes changed files, manual runs specify paths
- Base rulesets: PER-CS (modern successor to PSR-12) + PHP 8.2 migration rules
- Array rules: Short syntax, consistent indentation, trimmed spaces, trailing commas
- Import rules: Unused imports removed, sorted alphabetically (classes, functions, constants), no leading slash
- Spacing: Blank lines before return/throw/try, no extra blank lines, clean whitespace
- Code cleanup: No empty statements, no unneeded braces or control parentheses
- Types: Short scalar casts (
(bool)not(boolean)), native function casing - Class structure: Ordered elements (traits, constants, properties, constructor, methods by visibility)
- Style: Single quotes, no Yoda conditions, PHPDoc formatting
- PHPUnit: Snake_case test method names allowed
All rules are non-risky (safe transformations that don't change code behavior).
- Only analyzes changed files for fast pre-commit checks:
use_grumphp_paths: truefor PHPStan - only files GrumPHP detects as changedconfig_contains_finder: falsefor PHP-CS-Fixer - GrumPHP passes the file list
- Stops on first failure
- Local git hooks
If your project has local phpstan.neon, grumphp.yml, or .php-cs-fixer.dist.php:
- Regenerate baseline: Run
vendor/bin/phpstan analyse src/ -c vendor/marac19901990/php-quality-pack/rules/phpstan.neon --generate-baseline - Delete local configs: Remove
phpstan.neon,grumphp.yml,.php-cs-fixer.dist.php - Update composer.json: Set
config-default-pathtovendor/marac19901990/php-quality-pack/rules/grumphp.yml - Run composer install: Reinstalls GrumPHP hooks with new config
If your project uses Makefile targets, update them to use the vendor config paths:
stan: ## Run PHPStan
vendor/bin/phpstan analyse src/ -c vendor/marac19901990/php-quality-pack/rules/phpstan.neon
stan-baseline: ## Generate PHPStan baseline
vendor/bin/phpstan analyse src/ -c vendor/marac19901990/php-quality-pack/rules/phpstan.neon --generate-baseline
cs-fix: ## Run PHP-CS-Fixer
vendor/bin/php-cs-fixer fix --config vendor/marac19901990/php-quality-pack/rules/php-cs-fixer.php
cs-check: ## Check code style (dry-run)
vendor/bin/php-cs-fixer fix --config vendor/marac19901990/php-quality-pack/rules/php-cs-fixer.php --dry-run --diffAdd these entries to your project's .gitignore:
.php-cs-fixer.cacheExample workflow for CI:
name: Code Quality
on: [push, pull_request]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Create PHPStan baseline if missing
run: test -f phpstan-baseline.neon || echo "parameters:" > phpstan-baseline.neon
- name: Run PHPStan
run: vendor/bin/phpstan analyse src/ -c vendor/marac19901990/php-quality-pack/rules/phpstan.neon
- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --config=vendor/marac19901990/php-quality-pack/rules/php-cs-fixer.php --dry-run --diffYou may see this warning during commits:
PHP Deprecated: Using Diff::parse without raw information is deprecated.
This comes from gitonomy/gitlib (a GrumPHP dependency) and doesn't affect functionality. It will be resolved when GrumPHP updates the dependency.
MIT License - see LICENSE for details.