IfSet   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 32
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A applyToNode() 0 18 3
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
            unset($result->{$this->property});
39
            
40
            $node->setResult($result);
41
        }
42
    }
43
}
44