-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
Fix setOptions typehints. #805
Fix setOptions typehints. #805
Conversation
🤔 where is the conflict? Both methods seem compatible to me… a method accepting mixed also accepts string, by definition. It also seems compatible to PHP itself, by the way: https://3v4l.org/Q2FJN… or even to Psalm's playground: https://psalm.dev/r/75cc3938a8 |
I think the real issue is that this job is running on PHP 7.4, while |
Interesting, I've gotten so used to PHP being inflexible about types that I didn't realize this could possibly be legal. That being said, under what circumstance would it make sense to use something other than a string as an option key? If there is a strong reason, then maybe this needs to be addressed by changing the Psalm configuration in DoctrineORMModule. |
To be clear, I'm not saying we should not merge your change, but let's first figure out what is so wrong with the Psalm job in |
Ah actually, It's running on php 8.2, but the target version is php 7.4 🤔 |
Setting the target php version in the config file, like we do on the ORM fixes the issue: https://github.com/doctrine/orm/blob/2.15.x/psalm.xml#L4 Here is the reason behind specifying it: doctrine/orm#9314 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this looks like a breaking change for callers, since the parent method is called, $key
has to be a string every time this is called.
Thanks, @greg0ire! Would you like me to open a PR to raise the version to match in DoctrineORMModule? If so, I can do that tomorrow morning! |
Yes please, I think it makes sense to avoid future similar weird surprises. |
The argument 1 typehint on setOption conflicts with the Laminas\Form\ElementInterface -- see: https://github.com/laminas/laminas-form/blob/3.11.x/src/ElementInterface.php#L36
This problem was detected by Psalm when I began work on adding DoctrineModule v6 support to DoctrineORMModule.
This string typehint was introduced in laminas-form v3, so the "mixed" typehint probably worked in combination with v2 and earlier. Since this module depends on laminas-form v3.4.1 or later, there should be no problem with making this adjustment.