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

AnswerNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 2
A normalize() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Question\Serializers;
4
5
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
6
use VSV\GVQ_API\Question\Models\Answer;
7
8
class AnswerNormalizer implements NormalizerInterface
9
{
10
    /**
11
     * @inheritdoc
12
     */
13
    public function normalize($answer, $format = null, array $context = []): array
14
    {
15
        /** @var Answer $answer */
16
        return [
17
            'id' => $answer->getId()->toString(),
18
            'text' => $answer->getText()->toNative(),
19
            'correct' => $answer->isCorrect(),
20
        ];
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function supportsNormalization($data, $format = null): bool
27
    {
28
        return ($data instanceof Answer) && ($format === 'json');
29
    }
30
}
31