Completed
Pull Request — master (#5)
by Moesjarraf
09:47
created

SwitchChoose   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A applyToNode() 0 8 1
A choose() 0 5 2
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher;
6
use LegalThings\DataEnricher\Node;
7
use LegalThings\DataEnricher\Processor;
8
use Jasny\DotKey;
9
10
/**
11
 * Choose one of the child properties based on a property in the document
12
 */
13
class SwitchChoose implements Processor
14
{
15
    use Processor\Implementation;
16
    
17
    /**
18
     * @var DotKey
19
     */
20
    protected $source;
21
    
22
    /**
23
     * Class constructor
24
     * 
25
     * @param DataEnricher $invoker
26
     * @param string       $property  Property key which should trigger the processor
27
     */
28
    public function __construct(DataEnricher $invoker, $property)
29
    {
30
        $this->source = DotKey::on($invoker->getSource());
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31
        $this->property = $property;
32
    }
33
    
34
    /**
35
     * Apply processing to a single node
36
     * 
37
     * @param Node $node
38
     */
39
    public function applyToNode($node)
40
    {
41
        $ref = $node->getInstruction($this);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42
        $cases = $node->getResult();
43
        
44
        $result = $this->choose($ref, $cases);
45
        $node->setResult($result);
46
    }
47
    
48
    /**
49
     * Choose on of the cases
50
     * 
51
     * @param string $ref    Property name of source
52
     * @param object $cases
53
     * @return type
54
     */
55
    protected function choose($ref, $cases)
56
    {
57
        $test = $this->source->get($ref);
58
        return isset($cases->$test) ? $cases->$test : null;
59
    }
60
}
61