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.
Architecture fit: This package integrates seamlessly with Symfony applications using PHPStan for static analysis. It extends PHPStan's capabilities to understand Symfony-specific patterns (container services, console commands, Messenger handlers), filling critical type inference gaps in the framework. The extension is purpose-built for Symfony's architecture, leveraging the container XML dump for accurate metadata.
Integration feasibility: High feasibility via Composer dependency. Requires minimal setup if using phpstan/extension-installer, but manual configuration is straightforward. Critical dependency on Symfony's container cache generation (cache:clear), which must be executed before analysis. Configuration complexity scales with project size and Symfony version (e.g., Symfony 5.3+ requires additional scanDirectories/scanFiles).
Technical risk: Moderate. Misconfigured containerXmlPath causes false negatives (undetected errors). Dependency on Symfony's cache structure creates fragility during framework upgrades or custom container configurations. Potential for false positives when using dynamic service resolution or optional dependencies (e.g., has() checks). Compatibility risks exist for non-standard Symfony deployments (e.g., custom kernel setups).
Key questions:
Stack fit: Ideal for Symfony projects using PHPStan for quality gates. Requires PHPStan 1.0+ and Symfony 4.4+. Works best with standard Symfony directory structures. Compatible with both monolithic and microservice architectures when container XML is accessible.
Migration path:
composer require --dev phpstan/phpstan-symfonybin/console cache:clear --env=dev)phpstan.neon with containerXmlPath matching Symfony versionscanDirectories and scanFiles for config filesconsoleApplicationLoader--level=max to leverage all rulesCompatibility: Fully supports Symfony 4.4–6.x. Requires PHP 8.0+ for latest versions. Known to conflict with custom container compilers that modify service definitions after cache generation. Works with Composer 2.x but may need adjustment for non-standard autolo
How can I help you explore Laravel packages today?