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

SwitchChoose   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
c 2
b 0
f 2
lcom 1
cbo 3
dl 0
loc 35
ccs 0
cts 9
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyToNode() 0 8 1
A choose() 0 5 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