Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
76.92% |
10 / 13 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ReflectionTypeNormalizer | |
76.92% |
10 / 13 |
|
50.00% |
2 / 4 |
5.31 | |
0.00% |
0 / 1 |
| supportsDenormalization | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| denormalize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| supportsNormalization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| normalize | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\Serializer\Normalizers; |
| 3 | |
| 4 | use Apie\Core\Lists\ItemHashmap; |
| 5 | use Apie\Core\Lists\ItemList; |
| 6 | use Apie\Core\ValueObjects\Utils; |
| 7 | use Apie\Serializer\Context\ApieSerializerContext; |
| 8 | use Apie\Serializer\Interfaces\DenormalizerInterface; |
| 9 | use Apie\Serializer\Interfaces\NormalizerInterface; |
| 10 | use Apie\TypeConverter\ReflectionTypeFactory; |
| 11 | use Psr\Http\Message\UploadedFileInterface; |
| 12 | use ReflectionIntersectionType; |
| 13 | use ReflectionNamedType; |
| 14 | use ReflectionType; |
| 15 | use ReflectionUnionType; |
| 16 | |
| 17 | class ReflectionTypeNormalizer implements DenormalizerInterface, NormalizerInterface |
| 18 | { |
| 19 | public function supportsDenormalization( |
| 20 | string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, |
| 21 | string $desiredType, |
| 22 | ApieSerializerContext $apieSerializerContext |
| 23 | ): bool { |
| 24 | return in_array( |
| 25 | $desiredType, |
| 26 | [ |
| 27 | ReflectionType::class, |
| 28 | ReflectionNamedType::class, |
| 29 | ReflectionUnionType::class, |
| 30 | ReflectionIntersectionType::class |
| 31 | ] |
| 32 | ); |
| 33 | } |
| 34 | public function denormalize( |
| 35 | string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, |
| 36 | string $desiredType, |
| 37 | ApieSerializerContext $apieSerializerContext |
| 38 | ): mixed { |
| 39 | return ReflectionTypeFactory::createReflectionType(Utils::toString($object)); |
| 40 | } |
| 41 | public function supportsNormalization( |
| 42 | mixed $object, |
| 43 | ApieSerializerContext $apieSerializerContext |
| 44 | ): bool { |
| 45 | return $object instanceof ReflectionType; |
| 46 | } |
| 47 | public function normalize( |
| 48 | mixed $object, |
| 49 | ApieSerializerContext $apieSerializerContext |
| 50 | ): string|int|float|bool|null|ItemList|ItemHashmap { |
| 51 | assert($object instanceof ReflectionType); |
| 52 | return $object instanceof ReflectionNamedType ? $object->getName() : (string) $object; |
| 53 | } |
| 54 | } |