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

AnswerNormalizer::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 7
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 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