Completed
Pull Request — master (#5)
by Moesjarraf
08:07
created

Implementation::applyTo()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher;
6
use LegalThings\DataEnricher\Node;
7
8
/**
9
 * Basic stuff for a processor implementation
10
 */
11
trait Implementation
12
{
13
    /**
14
     * Property key which should trigger the processor
15
     * @var string
16
     */
17
    protected $property;
18
    
19
    /**
20
     * Apply processing to a single node
21
     * 
22
     * @param Node $node
23
     * @return void
24
     */
25
    abstract protected function applyToNode(Node $node);
26
    
27
    /**
28
     * Class constructor
29
     * 
30
     * @param DataEnricher $invoker
31
     * @param string       $property  Property key with the processing instruction
32
     */
33
    public function __construct(DataEnricher $invoker, $property)
0 ignored issues
show
Unused Code introduced by
The parameter $invoker is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        $this->property = $property;
36
    }
37
    
38
    /**
39
     * Get the property key that holds the processing instruction
40
     * 
41
     * @return string
42
     */
43
    public function getProperty()
44
    {
45
        return $this->property;
46
    }
47
    
48
    /**
49
     * Apply reference processing
50
     * 
51
     * @param Node[] $nodes
52
     */
53
    public function applyTo(array $nodes)
54
    {
55
        foreach ($nodes as $node) {
56
            if ($node->hasInstruction($this)) {
57
                $this->applyToNode($node);
58
            }
59
        }
60
    }
61
}
62