Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ReflectionClassNormalizer
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 supportsDenormalization
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 denormalize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 supportsNormalization
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 normalize
100.00% covered (success)
100.00%
2 / 2
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 ReflectionClass;
12
13class ReflectionClassNormalizer implements DenormalizerInterface, NormalizerInterface
14{
15    public function supportsDenormalization(
16        string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object,
17        string $desiredType,
18        ApieSerializerContext $apieSerializerContext
19    ): bool {
20        return in_array(
21            $desiredType,
22            [
23                ReflectionClass::class
24            ]
25        );
26    }
27
28    /**
29     * @return ReflectionClass<covariant object>
30     */
31    public function denormalize(
32        string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object,
33        string $desiredType,
34        ApieSerializerContext $apieSerializerContext
35    ): ReflectionClass {
36        return new ReflectionClass(Utils::toString($object));
37    }
38    public function supportsNormalization(
39        mixed $object,
40        ApieSerializerContext $apieSerializerContext
41    ): bool {
42        return $object instanceof ReflectionClass;
43    }
44    public function normalize(
45        mixed $object,
46        ApieSerializerContext $apieSerializerContext
47    ): string|int|float|bool|null|ItemList|ItemHashmap {
48        assert($object instanceof ReflectionClass);
49        return $object->getName();
50    }
51}