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