Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
81.82% |
9 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
UnionDenormalizer | |
81.82% |
9 / 11 |
|
50.00% |
1 / 2 |
6.22 | |
0.00% |
0 / 1 |
supportsDenormalization | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
5.93 | |||
denormalize | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Apie\Serializer\Normalizers; |
4 | |
5 | use Apie\Core\ApieLib; |
6 | use Apie\Core\Lists\ItemHashmap; |
7 | use Apie\Core\Lists\ItemList; |
8 | use Apie\Serializer\Context\ApieSerializerContext; |
9 | use Apie\Serializer\Interfaces\DenormalizerInterface; |
10 | use Apie\TypeConverter\ReflectionTypeFactory; |
11 | use Psr\Http\Message\UploadedFileInterface; |
12 | use ReflectionIntersectionType; |
13 | use ReflectionNamedType; |
14 | use ReflectionUnionType; |
15 | |
16 | class UnionDenormalizer implements DenormalizerInterface |
17 | { |
18 | |
19 | public function supportsDenormalization(float|bool|int|string|UploadedFileInterface|ItemHashmap|ItemList|null $object, string $desiredType, ApieSerializerContext $apieSerializerContext): bool |
20 | { |
21 | if (strpos($desiredType, '&') !== false || strpos($desiredType, '|') !== false) { |
22 | try { |
23 | $type = ReflectionTypeFactory::createReflectionType($desiredType); |
24 | return $type instanceof ReflectionUnionType || $type instanceof ReflectionIntersectionType; |
25 | } catch (\Throwable) { |
26 | return false; |
27 | } |
28 | } |
29 | return false; |
30 | } |
31 | |
32 | public function denormalize(float|bool|int|string|UploadedFileInterface|ItemHashmap|ItemList|null $object, string $desiredType, ApieSerializerContext $apieSerializerContext): mixed |
33 | { |
34 | $type = ReflectionTypeFactory::createReflectionType($desiredType); |
35 | return $apieSerializerContext->denormalizeFromTypehint( |
36 | $object, |
37 | $type |
38 | ); |
39 | } |
40 | } |