wyrihaximus/phpstan-rules-wrapper
Composer wrapper that bundles popular PHPStan rule sets and extensions into one install. Works out of the box with phpstan/extension-installer, pulling in strict, deprecation, PHPUnit, Mockery, dead-code detection, PSR-3, and type-coverage rules.
Installation:
composer require --dev wyrihaximus/phpstan-rules-wrapper
This leverages phpstan/extension-installer under the hood, so no additional configuration is required in phpstan.neon.
First Use Case: Run PHPStan with the default configuration:
vendor/bin/phpstan analyse
The package automatically integrates 10+ PHPStan rule sets (e.g., phpstan/phpstan-strict-rules, symplify/phpstan-extensions, shipmonk/dead-code-detector).
Where to Look First:
phpstan.neon for any existing rules (none needed for this package).Zero-Configuration Integration:
includes are required in phpstan.neon.Customizing Rules:
phpstan.neon:
includes:
- vendor/wyrihaximus/phpstan-rules-wrapper/phpstan.neon
rules:
Shipmonk\DeadCodeDetector\DeadCodeDetectorRule: false # Disable dead code detection
PHPStan\StrictRules\StrictPropertyTypeRule: true # Explicitly enable strict rules
extends to inherit and modify:
extends:
- vendor/wyrihaximus/phpstan-rules-wrapper/phpstan.neon
CI/CD Workflows:
phpunit.xml:
<phpunit>
<phpstan>
<config>phpstan.neon</config>
<autoload>
<file>vendor/autoload.php</file>
</autoload>
</phpunit>
</phpunit>
vendor/bin/parallel-lint --phpstan --workers=4
Laravel-Specific Use Cases:
symplify/phpstan-extensions (included) to analyze Laravel’s bind(), singleton(), and tag() methods:
services:
- Symplify\PHPStanExtensions\Services\Container\ContainerService
phpstan/phpstan-phpunit to validate route parameters and controller methods.Dead Code Detection:
shipmonk/dead-code-detector to find unused:
app/Models/User.php:
vendor/bin/phpstan analyse --level=max --no-progress-bar
Onboarding New Developers:
composer.json and run composer install. No additional setup required.Refactoring Sessions:
phpstan/phpstan-strict-rules to catch type inconsistencies during refactoring.array types to strict generics:
// Before
public function getUsers(): array { ... }
// After (with strict rules)
public function getUsers(): array<User> { ... }
Deprecation Management:
phpstan/phpstan-deprecation-rules flags deprecated Laravel methods (e.g., Route::resource() vs. Route::apiResource()).[ERROR] Method Illuminate\Routing\Router::resource() is deprecated since Laravel 9.0.
rector:
Use symplify/phpstan-extensions (included) to auto-fix issues with Rector:
vendor/bin/rector process src --dry-run
parameters.excludePaths in phpstan.neon:
parameters:
excludePaths:
- tests/
- database/
phpstan.neon by extending it:
extends:
- vendor/wyrihaximus/phpstan-rules-wrapper/phpstan.neon
rules:
- YourVendor\YourRules\YourRule
Rule Conflicts:
ergebnis.noPhpstanIgnore) are disabled by default due to conflicts with Laravel’s .phpstan.ignore files.phpstan.neon:
rules:
Ergebnis\PhpStanRules\Rules\NoPhpstanIgnoreRule: false
Performance Overhead:
type-coverage or dead-code-detector can slow down analysis.vendor/bin/phpstan analyse --level=max --memory-limit=2G
PHP Version Requirements:
composer.json).12.x for PHP 8.1).False Positives:
phpstan-mockery may flag legitimate Mockery usage.mockery.directMockingAllowed in phpstan.neon:
services:
- PHPStan\Mockery\MockeryService
parameters:
mockery:
directMockingAllowed: true
Vendor Directory Bloat:
vendor/ size.composer install --prefer-dist to optimize disk usage.Isolate Rule Issues:
vendor/bin/phpstan analyse --level=max --rules=PHPStan\StrictRules\*
--error-format=json for machine-readable output:
vendor/bin/phpstan analyse --error-format=json > errors.json
Check Rule Compatibility:
composer.lock match the wrapper’s dependencies.symplify/phpstan-extensions is ^10.0 for Laravel 10.x.Disable All Rules:
rules:
*: false
Neon File Location:
vendor/wyrihaximus/phpstan-rules-wrapper/phpstan.neon.ln -s vendor/wyrihaximus/phpstan-rules-wrapper/phpstan.neon config/phpstan-wrapper.neon
Level-Specific Rules:
strict-rules) are level-dependent (e.g., --level=max).phpstan.neon:
levels:
project:
rules:
- PHPStan\StrictRules\*
Laravel-Specific Rules:
symplify/phpstan-extensions may flag Laravel’s magic methods (e.g., __get(), __set()).parameters:
excludePaths:
- vendor/laravel/
Add Custom Rulesets:
composer.json to include additional rules:
"extra": {
"phpstan-rules-wrapper": {
"custom-rules": ["vendor/package/rules.neon"]
}
}
Override Individual Rules:
parameters.rules to fine-tune included rulesets:
parameters:
rules:
Shipmonk\DeadCodeDetector\
How can I help you explore Laravel packages today?