Passed
Push — master ( 3ec415...9f2f47 )
by Daniel
16:25
created

DataUriNormalizer::normalize()   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
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
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\Serializer\Normalizer;
15
16
use Silverback\ApiComponentsBundle\Model\Uploadable\UploadedDataUriFile;
17
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
18
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer as SymfonyDataUriNormalizer;
19
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
20
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
21
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
22
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
23
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
24
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
25
26
/**
27
 * The DataUriNormalizer would be called even if we have already denormalized. The `supports`
28
 * method seems to have 'null' data. So we check during denormalization if we have already done it.
29
 * Bit hacky, but it'll be OK for now. Should trace source of issue, probably a bug in dependency,
30
 * Check removing this every now and again perhaps too. Tests will fail.
31
 *
32
 * @author Daniel West <[email protected]>
33
 */
34
class DataUriNormalizer implements NormalizerAwareInterface, DenormalizerAwareInterface, CacheableSupportsMethodInterface, NormalizerInterface, DenormalizerInterface
35
{
36
    use NormalizerAwareTrait;
37
    use DenormalizerAwareTrait;
38
39
    private SymfonyDataUriNormalizer $decorated;
40
41 7
    public function __construct(SymfonyDataUriNormalizer $decorated)
42
    {
43 7
        $this->decorated = $decorated;
44 7
    }
45
46
    public function hasCacheableSupportsMethod(): bool
47
    {
48
        return $this->decorated->hasCacheableSupportsMethod();
49
    }
50
51
    public function denormalize($data, $type, $format = null, array $context = [])
52
    {
53
        if ($data instanceof UploadedDataUriFile) {
54
            return $data;
55
        }
56
        $this->decorated->denormalize($data, $type, $format, $context);
57
    }
58
59
    public function supportsDenormalization($data, $type, $format = null): bool
60
    {
61
        return $this->decorated->supportsDenormalization($data, $type, $format);
62
    }
63
64
    public function normalize($object, $format = null, array $context = [])
65
    {
66
        return $this->decorated->normalize($object, $format, $context);
67
    }
68
69
    public function supportsNormalization($data, $format = null): bool
70
    {
71
        return $this->decorated->supportsNormalization($data, $format);
72
    }
73
}
74