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

Table::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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