-
Notifications
You must be signed in to change notification settings - Fork 108
fix: update template annotations to remove covariant keyword #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.0.x
Are you sure you want to change the base?
fix: update template annotations to remove covariant keyword #663
Conversation
What is the expected moment to have this merged please? We want to upgrade to php8.4 but this is a blocking issue! |
@mroeling Please describe what error are you experiencing and why it's blocking you from upgrading to 8.4. It'd be helpful in helping me underseand why this change is needed. |
Ofc, no problem. Info:
So basically we are waiting for this change to get into the mainstream so that we can test with php8.4. Using php8.4-fpm there is no issue, but for CLI this is blocking. |
Please show the path where you're running PHPStan from, the path to bin/phpstan. There is something atypical about your setup. These errors from vendor stubs are usually filtered and not showed. |
We use phing as "executor". From the root (=phing.dir), the vendor map is in
The getReflectionClass() functions from these 3 Doctrine classes are called within our codebase, in the |
That looks okay. Personally I'd try this:
Typically people don't run PHPStan with these absolute paths and that might be throwing off the filtering logic. These bug(s) still need to be fixed, I just want to help you meanwhile. |
Much appreciated! I'll give it a try. |
Description
This PR addresses PHPStan errors related to template type variance in Doctrine's metadata classes. The errors were occurring because the template type
T
was declared as covariant but was being used in an invariant position in thegetReflectionClass()
method.The Problem
The following errors were reported by PHPStan:
Doctrine\ODM\MongoDB\Mapping\ClassMetadata::getReflectionClass()
Doctrine\ORM\Mapping\ClassMetadataInfo::getReflectionClass()
Doctrine\Persistence\Mapping\ClassMetadata::getReflectionClass()
The Solution
We removed the
-covariant
modifier from the template type declarations in:MongoClassMetadataInfo.stub
ORM/Mapping/ClassMetadata.stub
ORM/Mapping/ClassMetadataInfo.stub
Persistence/Mapping/ClassMetadata.stub
Why This Works
The covariance modifier was inappropriate in this case because:
getReflectionClass()
method returns aReflectionClass<T>
Issues
#646