StaticItem   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 94
rs 10
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getText() 0 3 1
A showsItemExtra() 0 3 1
A getRows() 0 3 1
A setText() 0 3 1
A canSelect() 0 3 1
A setStyle() 0 3 1
A getSelectAction() 0 3 1
A hideItemExtra() 0 2 1
A __construct() 0 5 1
A getStyle() 0 3 1
A showItemExtra() 0 2 1
1
<?php
2
3
namespace PhpSchool\CliMenu\MenuItem;
4
5
use PhpSchool\CliMenu\MenuStyle;
6
use PhpSchool\CliMenu\Style\DefaultStyle;
7
use PhpSchool\CliMenu\Style\ItemStyle;
8
use PhpSchool\CliMenu\Util\StringUtil;
9
10
/**
11
 * @author Michael Woodward <[email protected]>
12
 */
13
class StaticItem implements MenuItemInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $text;
19
20
    /**
21
     * @var DefaultStyle
22
     */
23
    private $style;
24
25
    public function __construct(string $text)
26
    {
27
        $this->text = $text;
28
29
        $this->style = new DefaultStyle();
30
    }
31
32
    /**
33
     * The output text for the item
34
     */
35
    public function getRows(MenuStyle $style, bool $selected = false) : array
36
    {
37
        return explode("\n", StringUtil::wordwrap($this->text, $style->getContentWidth()));
38
    }
39
40
    /**
41
     * Return the raw string of text
42
     */
43
    public function getText() : string
44
    {
45
        return $this->text;
46
    }
47
48
    /**
49
     * Set the raw string of text
50
     */
51
    public function setText(string $text) : void
52
    {
53
        $this->text = $text;
54
    }
55
56
    /**
57
     * Execute the items callable if required
58
     */
59
    public function getSelectAction() : ?callable
60
    {
61
        return null;
62
    }
63
64
    /**
65
     * Can the item be selected
66
     */
67
    public function canSelect() : bool
68
    {
69
        return false;
70
    }
71
72
    /**
73
     * Whether or not we are showing item extra
74
     */
75
    public function showsItemExtra() : bool
76
    {
77
        return false;
78
    }
79
80
    /**
81
     * Enable showing item extra
82
     */
83
    public function showItemExtra() : void
84
    {
85
        //noop
86
    }
87
88
    /**
89
     * Disable showing item extra
90
     */
91
    public function hideItemExtra() : void
92
    {
93
        //noop
94
    }
95
96
    /**
97
     * @return DefaultStyle
98
     */
99
    public function getStyle() : ItemStyle
100
    {
101
        return $this->style;
102
    }
103
104
    public function setStyle(DefaultStyle $style) : void
105
    {
106
        $this->style = $style;
107
    }
108
}
109