Completed
Push — master ( 207c5b...13311a )
by Aydin
02:50 queued 10s
created

SplitItemBuilder::setGutter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace PhpSchool\CliMenu\Builder;
4
5
use PhpSchool\CliMenu\CliMenu;
6
use PhpSchool\CliMenu\MenuItem\SplitItem;
7
use PhpSchool\CliMenu\MenuStyle;
8
use PhpSchool\Terminal\Terminal;
9
10
/**
11
 * @author Aydin Hassan <[email protected]>
12
 */
13
class SplitItemBuilder implements Builder
14
{
15
    use BuilderUtils;
16
17
    /**
18
     * @var int
19
     */
20
    private $gutter = 2;
21
22
    public function __construct(Builder $parent)
23
    {
24
        $this->parent = $parent;
0 ignored issues
show
Bug introduced by Aydin Hassan
The property parent does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    public function build() : SplitItem
28
    {
29
        $items = $this->buildSubMenus($this->menuItems);
30
        
31
        $splitItem = new SplitItem($items);
32
        $splitItem->setGutter($this->gutter);
33
34
        return $splitItem;
35
    }
36
37
    public function setSubMenuParents(CliMenu $menu) : void
38
    {
39
        foreach ($this->subMenus as $subMenu) {
40
            $subMenu->setParent($menu);
41
        }
42
    }
43
44
    public function getTerminal() : Terminal
45
    {
46
        return $this->parent->getTerminal();
47
    }
48
49
    public function getMenuStyle() : MenuStyle
50
    {
51
        return $this->parent->getMenuStyle();
52
    }
53
54
    public function end() : CliMenuBuilder
55
    {
56
        return $this->parent;
57
    }
58
59
    public function setGutter(int $gutter) : SplitItemBuilder
60
    {
61
        $this->gutter = $gutter;
62
    }
63
}
64