Skip to content

Conversation

@JanTvrdik
Copy link
Member

Summary

  • Adds optional integration with phpstan/phpstan-doctrine's ObjectMetadataResolver
  • When phpstan-doctrine is installed and configured, uses real Doctrine ClassMetadata for resolving association target types
  • Falls back to attribute-based resolution when metadata is unavailable
  • Supports both Doctrine ORM 2.x (array mappings) and 3.x (object mappings)

Changes

  • Added phpstan/phpstan-doctrine to require-dev and suggest
  • Modified EntityPreloaderCore to accept optional ObjectMetadataResolver and try metadata resolution first
  • Updated EntityPreloaderReturnTypeExtension and EntityPreloaderRule with constructors
  • Converted rules.neon to service syntax for consistency

Benefits

  • More accurate type inference for entities using XML/YAML mappings (not just PHP attributes)
  • Seamless integration - autowiring handles the optional dependency injection

Test plan

  • PHPStan analysis passes
  • All existing tests pass
  • Dependency analysis passes

@JanTvrdik JanTvrdik force-pushed the phpstan-doctrine-integration branch 6 times, most recently from 7bc37d9 to acbf030 Compare December 8, 2025 13:29
@JanTvrdik JanTvrdik requested a review from janedbal December 8, 2025 13:36
When phpstan/phpstan-doctrine is installed and configured with an
ObjectManager loader, the PHPStan extension now uses real Doctrine
ClassMetadata for resolving association target types. This provides
more accurate type inference for entities using XML/YAML mappings.

Falls back to attribute-based resolution when metadata is unavailable.
@JanTvrdik JanTvrdik force-pushed the phpstan-doctrine-integration branch from acbf030 to 36a6ecd Compare December 8, 2025 13:41
@JanTvrdik JanTvrdik merged commit 8a236fb into master Dec 8, 2025
21 checks passed
@JanTvrdik JanTvrdik deleted the phpstan-doctrine-integration branch December 8, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants