Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
4 / 5 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| DateTimeZoneNormalizer | |
80.00% |
4 / 5 |
|
75.00% |
3 / 4 |
4.13 | |
0.00% |
0 / 1 |
| supportsNormalization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| normalize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| supportsDenormalization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| denormalize | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 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 DateTimeZone; |
| 11 | use Psr\Http\Message\UploadedFileInterface; |
| 12 | |
| 13 | final class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterface |
| 14 | { |
| 15 | public function supportsNormalization(mixed $object, ApieSerializerContext $apieSerializerContext): bool |
| 16 | { |
| 17 | return $object instanceof DateTimeZone; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @param DateTimeZone $object |
| 22 | */ |
| 23 | public function normalize(mixed $object, ApieSerializerContext $apieSerializerContext): string |
| 24 | { |
| 25 | return $object->getName(); |
| 26 | } |
| 27 | |
| 28 | public function supportsDenormalization( |
| 29 | string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, |
| 30 | string $desiredType, |
| 31 | ApieSerializerContext $apieSerializerContext |
| 32 | ): bool { |
| 33 | return is_a($desiredType, DateTimeZone::class, true); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param class-string<DateTimeZone> $desiredType |
| 38 | */ |
| 39 | public function denormalize(string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, string $desiredType, ApieSerializerContext $apieSerializerContext): DateTimeZone |
| 40 | { |
| 41 | $object = Utils::toString($object); |
| 42 | return new $desiredType($object); |
| 43 | } |
| 44 | } |