JsonDeserializationVisitor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 22.73 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 10
loc 44
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A decode() 10 10 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
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Visitor\Json;
13
14
use Ivory\Serializer\Instantiator\InstantiatorInterface;
15
use Ivory\Serializer\Mutator\MutatorInterface;
16
use Ivory\Serializer\Visitor\AbstractDeserializationVisitor;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
class JsonDeserializationVisitor extends AbstractDeserializationVisitor
22
{
23
    /**
24
     * @var int
25
     */
26
    private $maxDepth;
27
28
    /**
29
     * @var int
30
     */
31
    private $options;
32
33
    /**
34
     * @param InstantiatorInterface $instantiator
35
     * @param MutatorInterface      $mutator
36
     * @param int                   $maxDepth
37
     * @param int                   $options
38
     */
39 1492
    public function __construct(
40
        InstantiatorInterface $instantiator,
41
        MutatorInterface $mutator,
42
        $maxDepth = 512,
43
        $options = 0
44
    ) {
45 1492
        parent::__construct($instantiator, $mutator);
46
47 1492
        $this->maxDepth = $maxDepth;
48 1492
        $this->options = $options;
49 1492
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 152 View Code Duplication
    protected function decode($data)
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...
55
    {
56 152
        $result = @json_decode($data, true, $this->maxDepth, $this->options);
57
58 152
        if (json_last_error() !== JSON_ERROR_NONE) {
59
            throw new \InvalidArgumentException(json_last_error_msg());
60
        }
61
62 152
        return $result;
63
    }
64
}
65