Conversation
…ions Previously, when using associations without explicit targetEntity attribute, PHPStan would only infer the target entity from the property type for OneToOne associations. This left ManyToOne associations without targetEntity attribute incorrectly reported as "not a valid Doctrine association". This change extends type inference to also work for ManyToOne associations, matching the behavior users expect when not using phpstan-doctrine. Fixes #37
dbf9e23 to
f744d0e
Compare
Member
|
Or, we might drop this fallback completely to mitigate all maintenance. And only support PHPStan inference when phpstan-doctrine is used properly. |
janedbal
approved these changes
Dec 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ManyToOneassociations without explicittargetEntityattributeOneToOneassociations could infer target entity from property typeProblem
When using associations without explicit
targetEntityattribute:PHPStan would incorrectly report: "Property 'Employee::$supervisor' is not a valid Doctrine association."
Solution
Extended the
getAssociationTargetTypeFromPropertyReflectionmethod to also infer target entity from property type forManyToOneassociations, not justOneToOne.Test plan
EmployeeandEmployeeSettingstest entities replicating issue PHPStan rules not working correctly? #37targetEntityFixes #37