lookyman/phpstan-symfony
PHPStan extension for Symfony projects. Improves static analysis with Symfony-specific type inference and container/framework awareness, helping catch bugs earlier and reduce false positives when analyzing services, controllers, and common Symfony patterns.
Check Compatibility Since this package is deprecated and last updated in 2018, verify if your project still uses Symfony 3.x/4.x (its target range). If using Symfony 5+ or PHPStan 1.0+, consider alternatives like:
phpstan/phpstan-symfony (official, actively maintained)symplify/phpstan-symfony (Symfony-focused fork).Installation
Add to composer.json (if absolutely necessary):
composer require --dev lookyman/phpstan-symfony
Ensure PHPStan is also installed:
composer require --dev phpstan/phpstan
First Use Case Run PHPStan with Symfony rules:
vendor/bin/phpstan analyse src --level=max
Check for Symfony-specific errors (e.g., invalid service calls, missing annotations).
Symfony-Specific Rule Integration
ContainerInterface calls, Route annotations).ParamConverter services or invalid EventDispatcher listeners.Configuration
Extend phpstan.neon to enable Symfony rules:
includes:
- vendor/lookyman/phpstan-symfony/extension.neon
Workflow Integration
- name: Run PHPStan
run: vendor/bin/phpstan analyse --level=max
phpstan with husky to catch issues early.Custom Rules
SymfonyExtension class (if needed).phpstan/phpstan-symfony for compatibility.phpstan/phpstan-doctrine or phpstan/phpstan-laravel (if applicable).Deprecation Risks
ClassNotFoundException for Symfony 5+ classes (e.g., AutowiringPass).Rule Inaccuracy
YamlFileLoader assumptions).Configuration Conflicts
phpstan/phpstan-symfony) can cause rule duplication or silent failures.Performance Overhead
Enable Verbose Mode:
vendor/bin/phpstan analyse --verbose
Helps identify which rules are failing.
Isolate Rules: Temporarily disable other extensions to check if conflicts exist:
includes:
- vendor/phpstan/phpstan-symfony/extension.neon # Try official instead
Check Symfony Version:
Ensure your symfony/* packages match the package’s supported range (Symfony 3.x/4.x).
SymfonyExtension:
class CustomSymfonyExtension extends \Lookyman\PHPStanSymfony\SymfonyExtension {
public function getRuleSet(): RuleSet {
return RuleSet::create([new CustomRule()]);
}
}
phpstan.neon:
suppress:
- Lookyman\PHPStanSymfony\Rules\InvalidServiceRule::class
If stuck with this package:
vendor/lookyman/phpstan-symfony/src/Rules/).symplify/phpstan-symfony for Symfony 4.4+.phpstan/phpstan-laravel.How can I help you explore Laravel packages today?