Completed
Pull Request — master (#92)
by
unknown
03:57
created

MenuMenuItem::getSubMenu()   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 0
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
     * Returns the sub menu
45
     */
46
    public function getSubMenu() : CliMenu
47
    {
48
        return $this->subMenu;
49
    }
50
51
    /**
52
     * Display the sub menu
53
     */
54
    public function showSubMenu(CliMenu $parentMenu) : void
55
    {
56
        $parentMenu->closeThis();
57
        $this->subMenu->open();
58
    }
59
}
60