-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Handle union types for typed properties and docblocks #1330
Conversation
ping @yyaremenko @gam6itko :) |
i'm sorry for the delay, @dgafka could you please rebase this? |
@goetas branch is up to date with master now :) |
Hello, trying to upgrade a project to 8.1 and running into failed tests because of this. How can I help to get this merged/tested etc? |
Just tested this on our app and can confirm it seems to work well for us. |
Hey @goetas, |
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.
@dgafka - Could you take a look at the code style issues that has been reported by the coding standard, please? I believe they can be fixed automatically by the tool. Also you need to exclude your fixture from PHPStan analysis - as in CI it is running with PHP7.4 that do not support union types.
@scyzoryck how to fix that:
as excluding it from phpstan analyse does not change a thing:
|
…izer into feature/handle-union-types
I've put the test under phpstan ignore too. Tests are passing now. |
Co-authored-by: Marcin Czarnecki <[email protected]>
Extracted separate phpstan analysis for PHP 7.4. |
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.
Thanks! Looks good for me! @goetas - Could you take a look, please?
This handle union types for typed properties and DocBlock type resolver.
The solution allows for defining union types for above, which was previously failing during cache building phase.
As union type is non implicit in what we are actually serializing / deserializing, we are not trying to recognize which type user want to use in specific context.
How does serialization works?
Serializing knows which type to use, as it actually holds the value that is going to be serialized. It use that value to infer the type and do the serialization.
How does deserialization works?
The deserialization will throw an exception as we can't guess, which type user would like to pick.
If developer will define Type Attribute, it will be chosen as default one.
This is a place for improvement. Possible we could introduce custom union deserializing handler, that would decide on his own what class he would like to deserialize too.