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

Implementation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
applyToNode() 0 1 ?
A __construct() 0 4 1
A getProperty() 0 4 1
A applyTo() 0 8 3
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