LessonNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
c 1
b 0
f 0
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A normalize() 0 8 1
A supportsNormalization() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Serializer;
6
7
use App\Model\LessonInterface;
8
use App\Serializer\Processor\FileHrefProcessor;
9
use App\Serializer\Processor\LessonCompletedProcessor;
10
use App\Serializer\Processor\LessonPaginationProcessor;
11
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
12
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
13
14
class LessonNormalizer implements NormalizerInterface
15
{
16
    private $normalizer;
17
    private $fileHrefProcessor;
18
    private $lessonCompletedProcessor;
19
    private $lessonPaginationProcessor;
20
21
    public function __construct(
22
        ObjectNormalizer $normalizer,
23
        FileHrefProcessor $fileHrefProcessor,
24
        LessonCompletedProcessor $lessonCompletedProcessor,
25
        LessonPaginationProcessor $lessonPaginationProcessor
26
    ) {
27
        $this->normalizer = $normalizer;
28
        $this->fileHrefProcessor = $fileHrefProcessor;
29
        $this->lessonCompletedProcessor = $lessonCompletedProcessor;
30
        $this->lessonPaginationProcessor = $lessonPaginationProcessor;
31
    }
32
33
    public function normalize($object, $format = null, array $context = [])
34
    {
35
        $data = $this->normalizer->normalize($object, $format, $context);
36
        $data = $this->fileHrefProcessor->process($object, $data);
0 ignored issues
show
Bug introduced by
It seems like $data can also be of type ArrayObject; however, parameter $data of App\Serializer\Processor...refProcessor::process() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        $data = $this->fileHrefProcessor->process($object, /** @scrutinizer ignore-type */ $data);
Loading history...
37
        $data = $this->lessonCompletedProcessor->process($object, $data);
38
        $data = $this->lessonPaginationProcessor->process($object, $data);
39
40
        return $data;
41
    }
42
43
    public function supportsNormalization($data, $format = null): bool
44
    {
45
        return $data instanceof LessonInterface;
46
    }
47
}
48