Unserialize   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 2
dl 52
loc 52
ccs 15
cts 17
cp 0.8824
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B applyToNode() 20 20 7
A json() 4 4 1
A url() 5 5 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
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher\Node;
6
use LegalThings\DataEnricher\Processor;
7
8
/**
9
 * Unserialize processor
10
 */
11 View Code Duplication
class Unserialize implements Processor
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...
12
{
13
    use Processor\Implementation;
14
    
15
    /**
16
     * Apply processing to a single node
17
     * 
18
     * @param Node $node
19
     */
20 2
    public function applyToNode(Node $node)
21
    {
22 2
        $instruction = $node->getInstruction($this);
23
        
24 2
        if (is_array($instruction) || is_object($instruction)) {
25 2
            $instruction = (object)$instruction;
26 2
        }
27
        
28 2
        if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->format)) {
29
            return;
30
        }
31
        
32 2
        if (!method_exists($this, $instruction->format)) {
33
            return;
34
        }
35
        
36 2
        $result = call_user_func_array([$this, $instruction->format], [$instruction->input]);
37
        
38 2
        $node->setResult($result);
39 2
    }
40
    
41
    
42
    /**
43
     * Json unserialize
44
     * 
45
     * @param string $input
46
     */
47 1
    public function json($input)
48
    {
49 1
        return json_decode($input);
50
    }
51
52
    /**
53
     * Url unserialize
54
     * 
55
     * @param string $input
56
     */
57 1
    public function url($input)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
58
    {
59 1
        parse_str($input, $output);
60 1
        return (object)$output;
61
    }
62
}
63