Issues (15)

src/Serializer/CourseNormalizer.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Serializer;
6
7
use App\Model\CourseInterface;
8
use App\Serializer\Processor\FileHrefProcessor;
9
use App\Serializer\Processor\ProgressProcessor;
10
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
11
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
12
13
class CourseNormalizer implements NormalizerInterface
14
{
15
    private $normalizer;
16
    private $fileHrefProcessor;
17
    private $progressProcessor;
18
19
    public function __construct(
20
        ObjectNormalizer $normalizer,
21
        FileHrefProcessor $fileHrefProcessor,
22
        ProgressProcessor $progressProcessor
23
    ) {
24
        $this->normalizer = $normalizer;
25
        $this->fileHrefProcessor = $fileHrefProcessor;
26
        $this->progressProcessor = $progressProcessor;
27
    }
28
29
    public function normalize($object, $format = null, array $context = [])
30
    {
31
        if (!$object instanceof CourseInterface) {
32
            return [];
33
        }
34
35
        $data = $this->normalizer->normalize($object, $format, $context);
36
        $data = $this->fileHrefProcessor->process($object, $data);
0 ignored issues
show
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->progressProcessor->process($object, $data);
38
39
        return $data;
40
    }
41
42
    public function supportsNormalization($data, $format = null): bool
43
    {
44
        return $data instanceof CourseInterface;
45
    }
46
}
47