Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Phpstan Doctrine

Phpstan Doctrine Laravel Package

phpstan/phpstan-doctrine

PHPStan extension for Doctrine that validates DQL and QueryBuilder, checks repository findBy and magic methods, improves EntityManager and repository type inference, supports ORM and ODM, and reports mapping, entity type, and proxy issues.

View on GitHub
Deep Wiki
Context7

phpstan/phpstan-doctrine is a PHPStan extension that brings static analysis to Doctrine ORM and ODM projects. It validates DQL queries, resolves repository generics, and infers precise types for entity lookups—catching mapping mistakes before runtime.

  • DQL & QueryBuilder validation for parse errors, unknown entities, and invalid fields
  • Repository awareness: magic findBy*/countBy* methods and EntityRepository<T> generics
  • Type inference for EntityManager::find(), getRepository(), and Query::getResult()
  • Mapping checks between column/relation definitions and property types
  • Proxy safety warnings for final entities and constructors
Frequently asked questions about Phpstan Doctrine
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
ably/pubsub-server
mstfkhazaal/defender
mfonte/base62x
karnoweb/metapilot
tobya/bcsapiwrapper
swalker2/cpanel
vish4395/laravel-translation-manager
morningtrain/economic
teksite/systeminfo-laravel
atomcms/voting
run6/weather
siokas/laravelembeddirectives
adamlien/pkuuids
gilsonsouza/lara-doc-generator
manelgavalda/enrollment_mobile
unabomber/timezone
delatbabel/contacts
astritzeqiri/g-recaptcha
kevinongko/laravel-genode
developeruz/laravel-analytics