Passed
Push — main ( b2d943...872826 )
by Daniel
05:35
created

VersionedDocumentationNormalizer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\ApiPlatform\Serializer;
15
16
use ApiPlatform\Documentation\Documentation;
17
use ApiPlatform\Hydra\Serializer\DocumentationNormalizer;
18
use Silverback\ApiComponentsBundle\OpenApi\OpenApiFactory;
19
use Symfony\Component\Serializer\Exception\ExceptionInterface;
20
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
21
22
/**
23
 * @author Daniel West <[email protected]>
24
 */
25
class VersionedDocumentationNormalizer implements NormalizerInterface
26
{
27
    private NormalizerInterface|DocumentationNormalizer $decorated;
28
29
    public function __construct(NormalizerInterface|DocumentationNormalizer $decorated)
30
    {
31
        $this->decorated = $decorated;
32
    }
33
34
    /**
35
     * @param Documentation $object
36
     *
37
     * @throws ExceptionInterface
38
     */
39
    public function normalize($object, string $format = null, array $context = []): array
40
    {
41
        $doc = $this->decorated->normalize($object, $format, $context);
42
        if ('' !== $object->getVersion()) {
43
            $doc['info'] = ['version' => OpenApiFactory::getExtendedVersion($object->getVersion())];
44
        }
45
46
        return $doc;
47
    }
48
49
    public function supportsNormalization($data, string $format = null, array $context = []): bool
50
    {
51
        return $this->decorated->supportsNormalization($data, $format, $context);
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Component\Serial...supportsNormalization() has too many arguments starting with $context. ( Ignorable by Annotation )

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

51
        return $this->decorated->/** @scrutinizer ignore-call */ supportsNormalization($data, $format, $context);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
52
    }
53
54
    public function getSupportedTypes(?string $format): array
55
    {
56
        return $this->decorated->getSupportedTypes($format);
0 ignored issues
show
Bug introduced by
The method getSupportedTypes() does not exist on Symfony\Component\Serial...zer\NormalizerInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Serial...izer\AbstractNormalizer or Symfony\Component\Serial...wareNormalizerInterface or Symfony\Component\Serial...bstractObjectNormalizer. Are you sure you never get one of those? ( Ignorable by Annotation )

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

56
        return $this->decorated->/** @scrutinizer ignore-call */ getSupportedTypes($format);
Loading history...
57
    }
58
}
59