Unserialize::applyToNode()   B
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 7.2269

Importance

Changes 0
Metric Value
dl 20
loc 20
ccs 10
cts 12
cp 0.8333
rs 8.6666
c 0
b 0
f 0
cc 7
nc 6
nop 1
crap 7.2269
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