Failed Conditions
Push — master ( 0bbe18...211e20 )
by Moesjarraf
03:53
created

Serialize::applyToNode()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 7.2269

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 20
loc 20
ccs 10
cts 12
cp 0.8333
rs 8.2222
cc 7
eloc 10
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
 * Serialize processor
10
 */
11 View Code Duplication
class Serialize 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 serialize
44
     * 
45
     * @param mixed $input
46
     */
47 1
    public function json($input)
48
    {
49 1
        return json_encode($input);
50
    }
51
52
    /**
53
     * Url serialize
54
     * 
55
     * @param stdClass $input
56
     */
57 1
    public function url($input)
58
    {
59 1
        return http_build_query($input);
60
    }
61
}
62