weirdan/doctrine-psalm-plugin
Psalm plugin for Doctrine ORM projects. Adds smarter type inference for EntityManager, repositories, proxies and collections, reducing false positives and improving static analysis of Doctrine entities and queries in PHP applications.
Enhancing Code Quality & Developer Experience (DX):
Refactoring & Tech Debt Reduction:
@ORM\* annotations).CI/CD & Shift-Left Quality:
Scaling Developer Onboarding:
Adopt if:
Look elsewhere if:
"This plugin is a low-cost, high-impact way to reduce bugs in our Doctrine-heavy codebase. By integrating with Psalm, it catches ORM-related errors early—saving dev time on debugging and reducing production incidents. For example, it flags issues like incorrect entity relationships or proxy mismatches before they reach QA, which directly cuts our tech debt and support costs. The maintenance overhead is minimal (just a Composer dependency), and it aligns with our investment in static analysis tools. Given the 12.53 opportunity score and active development, this is a no-brainer for teams working on our core domain logic."
*"The weirdan/doctrine-psalm-plugin solves two critical pain points in our stack:
- False Positives: Psalm struggles with Doctrine’s dynamic behavior (proxies, lazy-loading, metadata). This plugin teaches Psalm the ‘language’ of Doctrine, reducing noise in our static analysis.
- Actionable Errors: It surfaces real bugs—like invalid repository calls or missing
@ORM\*annotations—during CI, not in production. For example, it’ll catch cases where a proxy isn’t initialized properly, which is a common source of N+1 queries or runtime exceptions.Why Psalm? We’re already using it for general typing, and this plugin extends its coverage to Doctrine. It’s lightweight (no runtime overhead), integrates seamlessly with our existing workflow, and has a strong signal-to-noise ratio for ORM-heavy code.
Implementation: Add it to
psalm.plugin-sets, configure inpsalm.xml, and run in CI. We can phase it in by starting with a strictness trial (e.g.,--no-cachemode) to validate the value before enforcing it.Alternatives? PHPStan has similar plugins, but Psalm’s type inference is more aggressive for Doctrine patterns, and this plugin is actively maintained (last release: Jan 2025)."*
*"This plugin will save you hours of debugging by catching Doctrine issues early. Imagine:
- No more ‘
Call to a member function getX() on null’ errors from lazy-loaded proxies—Psalm will warn you if a proxy isn’t initialized.- Automatic type hints for repository methods (e.g.,
find()returns?Userinstead ofmixed).- Clear errors when you forget to add
@ORM\GeneratedValueor misconfigure relationships.It’s like having a second pair of eyes for your ORM logic, but automated. And since it runs in CI, you’ll catch these issues before they block your PR.
How to use it:
- Install via Composer:
composer require --dev weirdan/doctrine-psalm-plugin.- Add to
psalm.xml:<plugin_class>weirdan\DoctrinePsalmPlugin\Plugin</plugin_class>- Run
./vendor/bin/psalm—you’ll see fewer false alarms and more real Doctrine-related errors.Pro Tip: Start with
--no-cacheto see the full impact, then adjustpsalm.xmlto ignore false positives after the plugin catches the real ones."*
How can I help you explore Laravel packages today?