Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AliasDenormalizer | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| supportsDenormalization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | |
| 13 | class AliasDenormalizer implements DenormalizerInterface |
| 14 | { |
| 15 | |
| 16 | public function supportsDenormalization(float|bool|int|string|UploadedFileInterface|ItemHashmap|ItemList|null $object, string $desiredType, ApieSerializerContext $apieSerializerContext): bool |
| 17 | { |
| 18 | return ApieLib::hasAlias($desiredType); |
| 19 | } |
| 20 | |
| 21 | public function denormalize(float|bool|int|string|UploadedFileInterface|ItemHashmap|ItemList|null $object, string $desiredType, ApieSerializerContext $apieSerializerContext): mixed |
| 22 | { |
| 23 | $newDesiredType = ApieLib::getAlias($desiredType); |
| 24 | return $apieSerializerContext->denormalizeFromTypehint( |
| 25 | $object, |
| 26 | ReflectionTypeFactory::createReflectionType($newDesiredType) |
| 27 | ); |
| 28 | } |
| 29 | } |