- How do I install phpstan/phpstan-doctrine for a Laravel project?
- Run `composer require --dev phpstan/phpstan-doctrine` in your project root. Ensure PHPStan is also installed (`composer require --dev phpstan/phpstan`). Configure it in `phpstan.neon` by extending the Doctrine ruleset.
- Does this package support Laravel’s multi-database connections (e.g., MySQL + PostgreSQL)?
- Yes, the latest version introduces multi-EntityManager support. Configure custom `objectManagerLoaders` in `phpstan.neon` to analyze queries across connections. Use Laravel’s Service Container to dynamically resolve managers if needed.
- Will this break my existing PHPStan configuration for Laravel?
- No, the package maintains backward compatibility. Update to `^2.0.28` and verify your `phpstan.neon` works unchanged. Only enable multi-manager features if using multiple Doctrine connections.
- How does this improve Laravel’s IDE experience (e.g., PhpStorm)?
- It reduces false positives by validating Doctrine queries, repository methods, and entity relationships at static analysis time. This cuts down on IDE noise and catches DQL/ORM errors early, even before runtime.
- Can I use this with Laravel’s Service Container and dependency injection?
- Absolutely. The package infers return types for `EntityManagerInterface` and repository methods injected via Laravel’s container. It also supports context-aware entity managers tied to specific database connections.
- What Laravel versions and PHPStan versions are supported?
- Works with Laravel 8+ and PHPStan 2.2.x (PHPStan 1.x is deprecated). The package is Doctrine-agnostic, so it covers Laravel’s ORM use case. Tested with PHP 8.0+.
- How do I configure it for multiple Doctrine connections in Laravel?
- Define custom `objectManagerLoaders` in `phpstan.neon` pointing to loader classes that resolve each `EntityManagerInterface` (e.g., `app('em.primary')` and `app('em.secondary')`). Start with one manager, then expand.
- Does this package slow down my CI/CD pipeline?
- No runtime overhead exists. Static analysis adds minimal time. Use `phpstan analyse --parallel` to speed up multi-manager setups. Benchmark with your existing CI workflow.
- What if I get false negatives with multi-EntityManager setups?
- Misconfigured loaders may miss queries. Use `phpstan analyse --generate-report` to check coverage. Debug with `--debug` and ensure all managers are properly registered in `phpstan.neon`.
- Are there alternatives to phpstan/phpstan-doctrine for Laravel?
- Psalm is a viable alternative, but this package is optimized for Laravel’s multi-manager architectures and integrates seamlessly with PHPStan’s ecosystem. Start with this if you’re already using PHPStan.