Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
4 / 6 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
PermissionListNormalizer | |
66.67% |
4 / 6 |
|
75.00% |
3 / 4 |
4.59 | |
0.00% |
0 / 1 |
supportsDenormalization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
denormalize | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
supportsNormalization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
normalize | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Apie\Serializer\Normalizers; |
4 | |
5 | use Apie\Core\Lists\ItemHashmap; |
6 | use Apie\Core\Lists\ItemList; |
7 | use Apie\Core\Lists\PermissionList; |
8 | use Apie\Core\ValueObjects\Utils; |
9 | use Apie\Serializer\Context\ApieSerializerContext; |
10 | use Apie\Serializer\Interfaces\DenormalizerInterface; |
11 | use Apie\Serializer\Interfaces\NormalizerInterface; |
12 | use Apie\Serializer\Lists\SerializedList; |
13 | use Psr\Http\Message\UploadedFileInterface; |
14 | |
15 | class 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 | } |