Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
3 / 4
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
UriNormalizer
75.00% covered (warning)
75.00%
3 / 4
75.00% covered (warning)
75.00%
3 / 4
4.25
0.00% covered (danger)
0.00%
0 / 1
 supportsNormalization
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 supportsDenormalization
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 normalize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 denormalize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Serializer\Normalizers;
3
4use Apie\Core\Lists\ItemHashmap;
5use Apie\Core\Lists\ItemList;
6use Apie\Core\ValueObjects\Utils;
7use Apie\Serializer\Context\ApieSerializerContext;
8use Apie\Serializer\Interfaces\DenormalizerInterface;
9use Apie\Serializer\Interfaces\NormalizerInterface;
10use Psr\Http\Message\UploadedFileInterface;
11use Uri\Rfc3986\Uri;
12
13class UriNormalizer implements NormalizerInterface, DenormalizerInterface
14{
15    public function supportsNormalization(mixed $object, ApieSerializerContext $apieSerializerContext): bool
16    {
17        return $object instanceof Uri;
18    }
19
20    public function supportsDenormalization(string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, string $desiredType, ApieSerializerContext $apieSerializerContext): bool
21    {
22        return $desiredType === Uri::class;
23    }
24
25    /**
26     * @param Uri $object
27     */
28    public function normalize(mixed $object, ApieSerializerContext $apieSerializerContext): string
29    {
30        return $object->toString();
31    }
32
33    public function denormalize(string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, string $desiredType, ApieSerializerContext $apieSerializerContext): Uri
34    {
35        return new Uri(Utils::toString($object));
36    }
37}