Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
6 / 8
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
StringNormalizer
75.00% covered (warning)
75.00%
6 / 8
50.00% covered (danger)
50.00%
1 / 2
7.77
0.00% covered (danger)
0.00%
0 / 1
 supportsDenormalization
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 denormalize
71.43% covered (warning)
71.43%
5 / 7
0.00% covered (danger)
0.00%
0 / 1
6.84
1<?php
2namespace Apie\Serializer\Normalizers;
3
4use Apie\Core\Exceptions\InvalidTypeException;
5use Apie\Core\Lists\ItemHashmap;
6use Apie\Core\Lists\ItemList;
7use Apie\Serializer\Context\ApieSerializerContext;
8use Apie\Serializer\Interfaces\DenormalizerInterface;
9use Psr\Http\Message\UploadedFileInterface;
10
11class 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}