Decode   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 62
ccs 17
cts 19
cp 0.8947
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B applyToNode() 0 20 7
A base64() 0 4 1
A base58() 0 5 1
A url() 0 4 1
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher\Node;
6
use LegalThings\DataEnricher\Processor;
7
use StephenHill\Base58;
8
9
/**
10
 * Decode processor
11
 */
12
class Decode implements Processor
13
{
14
    use Processor\Implementation;
15
    
16
    /**
17
     * Apply processing to a single node
18
     * 
19
     * @param Node $node
20
     */
21 3
    public function applyToNode(Node $node)
22
    {
23 3
        $instruction = $node->getInstruction($this);
24
        
25 3
        if (is_array($instruction) || is_object($instruction)) {
26 3
            $instruction = (object)$instruction;
27 3
        }
28
        
29 3
        if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->algo)) {
30
            return;
31
        }
32
        
33 3
        if (!method_exists($this, $instruction->algo)) {
34
            return;
35
        }
36
        
37 3
        $result = call_user_func_array([$this, $instruction->algo], [$instruction->input]);
38
        
39 3
        $node->setResult($result);
40 3
    }
41
    
42
    
43
    /**
44
     * Base64 decode
45
     * 
46
     * @param string $input
47
     */
48 1
    public function base64($input)
49
    {
50 1
        return base64_decode($input);
51
    }
52
    
53
    /**
54
     * Base58 decode
55
     * 
56
     * @param string $input
57
     */
58 1
    public function base58($input)
59
    {
60 1
        $base58 = new Base58();
61 1
        return $base58->decode($input);
62
    }
63
    
64
    /**
65
     * Url decode
66
     * 
67
     * @param string $input
68
     */
69 1
    public function url($input)
70
    {
71 1
        return urldecode($input);
72
    }
73
}
74