mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Use ClassMetadata[Info] class in type hints instead of the ClassMetadata interface #6744
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mpdude on GitHub (Jun 7, 2021).
This was sparked by #8402:
At least
\Doctrine\ORM\Mapping\ClassMetadataFactory::doLoadMetadataand\Doctrine\ORM\Mapping\ClassMetadataFactory::validateRuntimeMetadata(with the changes of #8402) use\Doctrine\Persistence\Mapping\ClassMetadata(an interface) as DocBlock type-hints for parameters, but access\Doctrine\ORM\Mapping\ClassMetadataInfo::$discriminatorMapthrough it.This causes PHPStan and Psalm to complain, since
Interfaces cannot have properties.When code like
$parent->discriminatorMapis supposed to be kept as-is (that is, no corresponding method added in theClassMetadatainterface), the type hints need to be changed. This might cascade through a chain of called methods, though.@greg0ire commented on GitHub (Jun 14, 2021):
I don't think changing the type declarations is an option for
doLoadMetadata: it's forbidden to narrow them down since that would break the LSP.Instead we could throw if anything else than an ORM
ClassMetadatais passed.For
validateRuntimeMetadata()it's another story since there is no method override. We can change the type declaration 👍After doing that, we should regenerate PHPStan and Psalm baselines in case they contain something about this.
@mpdude commented on GitHub (Jun 8, 2023):
Found this old issue. Don't really recall what I was talking about, might have been resolved since then.
@greg0ire commented on GitHub (Jun 8, 2023):
I think the
@extendsannotation introduced in98d77043d8 (diff-3e426fe47b58d2d4b970b1b7a0cbf5999af950e4f84e48dce4bee5061b57ed31)does fix it.