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

AnswerNormalizer::supportsNormalization()   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 2
dl 0
loc 3
rs 10
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