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

DataUriNormalizer::hasCacheableSupportsMethod()   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 0
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\HttpFoundation\File\File;
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, NormalizerInterface, DenormalizerInterface
35
{
36
    use DenormalizerAwareTrait;
37
    use NormalizerAwareTrait;
38
39
    private NormalizerInterface|SymfonyDataUriNormalizer $decorated;
40
41
    public function __construct(NormalizerInterface|SymfonyDataUriNormalizer $decorated)
42
    {
43
        $this->decorated = $decorated;
44
    }
45
46
    public function denormalize($data, $type, $format = null, array $context = []): mixed
47
    {
48
        if ($data instanceof UploadedDataUriFile || ($data instanceof File && '' === $data->getPath())) {
49
            return $data;
50
        }
51
52
        return $this->decorated->denormalize($data, $type, $format, $context);
0 ignored issues
show
Bug introduced by
The method denormalize() does not exist on Symfony\Component\Serial...zer\NormalizerInterface. Did you maybe mean normalize()? ( Ignorable by Annotation )

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

52
        return $this->decorated->/** @scrutinizer ignore-call */ denormalize($data, $type, $format, $context);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
    }
54
55
    public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
56
    {
57
        return $this->decorated->supportsDenormalization($data, $type, $format, $context);
0 ignored issues
show
Bug introduced by
The method supportsDenormalization() does not exist on Symfony\Component\Serial...zer\NormalizerInterface. It seems like you code against a sub-type of Symfony\Component\Serial...zer\NormalizerInterface such as ApiPlatform\Elasticsearc...izer\DocumentNormalizer or Symfony\Component\Serial...ormalizer\UidNormalizer or Symfony\Component\Serial...alizer\CustomNormalizer or Symfony\Component\Serial...r\MimeMessageNormalizer or Symfony\Component\Serial...izer\AbstractNormalizer or Symfony\Component\Serial...\DateIntervalNormalizer or Silverback\ApiComponents...onentPositionNormalizer or Symfony\Component\Serial...lizer\DataUriNormalizer or ApiPlatform\Hal\Serializer\ObjectNormalizer or Silverback\ApiComponents...rmalizer\UserNormalizer or Silverback\ApiComponents...lizer\DataUriNormalizer or Silverback\ApiComponents...r\PublishableNormalizer or Symfony\Component\Serial...izer\DateTimeNormalizer or Silverback\ApiComponents...er\UploadableNormalizer or Symfony\Component\Serial...\DateTimeZoneNormalizer or Symfony\Component\Serial...bug\TraceableSerializer or ApiPlatform\Elasticsearc...rializer\ItemNormalizer or Symfony\Component\Serial...bug\TraceableNormalizer or Symfony\Component\Serial...er\BackedEnumNormalizer or Symfony\Component\Serializer\Serializer or Symfony\Component\Messen...ttenExceptionNormalizer. ( Ignorable by Annotation )

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

57
        return $this->decorated->/** @scrutinizer ignore-call */ supportsDenormalization($data, $type, $format, $context);
Loading history...
Unused Code introduced by
The call to Symfony\Component\Serial...pportsDenormalization() 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

57
        return $this->decorated->/** @scrutinizer ignore-call */ supportsDenormalization($data, $type, $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...
58
    }
59
60
    public function normalize($object, $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null
61
    {
62
        return $this->decorated->normalize($object, $format, $context);
63
    }
64
65
    public function supportsNormalization($data, $format = null, array $context = []): bool
66
    {
67
        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

67
        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...
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

67
        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...
68
    }
69
70
    public function getSupportedTypes(?string $format): array
71
    {
72
        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

72
        return $this->decorated->/** @scrutinizer ignore-call */ getSupportedTypes($format);
Loading history...
73
    }
74
}
75