Passed
Push — master ( 3bf788...763f00 )
by Jon
02:39 queued 10s
created

Gallery::setRole()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php namespace FlatPlan\Components;
2
3
use FlatPlan\Components\Image;
4
5
class Gallery extends AbstractComponent {
6
7
    private $role;
8
    private $items = array();
9
10
    protected $roles = ['gallery', 'mosaic'];
11
12
    /**
13
     * @param string $role
14
     * @param string $bannerType
15
     * @return void
16
     */
17
    public function __construct($role)
18
    {
19
        $this->setRole($role);
20
    }
21
22
    public function setRole($role)
23
    {
24
        if (!in_array($role, $this->roles)) {
25
            throw new \ErrorException('Invalid role supplied.');
26
        }
27
        $this->role = $role;
28
    }
29
30
    public function getRole()
31
    {
32
        return $this->role;
33
    }
34
35
    public function setItem($item)
36
    {
37
        if ($item instanceof Image) {
38
            array_push($this->items, $item);
39
        } else {
40
            throw new \ErrorException('Invalid image component supplied.');
41
        }
42
    }
43
44
    public function getItems()
45
    {
46
        return $this->items;
47
    }
48
49
    public function getComponent()
50
    {
51
        $component = new \stdClass();
52
        $component->role  = $this->getRole();
53
        $component->items = $this->getItems();
54
        return $component;
55
    }
56
57
    public function __toString()
58
    {
59
        return json_encode($this->getComponent());
60
    }
61
}
62