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

AbstractComponent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setRole() 0 7 2
A __toString() 0 3 1
A getRole() 0 3 1
A updateStyles() 0 9 3
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