Failed Conditions
Push — master ( e245a2...503ac3 )
by Arnold
8s
created

SwitchChoose::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher\Node;
6
use LegalThings\DataEnricher\Processor;
7
use LegalThings\DataEnricher\Processor\Helper;
8
9
/**
10
 * Choose one of the child properties based on a property in the document
11
 */
12
class SwitchChoose implements Processor
13
{
14
    use Processor\Implementation,
15
        Helper\GetByReference
16
    {
17
        Helper\GetByReference::withSourceAndTarget insteadof Processor\Implementation;
18
    }
19
    
20
    /**
21
     * Apply processing to a single node
22
     * 
23
     * @param Node $node
24
     */
25
    public function applyToNode(Node $node)
26
    {
27
        $ref = $node->getInstruction($this);
28
        $cases = $node->getResult();
29
        
30
        $result = $this->choose($ref, $cases);
31
        $node->setResult($result);
32
    }
33
    
34
    /**
35
     * Choose on of the cases
36
     * 
37
     * @param string $ref    Property name of source
38
     * @param object $cases
39
     * @return mixed
40
     */
41
    protected function choose($ref, $cases)
42
    {
43
        $test = $this->getByReference($ref, $this->source, $this->target);
44
        return isset($cases->$test) ? $cases->$test : null;
45
    }
46
}
47