Test Failed
Push — master ( 7b0da1...2a2e23 )
by Daniel
04:09
created

VersionedDocumentationNormalizer::normalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 8
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\Core\Hydra\Serializer\DocumentationNormalizer;
17
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
class VersionedDocumentationNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
24
{
25
    private DocumentationNormalizer $decorated;
26
27
    public function __construct(DocumentationNormalizer $decorated)
28
    {
29
        $this->decorated = $decorated;
30
    }
31
32
    public function hasCacheableSupportsMethod(): bool
33
    {
34
        return $this->decorated->hasCacheableSupportsMethod();
35
    }
36
37
    public function normalize($object, string $format = null, array $context = [])
38
    {
39
        $doc = $this->decorated->normalize($object, $format, $context);
40
        if ('' !== $object->getVersion()) {
41
            $doc['info'] = ['version' => $object->getVersion()];
42
        }
43
44
        return $doc;
45
    }
46
47
    public function supportsNormalization($data, string $format = null): bool
48
    {
49
        return $this->decorated->supportsNormalization($data, $format);
50
    }
51
}
52