Completed
Push — master ( 8538c3...35aef6 )
by Arnold
07:41
created

IfSet::applyToNode()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
rs 9.4285
cc 3
eloc 11
nc 3
nop 1
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher;
6
use LegalThings\DataEnricher\Processor;
7
use LegalThings\DataEnricher\Node;
8
use Jasny\DotKey;
9
10
/**
11
 * The value will be NULL if the reference isn't set
12
 */
13
class IfSet 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);
42
        
43
        $check = $this->source->get($ref);
44
        
45
        if (!isset($check)) {
46
            $node->setResult(null);
47
            
48
            foreach ($node as $prop => $value) {
0 ignored issues
show
Bug introduced by
The expression $node of type object<LegalThings\DataEnricher\Node> is not traversable.
Loading history...
49
                unset($node->$prop); // Remove all other properties, including processing instructions
50
            }
51
        } else {
52
            $result = $node->getResult();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 20 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...
53
            $result->{$this->property} = null;
54
            
55
            $node->setResult($result);
56
        }
57
    }
58
}
59