Text::setItems()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace CarlosIO\Geckoboard\Widgets;
4
5
use CarlosIO\Geckoboard\Data\Text\Item;
6
7
/**
8
 * Class Text.
9
 */
10
class Text extends Widget
11
{
12
    /**
13
     * @var array Messages
14
     */
15
    protected $items;
16
17
    /**
18
     * Set the items property.
19
     *
20
     * @param array $items Set of items to add to the widget
21
     *
22
     * @return $this
23
     */
24 1
    public function setItems($items)
25
    {
26 1
        $this->items = $items;
27
28 1
        return $this;
29
    }
30
31
    /**
32
     * Return the items attribute.
33
     *
34
     * @return array
35
     */
36 4
    public function getItems()
37
    {
38 4
        if (null === $this->items) {
39 1
            $this->items = array();
40 1
        }
41
42 4
        return $this->items;
43
    }
44
45
    /**
46
     * Add an item to the item list.
47
     *
48
     * @param \CarlosIO\Geckoboard\Data\Text\Item $item Item to be added
49
     *
50
     * @return $this
51
     */
52 3
    public function addItem(Item $item)
53
    {
54 3
        $this->items[] = $item;
55
56 3
        return $this;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 4
    public function getData()
63
    {
64
        return array(
65 4
            'item' => array_map(
66 4
                function (Item $item) {
67 3
                    return $item->toArray();
68 4
                },
69 4
                $this->getItems()
70 4
            ),
71 4
        );
72
    }
73
}
74