Test Failed
Push — master ( 25b8d1...f70cb8 )
by Pavel
03:49
created

JmsSerializerAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 48.65 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 18
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serialize() 9 9 2
A deserialize() 9 9 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
namespace ScayTrase\Api\Cruds\Adaptors\Jms;
4
5
use JMS\Serializer\DeserializationContext;
6
use JMS\Serializer\SerializationContext;
7
use JMS\Serializer\SerializerInterface as JmsSerializer;
8
use Symfony\Component\Serializer\SerializerInterface;
9
10
final class JmsSerializerAdapter implements SerializerInterface
11
{
12
    /** @var  JmsSerializer */
13
    private $serializer;
14
15
    /**
16
     * JmsSerializerAdapter constructor.
17
     *
18
     * @param JmsSerializer $serializer
19
     */
20
    public function __construct(JmsSerializer $serializer)
21
    {
22
        $this->serializer = $serializer;
23
    }
24
25
    /** {@inheritdoc} */
26 View Code Duplication
    public function serialize($data, $format, array $context = [])
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...
27
    {
28
        $jmsContext = SerializationContext::create();
29
        if (array_key_exists('groups', $context)) {
30
            $jmsContext->setGroups($context['groups']);
31
        }
32
33
        return $this->serializer->serialize($data, $format, $jmsContext);
34
    }
35
36
    /** {@inheritdoc} */
37 View Code Duplication
    public function deserialize($data, $type, $format, array $context = [])
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...
38
    {
39
        $jmsContext = DeserializationContext::create();
40
        if (array_key_exists('groups', $context)) {
41
            $jmsContext->setGroups($context['groups']);
42
        }
43
44
        $this->serializer->deserialize($data, $type, $format, $jmsContext);
45
    }
46
}
47