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
ReflectionMethodNormalizer
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 ReflectionMethod;
12
13class ReflectionMethodNormalizer 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                ReflectionMethod::class
24            ]
25        );
26    }
27    public function denormalize(
28        string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object,
29        string $desiredType,
30        ApieSerializerContext $apieSerializerContext
31    ): ReflectionMethod {
32        return ReflectionMethod::createFromMethodName(Utils::toString($object));
33    }
34    public function supportsNormalization(
35        mixed $object,
36        ApieSerializerContext $apieSerializerContext
37    ): bool {
38        return $object instanceof ReflectionMethod;
39    }
40    public function normalize(
41        mixed $object,
42        ApieSerializerContext $apieSerializerContext
43    ): string|int|float|bool|null|ItemList|ItemHashmap {
44        assert($object instanceof ReflectionMethod);
45        return $object->getDeclaringClass()->name . '::' . $object->getName();
46    }
47}