RagNumbers::getData()   B
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 23
ccs 16
cts 16
cp 1
rs 8.7972
cc 4
eloc 13
nc 8
nop 0
crap 4
1
<?php
2
3
namespace CarlosIO\Geckoboard\Widgets;
4
5
use CarlosIO\Geckoboard\Data\Entry;
6
7
/**
8
 * Class RagNumbers.
9
 */
10
class RagNumbers extends Widget
11
{
12
    /**
13
     * @var array red, amber and green dataset repository
14
     */
15
    protected $dataset;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 4
    public function __construct()
21
    {
22 4
        $this->dataset = array();
23 4
    }
24
25
    /**
26
     * Get red data.
27
     *
28
     * @return Entry
29
     */
30 4
    public function getRedData()
31
    {
32 4
        return $this->getEntry('red');
33
    }
34
35
    /**
36
     * Set red data.
37
     *
38
     * @param Entry $entry
39
     *
40
     * @return $this
41
     */
42 4
    public function setRedData(Entry $entry)
43
    {
44 4
        $this->setEntry('red', $entry);
45
46 4
        return $this;
47
    }
48
49
    /**
50
     * Get amber data.
51
     *
52
     * @return Entry
53
     */
54 4
    public function getAmberData()
55
    {
56 4
        return $this->getEntry('amber');
57
    }
58
59
    /**
60
     * Set amber data.
61
     *
62
     * @param Entry $entry
63
     *
64
     * @return $this
65
     */
66 2
    public function setAmberData(Entry $entry)
67
    {
68 2
        $this->setEntry('amber', $entry);
69
70 2
        return $this;
71
    }
72
73
    /**
74
     * Get green data.
75
     *
76
     * @return Entry
77
     */
78 4
    public function getGreenData()
79
    {
80 4
        return $this->getEntry('green');
81
    }
82
83
    /**
84
     * Set green data.
85
     *
86
     * @param Entry $entry
87
     *
88
     * @return $this
89
     */
90 4
    public function setGreenData(Entry $entry)
91
    {
92 4
        $this->setEntry('green', $entry);
93
94 4
        return $this;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 4
    public function getData()
101
    {
102 4
        $result = array();
103
104 4
        $redData = $this->getRedData();
105 4
        if (null !== $redData) {
106 4
            $result[] = $redData->toArray();
107 4
        }
108
109 4
        $amberData = $this->getAmberData();
110 4
        if (null !== $amberData) {
111 2
            $result[] = $amberData->toArray();
112 2
        }
113
114 4
        $greenData = $this->getGreenData();
115 4
        if (null !== $greenData) {
116 4
            $result[] = $greenData->toArray();
117 4
        }
118
119
        return array(
120 4
            'item' => $result,
121 4
        );
122
    }
123
124
    /**
125
     * Set specific data.
126
     *
127
     * @param $color
128
     * @param $entry
129
     *
130
     * @return $this
131
     */
132 4
    protected function setEntry($color, $entry)
133
    {
134 4
        $this->dataset[$color] = $entry;
135
136 4
        return $this;
137
    }
138
139
    /**
140
     * Get specific data.
141
     *
142
     * @param $color
143
     *
144
     * @return null|Entry
145
     */
146 4
    protected function getEntry($color)
147
    {
148 4
        if (!isset($this->dataset[$color])) {
149 2
            return;
150
        }
151
152 4
        return $this->dataset[$color];
153
    }
154
}
155