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.
HandleTrait wrappers), critical for CQRS implementations where query/handler return types must be explicit. Enables safer refactoring of domain logic.#[Required] attributes) without breaking changes. Reduces technical debt by standardizing type safety across components.Adopt if:
mixed return types, validating config).Look elsewhere if:
#[Required])."This package integrates seamlessly with our existing Symfony stack to reduce bugs by 30–50% through static analysis. By catching type errors early—like invalid service injections or undefined console arguments—we’ll cut debugging time and improve deployment reliability. It’s a low-cost, high-impact tool that aligns with our tech debt reduction goals, with minimal overhead (only ~5–10% slower than PHPStan alone). Competitors like Laravel have similar tools, but Symfony’s ecosystem lacks this level of precision—making it a unique differentiator for our platform."
*"phpstan/phpstan-symfony supercharges our PHPStan setup for Symfony by:
mixed return types for critical methods (e.g., ContainerInterface::get(), HandleTrait::handle()), enabling IDE autocompletion and safer refactoring.#[Required] attributes and PHP config files.How to start:
composer.json (dev dependency).phpstan.neon with your container XML path (e.g., var/cache/dev/App_KernelDevDebugContainer.xml).phpstan analyse src --level=8—watch it catch issues you’ve been debugging manually.Trade-offs:
::has() checks for optional services).Next steps: Let’s pilot this in the payments module, where service injection errors are costly. I’ll provide a PR template for the config."*
How can I help you explore Laravel packages today?