Passed
Push — master ( 9187bd...555ece )
by steven
03:07
created

QuestionsNormalizer::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\Question;
7
use VSV\GVQ_API\Question\Models\Questions;
8
9
class QuestionsNormalizer implements NormalizerInterface
10
{
11
    /**
12
     * @var QuestionNormalizer
13
     */
14
    private $questionNormalizer;
15
16
    /**
17
     * @param QuestionNormalizer $questionNormalizer
18
     */
19
    public function __construct(QuestionNormalizer $questionNormalizer)
20
    {
21
        $this->questionNormalizer = $questionNormalizer;
22
    }
23
24
    /**
25
     * @inheritdoc
26
     * @param Questions $questions
27
     */
28
    public function normalize($questions, $format = null, array $context = []): array
29
    {
30
        return array_map(
31
            function (Question $question) use ($format, $context) {
32
                return $this->questionNormalizer->normalize($question, $format, $context);
33
            },
34
            $questions->toArray()
35
        );
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function supportsNormalization($data, $format = null): bool
42
    {
43
        return ($data instanceof Questions) && ($format === 'json');
44
    }
45
}
46