Replace   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 34
ccs 13
cts 15
cp 0.8667
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B applyToNode() 0 24 9
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher\Node;
6
use LegalThings\DataEnricher\Processor;
7
8
/**
9
 * Replace processor
10
 */
11
class Replace implements Processor
12
{
13
    use Processor\Implementation;
14
    
15
    /**
16
     * Apply processing to a single node
17
     * 
18
     * @param Node $node
19
     */
20 4
    public function applyToNode(Node $node)
21
    {
22 4
        $instruction = $node->getInstruction($this);
23
        
24 4
        if (is_array($instruction) || is_object($instruction)) {
25 4
            $instruction = (object)$instruction;
26 4
        }
27
        
28 4
        if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->replacement)) {
29
            return;
30
        }
31
        
32 4
        if (!isset($instruction->find) && !isset($instruction->regex)) {
33
            return;
34
        }
35
        
36 4
        if (isset($instruction->find)) {
37 2
            $result = str_replace($instruction->find, $instruction->replacement, $instruction->input);
38 2
        } else {
39 2
            $result = preg_replace($instruction->regex, $instruction->replacement, $instruction->input);
40
        }
41
        
42 4
        $node->setResult($result);
43 4
    }
44
}
45