Completed
Pull Request — master (#204)
by
unknown
02:02
created

ToggableTrait::getText()   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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace PhpSchool\CliMenu\MenuItem;
4
5
trait ToggableTrait
6
{
7
    /**
8
     * @var callable
9
     */
10
    private $selectAction;
11
12
    private $text = '';
13
14
    private $showItemExtra = false;
15
16
    private $disabled = false;
17
18
    private $checked = false;
19
20
    /**
21
     * Toggles checked state
22
     */
23
    public function toggle() : void
24
    {
25
        $this->checked = !$this->checked;
26
    }
27
28
    /**
29
     * Sets checked state to true
30
     */
31
    public function setChecked() : void
32
    {
33
        $this->checked = true;
34
    }
35
36
    /**
37
     * Sets checked state to false
38
     */
39
    public function setUnchecked() : void
40
    {
41
        $this->checked = false;
42
    }
43
44
    /**
45
     * Whether or not the item is checked
46
     */
47
    public function getChecked() : bool
48
    {
49
        return $this->checked;
50
    }
51
52
    /**
53
     * Return the raw string of text
54
     */
55
    public function getText() : string
56
    {
57
        return $this->text;
58
    }
59
60
    /**
61
     * Set the raw string of text
62
     */
63
    public function setText(string $text) : void
64
    {
65
        $this->text = $text;
66
    }
67
68
    /**
69
     * Can the item be selected
70
     */
71
    public function canSelect() : bool
72
    {
73
        return !$this->disabled;
74
    }
75
76
    public function showsItemExtra() : bool
77
    {
78
        return $this->showItemExtra;
79
    }
80
81
    /**
82
     * Enable showing item extra
83
     */
84
    public function showItemExtra() : void
85
    {
86
        $this->showItemExtra = true;
87
    }
88
89
    /**
90
     * Disable showing item extra
91
     */
92
    public function hideItemExtra() : void
93
    {
94
        $this->showItemExtra = false;
95
    }
96
}
97