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

AnswerDenormalizer::denormalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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