Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
FfiCtypeNormalizer
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
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%
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
 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 FFI;
11use FFI\CType;
12use Psr\Http\Message\UploadedFileInterface;
13
14class FfiCtypeNormalizer implements NormalizerInterface, DenormalizerInterface
15{
16    public function supportsNormalization(mixed $object, ApieSerializerContext $apieSerializerContext): bool
17    {
18        return $object instanceof CType;
19    }
20
21    public function normalize(mixed $object, ApieSerializerContext $apieSerializerContext): string
22    {
23        return $object->getName();
24    }
25
26    public function supportsDenormalization(string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, string $desiredType, ApieSerializerContext $apieSerializerContext): bool
27    {
28        return $desiredType === CType::class;
29    }
30
31    public function denormalize(string|int|float|bool|null|ItemList|ItemHashmap|UploadedFileInterface $object, string $desiredType, ApieSerializerContext $apieSerializerContext): CType
32    {
33        return FFI::cdef()->type(Utils::toString($object));
34    }
35}