Passed
Push — master ( 70f9dc...bcb616 )
by Jon
01:45
created

AbstractComponent::getRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace FlatPlan\Components;
2
3
abstract class AbstractComponent {
4
5
    protected $role;
6
    protected $layout    = 'layout';
7
    protected $style     = 'style';
8
    protected $textStyle = 'textStyle';
9
10
    abstract public function getComponent();
11
12
    public function setRole($role)
13
    {
14
        if (!in_array($role, $this->roles)) {
15
            throw new \ErrorException('Invalid role supplied.');
16
        }
17
        $this->role = $role;
18
        $this->updateStyles($role);
19
    }
20
21
    public function getRole()
22
    {
23
        return $this->role;
24
    }
25
26
    public function setIdentifier($identifier)
27
    {
28
        $this->identifier = $identifier;
0 ignored issues
show
Bug Best Practice introduced by
The property identifier does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
    }
30
31
    public function getIdentifier()
32
    {
33
        return $this->identifier;
34
    }
35
36
    public function updateStyles($role)
37
    {
38
        $this->layout    = $role . ucfirst($this->layout);
39
        $this->style     = $role . ucfirst($this->style);
40
        $this->textStyle = $role . ucfirst($this->textStyle);
41
42
        if (isset($this->components)) {
43
            foreach ($this->components as $component) {
44
                $component->updateStyles($role);
45
            }
46
        }
47
    }
48
49
    public function __toString()
50
    {
51
        return json_encode($this->getComponent());
52
    }
53
}
54