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

IfSet::__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\Processor;
6
use LegalThings\DataEnricher\Processor\Helper;
7
use LegalThings\DataEnricher\Node;
8
9
/**
10
 * The value will be NULL if the reference isn't set
11
 */
12
class IfSet 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
        $check = $this->getByReference($ref, $this->source, $this->target);
29
        
30
        if (!isset($check)) {
31
            $node->setResult(null);
32
            
33
            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...
34
                unset($node->$prop); // Remove all other properties, including processing instructions
35
            }
36
        } else {
37
            $result = $node->getResult();
38
            $result->{$this->property} = null;
39
            
40
            $node->setResult($result);
41
        }
42
    }
43
}
44