Passed
Push — master ( 69b252...c02560 )
by
unknown
56s queued 11s
created

FacadeCisListResponseDenormalizer   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 56
loc 56
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A denormalize() 19 19 5
A supportsDenormalization() 4 4 1
A setDenormalizer() 4 4 1
A hasCacheableSupportsMethod() 4 4 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\IsmpClient\Impl\Serializer\V4;
6
7
use Lamoda\IsmpClient\V4\Dto\FacadeCisItemResponse;
8
use Lamoda\IsmpClient\V4\Dto\FacadeCisListResponse;
9
use Symfony\Component\Serializer\Exception\BadMethodCallException;
10
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
11
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
12
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
13
use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface;
14
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
15
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
16
17 View Code Duplication
final class FacadeCisListResponseDenormalizer implements ContextAwareDenormalizerInterface, DenormalizerAwareInterface, CacheableSupportsMethodInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    /**
20
     * @var DenormalizerInterface
21
     */
22
    private $denormalizer;
23
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @throws NotNormalizableValueException
28
     */
29 4
    public function denormalize($data, $class, $format = null, array $context = [])
30
    {
31 4
        if (null === $this->denormalizer) {
32 1
            throw new BadMethodCallException('Please set a serializer before calling denormalize()!');
33
        }
34 3
        if (!\is_array($data)) {
35 1
            throw new InvalidArgumentException('Data expected to be an array, ' . \gettype($data) . ' given.');
36
        }
37 2
        if (FacadeCisListResponse::class !== $class) {
38 1
            throw new InvalidArgumentException('Unsupported class: ' . $class);
39
        }
40
41 1
        $items = [];
42 1
        foreach ($data as $datum) {
43 1
            $items[] = $this->denormalizer->denormalize($datum, FacadeCisItemResponse::class, $format, $context);
44
        }
45
46 1
        return new FacadeCisListResponse(...$items);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 10
    public function supportsDenormalization($data, $type, $format = null, array $context = [])
53
    {
54 10
        return FacadeCisListResponse::class === $type;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 18
    public function setDenormalizer(DenormalizerInterface $denormalizer)
61
    {
62 18
        $this->denormalizer = $denormalizer;
63 18
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 9
    public function hasCacheableSupportsMethod(): bool
69
    {
70 9
        return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod();
71
    }
72
}
73