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

IfElse   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 30
ccs 12
cts 13
cp 0.9231
rs 10

1 Method

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