Completed
Pull Request — master (#80)
by John
03:04
created

JmsSerializerAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 1
dl 40
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A serialize() 4 4 1
A deserialize() 4 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 declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Serialize\Serializer;
10
11
use JMS\Serializer\SerializerInterface as JmsSerializer;
12
use KleijnWeb\SwaggerBundle\Serialize\Serializer;
13
14
/**
15
 * Adapter for JMS\Serializer
16
 *
17
 * @author John Kleijn <[email protected]>
18
 */
19 View Code Duplication
class JmsSerializerAdapter implements Serializer
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...
20
{
21
    /**
22
     * @var JmsSerializer
23
     */
24
    private $target;
25
26
    /**
27
     * JmsSerializerAdapter constructor.
28
     *
29
     * @param JmsSerializer $target
30
     */
31
    public function __construct(JmsSerializer $target)
32
    {
33
        $this->target = $target;
34
    }
35
36
    /**
37
     * @param mixed $data any data
38
     *
39
     * @return string
40
     */
41
    public function serialize($data): string
42
    {
43
        return $this->target->serialize($data, 'json');
44
    }
45
46
    /**
47
     * Deserializes data into the given type.
48
     *
49
     * @param mixed  $data
50
     * @param string $type
51
     *
52
     * @return object|array
53
     */
54
    public function deserialize($data, string $type)
55
    {
56
        return $this->target->deserialize($data, $type, 'json');
57
    }
58
}
59