Support PHP8's Union and Mixed types#495
Conversation
|
I believe this is now feature-complete |
d2ef7ef to
7d55492
Compare
|
With the recent CI changes this is now green - once any review comments are addressed it can be merged and then we'll be able to update composer.json for PHP8 I think? |
7d55492 to
fe3e590
Compare
fe3e590 to
a2bb56c
Compare
|
I ran into the same issue today with https://travis-ci.org/github/milesj/decoda/jobs/728420774 and PHP8 not being testable right now. //EDIT: using --ignore-platform-reqs works as a workaround for now. |
|
I realised I wasn't providing an appropriate default promise for union types so have added it |
| $types, | ||
| function(string $type) { | ||
| if(class_exists($type) || interface_exists($type)) { | ||
| static function(string $type1, string $type2) { |
There was a problem hiding this comment.
Here we:
- Prefer to return a scalar or object promise rather than a null (existing behaviour)
- Prefer to return an object over a scalar (on the basis that the typical
Obj|falsecase is similar to the above) - If there are more than one object type in a union, or no objects and more than one scalar, we are just picking one of them essentially at random
3 here is maybe problematic, or at least counter-intuitive. We could sort by alphabetical order or something, but it doesn't seem to make sense. We could in theory use the order of the union except that ReflectionUnionType::getTypes 'has no guaranteed order'
Resolves #482
This pushes the types logic from the ArgumentNode and MethodNode (and the TypeHintReference) down into smaller value objects for ArgumentTypeNode and ReturnTypeNodes, and then expands it to support Unions