Completed
Push — master ( 33d412...b764b5 )
by Ben
02:26
created

Branch::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Thinktomorrow\Vine\Branch;
4
5
use Thinktomorrow\Vine\VineException;
6
7
/**
8
 * Class Branch
9
 *
10
 * @property string $key
11
 * @property string $value
12
 * @property string $label
13
 * @property array $branches
14
 */
15
class Branch
16
{
17
    private $key;
18
    private $value;
19
    private $label;
20
    private $branches;
21
22 42
    public function __construct($key, $value, $label, BranchCollection $branches = null)
23
    {
24 42
        $this->key = $key;
25 42
        $this->value = $value;
26 42
        $this->label = $label;
27 42
        $this->branches = $branches?: new BranchCollection();
28 42
    }
29
30 12
    public function hasBranches()
31
    {
32 12
        return ($this->branches->hasBranches());
33
    }
34
35 9
    public function push(Branch $branch)
36
    {
37 9
        $this->branches[] = $branch;
38
39 9
        return $this;
40
    }
41
42 42
    public function __get($key)
43
    {
44 42
        if(isset($this->$key)) return $this->$key;
45
46 3
        throw VineException::unknownBranchAttribute($key);
47
    }
48
}
49