Passed
Push — master ( 6a69b3...5f0e13 )
by Jon
02:04
created

AbstractComponent::updateStyles()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 9
rs 9.6666
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 updateStyles($role)
27
    {
28
        $this->layout    = $role . ucfirst($this->layout);
29
        $this->style     = $role . ucfirst($this->style);
30
        $this->textStyle = $role . ucfirst($this->textStyle);
31
32
        if (isset($this->components)) {
33
            foreach ($this->components as $component) {
34
                $component->updateStyles($role);
35
            }
36
        }
37
    }
38
39
    public function __toString()
40
    {
41
        return json_encode($this->getComponent());
42
    }
43
}
44