Completed
Push — feature/VSVGVQ-24 ( 890c4d...a3069c )
by Luc
05:52 queued 02:46
created

supportsDenormalization()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Company\Serializers;
4
5
use Ramsey\Uuid\Uuid;
6
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
7
use VSV\GVQ_API\Common\ValueObjects\Language;
8
use VSV\GVQ_API\Company\Models\TranslatedAlias;
9
use VSV\GVQ_API\Company\ValueObjects\Alias;
10
11
class TranslatedAliasDenormalizer implements DenormalizerInterface
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function denormalize($data, $class, $format = null, array $context = array()): TranslatedAlias
17
    {
18
        // TODO: Better to use decorator and inject uuid generator.
19
        if (!isset($data['id'])) {
20
            $data['id'] = Uuid::uuid4();
21
        }
22
23
        return new TranslatedAlias(
24
            Uuid::fromString($data['id']),
25
            new Language($data['language']),
26
            new Alias($data['alias'])
27
        );
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function supportsDenormalization($data, $type, $format = null): bool
34
    {
35
        return ($type === TranslatedAlias::class) && ($format === 'json');
36
    }
37
}
38