VndErrorSerializer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 15.09 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 8
loc 53
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A serialize() 8 8 1
A deserialize() 0 4 1

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
/*
6
 * This file is part of the FiveLab Resource package
7
 *
8
 * (c) FiveLab
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace FiveLab\Component\Resource\Serializers\VndError;
15
16
use FiveLab\Component\Resource\Resource\ResourceInterface;
17
use FiveLab\Component\Resource\Serializer\Context\ResourceSerializationContext;
18
use FiveLab\Component\Resource\Serializer\Exception\DeserializationNotSupportException;
19
use FiveLab\Component\Resource\Serializer\ResourceSerializerInterface;
20
use FiveLab\Component\Resource\Serializer\SerializerInterface;
21
use FiveLab\Component\Resource\Serializers\Hateoas\Normalizer\RelationCollectionObjectNormalizer;
22
use FiveLab\Component\Resource\Serializers\Hateoas\Normalizer\RelationObjectNormalizer;
23
use FiveLab\Component\Resource\Serializers\VndError\Normalizer\ErrorCollectionObjectNormalizer;
24
use FiveLab\Component\Resource\Serializers\VndError\Normalizer\ErrorResourceObjectNormalizer;
25
26
/**
27
 * The serializer for serialize errors to Vnd.Error format.
28
 *
29
 * @author Vitaliy Zhuk <[email protected]>
30
 */
31
class VndErrorSerializer implements ResourceSerializerInterface
32
{
33
    /**
34
     * @var SerializerInterface
35
     */
36
    private $serializer;
37
38
    /**
39
     * @var string
40
     */
41
    private $format;
42
43
    /**
44
     * @var array
45
     */
46
    private $normalizers;
47
48
    /**
49
     * Constructor.
50
     *
51
     * @param SerializerInterface $serializer
52
     * @param array               $normalizers
53
     * @param string              $format
54
     */
55 2
    public function __construct(SerializerInterface $serializer, array $normalizers, string $format)
56
    {
57 2
        $this->serializer = $serializer;
58 2
        $this->format = $format;
59 2
        $this->normalizers = $normalizers;
60 2
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 1 View Code Duplication
    public function serialize(ResourceInterface $resource, ResourceSerializationContext $context): string
0 ignored issues
show
Duplication introduced by
This method 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...
66
    {
67
        $innerContext = [
68 1
            'normalizers' => $this->normalizers,
69
        ];
70
71 1
        return $this->serializer->serialize($resource, $this->format, $innerContext);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     *
77
     * @throws DeserializationNotSupportException
78
     */
79 1
    public function deserialize(string $data, string $resourceClass, ResourceSerializationContext $context): ResourceInterface
80
    {
81 1
        throw new DeserializationNotSupportException('The Vnd.Error not support deserialization.');
82
    }
83
}
84