Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
6 / 8 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| StringNormalizer | |
75.00% |
6 / 8 |
|
50.00% |
1 / 2 |
7.77 | |
0.00% |
0 / 1 |
| supportsDenormalization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| denormalize | |
71.43% |
5 / 7 |
|
0.00% |
0 / 1 |
6.84 | |||
| 1 | <?php |
| 2 | namespace Apie\Serializer\Normalizers; |
| 3 | |
| 4 | use Apie\Core\Exceptions\InvalidTypeException; |
| 5 | use Apie\Core\Lists\ItemHashmap; |
| 6 | use Apie\Core\Lists\ItemList; |
| 7 | use Apie\Serializer\Context\ApieSerializerContext; |
| 8 | use Apie\Serializer\Interfaces\DenormalizerInterface; |
| 9 | use Psr\Http\Message\UploadedFileInterface; |
| 10 | |
| 11 | class StringNormalizer implements DenormalizerInterface |
| 12 | { |
| 13 | public function supportsDenormalization(string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, string $desiredType, ApieSerializerContext $apieSerializerContext): bool |
| 14 | { |
| 15 | return $desiredType === 'string'; |
| 16 | } |
| 17 | public function denormalize(string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, string $desiredType, ApieSerializerContext $apieSerializerContext): string |
| 18 | { |
| 19 | return match (gettype($object)) { |
| 20 | 'string' => $object, |
| 21 | 'boolean' => (string) $object, |
| 22 | 'integer' => (string) $object, |
| 23 | 'double' => (string) $object, |
| 24 | default => throw new InvalidTypeException($object, 'string'), |
| 25 | }; |
| 26 | } |
| 27 | } |