Passed
Push — feature/VSVGVQ-7 ( 28bb1c...21bc21 )
by Luc
03:27
created

AnswerDenormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsDenormalization() 0 3 2
A denormalize() 0 6 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Question\Serializers;
4
5
use Ramsey\Uuid\Uuid;
6
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
7
use VSV\GVQ_API\Question\Models\Answer;
8
use VSV\GVQ_API\Question\ValueObjects\NotEmptyString;
9
10
class AnswerDenormalizer implements DenormalizerInterface
11
{
12
    /**
13
     * @inheritdoc
14
     */
15
    public function denormalize($data, $class, $format = null, array $context = []): Answer
16
    {
17
        return new Answer(
18
            Uuid::fromString($data['id']),
19
            new NotEmptyString($data['text']),
20
            (bool) $data['correct']
21
        );
22
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function supportsDenormalization($data, $type, $format = null): bool
28
    {
29
        return ($type === Answer::class) && ($format === 'json');
30
    }
31
}
32