Match::applyToNode()   B
last analyzed

Complexity

Conditions 9
Paths 10

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 9.1582

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 14
cts 16
cp 0.875
rs 8.0555
c 0
b 0
f 0
cc 9
nc 10
nop 1
crap 9.1582
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher\Node;
6
use LegalThings\DataEnricher\Processor;
7
8
/**
9
 * Match processor
10
 */
11
class Match 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)) {
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 = strpos($instruction->input, $instruction->find) !== false;
38 2
        } else {
39 2
            $flags = isset($instruction->flags) ? $instruction->flags : 0;
40 2
            $result = preg_match($instruction->regex, $instruction->input, $matches, $flags);
41
        }
42
        
43 4
        $node->setResult($result);
44 4
    }
45
}
46