phpstan/phpstan-symfony
PHPStan extension for Symfony that improves static analysis with precise return types and framework-specific rules. Understands container/services, parameters, controllers, request/headers, serializer, forms, messenger handlers, cache callbacks, config tree builders, and more.
composer require --dev command.phpstan/extension-installer for zero-configuration setups.var/cache/dev/*.xml files (typically available in dev environments).::has() checks may hide genuine errors (trade-off between precision and convenience).constantHassers be disabled globally to prioritize catching undefined services?ContainerInterface checks are Symfony-specific; generic PHPStan rules apply elsewhere.extension-installer.containerXmlPath in phpstan.neon (test locally first).constantHassers and scanDirectories based on false positives.phpstan --level=max).loadFromExtension() may require manual stubs.phpstan.neon (e.g., suppress specific rules).containerXmlPath may break if Symfony’s cache directory structure changes (e.g., after cache:clear).../var/cache/dev/) and document in README.md.phpstan/phpstan-symfony to a specific minor version to avoid breaking changes.ContainerInterface changes) and update rules accordingly.STATIC_ANALYSIS.md with:
::has() with optional dependencies).--error-format=github-pr-check for actionable PR feedback.phpstan analyze --parallel) for large codebases.phpstan.neon in a monorepo or shared template.max for core, medium for libraries).| Failure Type | Impact | Mitigation |
|---|---|---|
Missing containerXmlPath |
No container checks run. | Fail loudly in CI with a clear error message. |
| Outdated Symfony stubs | False negatives (e.g., missed errors). | Update stubs via composer update. |
| Overly strict rules | Block merges for legitimate code. | Use --level=medium initially, adjust later. |
| High memory usage | CI timeouts. | Enable lazy loading; split analysis. |
False positives in ::has() |
Noise in PR reviews. | Disable constantHassers or suppress rules. |
How can I help you explore Laravel packages today?