Completed
Pull Request — master (#5)
by Moesjarraf
09:47
created

Node   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A getResult() 0 4 1
A setResult() 0 4 1
A hasInstruction() 0 5 1
A getInstruction() 0 10 2
1
<?php
2
3
namespace LegalThings\DataEnricher;
4
5
use LegalThings\DataEnricher\Processor;
6
7
/**
8
 * An object with processing instructions
9
 */
10
class Node extends \stdClass
11
{
12
    /**
13
     * The processed data
14
     * @var mixed 
15
     */
16
    protected $i_result;
17
18
    /**
19
     * Class constructor
20
     * 
21
     * @param \stdClass $data
22
     */
23
    public function __construct(\stdClass $data)
24
    {
25
        $this->i_result = $data;
26
        
27
        foreach ($data as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $data of type object<stdClass> is not traversable.
Loading history...
28
            if ($key === 'i_result') {
29
                continue;
30
            }
31
            
32
            $this->$key = $value;
33
        }
34
    }
35
    
36
    /**
37
     * Get the processed result
38
     * 
39
     * @return mixed
40
     */
41
    public function getResult()
42
    {
43
        return $this->i_result;
44
    }
45
    
46
    /**
47
     * Set the result after processing
48
     * 
49
     * @param mixed $result
50
     */
51
    public function setResult($result)
52
    {
53
        $this->i_result = $result;
54
    }
55
56
    
57
    /**
58
     * Test if the node has an instruction for a processor
59
     * 
60
     * @param Processor $processor
61
     * @return boolean
62
     */
63
    public function hasInstruction(Processor $processor)
64
    {
65
        $prop = $processor->getProperty();
66
        return isset($this->$prop);
67
    }
68
    
69
    /**
70
     * Get an instruction for a processor
71
     * 
72
     * @param Processor $processor
73
     * @return mixed
74
     */
75
    public function getInstruction(Processor $processor)
76
    {
77
        $prop = $processor->getProperty();
78
        
79
        if (!isset($this->$prop)) {
80
            throw new \LogicException("Node doesn't have instruction property '$prop'");
81
        }
82
        
83
        return $this->$prop;
84
    }
85
}
86