Passed
Push — master ( 18ff88...32a943 )
by Michael
39s
created

ConfigItem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 76
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A set() 0 11 2
A getValue() 0 4 1
A getMetaData() 0 4 1
A getHistory() 0 4 1
A __clone() 0 4 1
1
<?php
2
3
namespace micmania1\config;
4
5
class ConfigItem implements ConfigItemInterface
6
{
7
    /**
8
     * @var mixed
9
     */
10
    protected $value;
11
12
    /**
13
     * @var array
14
     */
15
    protected $metaData = [];
16
17
    /**
18
     * @var array
19
     */
20
    protected $history = [];
21
22
    /**
23
     * @var boolean
24
     */
25
    protected $trackHistory = true;
26
27 22
    public function __construct($value, array $metaData = [], $trackHistory = true)
28
    {
29 22
        $this->value = $value;
30 22
        $this->metaData = $metaData;
31 22
        $this->trackHistory = (boolean) $trackHistory;
32 22
    }
33
34 22
    public function set($value, $metaData = [])
35
    {
36 22
        if($this->trackHistory) {
37
            // Clone will clear the history to prevent recursion
38 22
            $previous = clone $this;
39 22
            $this->history[] = $previous;
40 22
        }
41
42 22
        $this->value = $value;
43 22
        $this->metaData = $metaData;
44 22
    }
45
46
    /**
47
     * @return mixed
48
     */
49 22
    public function getValue()
50
    {
51 22
        return $this->value;
52
    }
53
54
    /**
55
     * @return array
56
     */
57 22
    public function getMetaData()
58
    {
59 22
        return $this->metaData;
60
    }
61
62
    /**
63
     * Fetch the item history ordered in descending order by data
64
     *
65
     * @return CollectionItemInterface[]
66
     */
67 1
    public function getHistory()
68
    {
69 1
        return $this->history;
70
    }
71
72
    /**
73
     * History is an array of historical records of itself so we clear it to prevent
74
     * recursion.
75
     */
76 22
    public function __clone()
77
    {
78 22
        $this->history = [];
79 22
    }
80
}
81