Passed
Push — master ( f80586...f4cd30 )
by Jon
07:56 queued 12s
created

Table   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setRole() 0 6 2
A getRole() 0 3 1
A getComponent() 0 5 1
A __construct() 0 3 1
A __toString() 0 3 1
1
<?php namespace FlatPlan\Components;
2
3
class Table extends AbstractComponent {
4
5
    private $role;
6
7
    protected $roles = ['table'];
8
9
    /**
10
     * @param string $role
11
     * @return void
12
     */
13
    public function __construct($role)
14
    {
15
        $this->setRole($role);
16
    }
17
18
    public function setRole($role)
19
    {
20
        if (!in_array($role, $this->roles)) {
21
            throw new \ErrorException('Invalid role supplied.');
22
        }
23
        $this->role = $role;
24
    }
25
26
    public function getRole()
27
    {
28
        return $this->role;
29
    }
30
31
    public function getComponent()
32
    {
33
        $component = new \stdClass();
34
        $component->role = $this->getRole();
35
        return $component;
36
    }
37
38
    public function __toString()
39
    {
40
        return json_encode($this->getComponent());
41
    }
42
}
43