wyrihaximus/phpstan-rules-wrapper
Meta package that bundles popular PHPStan rule sets via phpstan/extension-installer. Install once to enable strict, deprecation, PHPUnit/Mockery, dead-code detection, type-coverage, PSR-3, and more with minimal configuration.
Install the package:
composer require --dev wyrihaximus/phpstan-rules-wrapper
This leverages phpstan/extension-installer under the hood, so no additional configuration is required in most cases.
First Use Case: Run PHPStan with the default configuration:
vendor/bin/phpstan analyse
The package automatically includes 10+ popular PHPStan rule sets (e.g., phpstan/phpunit, symplify/phpstan-extensions, shipmonk/dead-code-detector).
Where to Look First:
phpstan.neon (or phpstan.dist.neon) for pre-configured rules.Integrate with CI/CD: Add PHPStan to your GitHub Actions/GitLab CI:
- name: PHPStan
run: vendor/bin/phpstan analyse --level=max
Use --level=max for strict checks or --level=5 for a balanced approach.
Customize Rules:
Extend phpstan.neon to override defaults:
includes:
- vendor/wyrihaximus/phpstan-rules-wrapper/phpstan.neon
- phpstan-custom.neon # Your overrides
services:
phpstan.rules.files:
- app/**/*.php
- tests/**/*.php
Targeted Analysis: Run PHPStan on specific files/directories:
vendor/bin/phpstan analyse src/Service --level=7
Dead Code Detection:
Use shipmonk/dead-code-detector (included) to find unused code:
vendor/bin/phpstan analyse --enable=deadCode
Mockery/Unit Test Rules:
Enable phpstan-mockery for better mock analysis:
services:
phpstan.parallel:
enabled: true # Speed up analysis
Strict Rules:
Combine with phpstan-strict-rules for stricter type checks:
vendor/bin/phpstan analyse --level=9
Deprecation Warnings:
Use phpstan-deprecation-rules to catch deprecated APIs:
vendor/bin/phpstan analyse --enable=deprecation
Rule Conflicts:
ergebnis.noPhpstanIgnore) are disabled by default due to conflicts. Check the release notes for disabled rules.phpstan.neon:
services:
phpstan.rules:
ergebnis.noPhpstanIgnore: false
Performance:
--parallel for faster runs:
vendor/bin/phpstan analyse --parallel
PHP Version Requirements:
Vendor Directory:
vendor directory (see PR #200). Ensure your .gitignore includes:
vendor/
Isolate Rule Issues: Run PHPStan with a single ruleset to debug:
vendor/bin/phpstan analyse --rules-set=phpstan/phpstan-phpunit
Check Rule Sources:
Use --debug to see which rules are being applied:
vendor/bin/phpstan analyse --debug
Override Specific Rules: Disable problematic rules temporarily:
services:
phpstan.rules:
shipmonk.deadCode: false # Disable dead code detection
Add Custom Rulesets:
Extend the wrapper by adding your own rules to composer.json:
{
"extra": {
"phpstan-rules-wrapper": {
"custom-rules": ["vendor/package/phpstan-rules.neon"]
}
}
}
Update Rulesets: The package uses Renovate for dependency updates. Monitor releases for breaking changes.
PHPStan Configuration:
Merge custom phpstan.neon with the wrapper’s defaults:
extends: vendor/wyrihaximus/phpstan-rules-wrapper/phpstan.neon
How can I help you explore Laravel packages today?