Completed
Push — master ( 306131...5909ec )
by Aydin
06:33 queued 03:57
created

MenuMenuItem::showSubMenu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace PhpSchool\CliMenu\MenuItem;
4
5
use Assert\Assertion;
6
use PhpSchool\CliMenu\CliMenu;
7
8
/**
9
 * @author Michael Woodward <[email protected]>
10
 */
11
class MenuMenuItem implements MenuItemInterface
12
{
13
    use SelectableTrait;
14
    
15
    /**
16
     * @var CliMenu
17
     */
18
    private $subMenu;
19
20
    public function __construct(string $text, CliMenu $subMenu, bool $disabled = false)
21
    {
22
        $this->text     = $text;
23
        $this->subMenu  = $subMenu;
24
        $this->disabled = $disabled;
25
    }
26
27
    /**
28
     * Execute the items callable if required
29
     */
30
    public function getSelectAction() : ?callable
31
    {
32
        return [$this, 'showSubMenu'];
33
    }
34
35
    /**
36
     * Return the raw string of text
37
     */
38
    public function getText() : string
39
    {
40
        return $this->text;
41
    }
42
43
    /**
44
     * Set the raw string of text
45
     */
46
    public function setText(string $text) : void
47
    {
48
        $this->text = $text;
49
    }
50
    
51
    /**
52
     * Returns the sub menu
53
     */
54
    public function getSubMenu() : CliMenu
55
    {
56
        return $this->subMenu;
57
    }
58
59
    /**
60
     * Display the sub menu
61
     */
62
    public function showSubMenu(CliMenu $parentMenu) : void
63
    {
64
        $parentMenu->closeThis();
65
        $this->subMenu->open();
66
    }
67
}
68