Completed
Push — master ( 2edd9d...d97347 )
by Aydin
21s queued 11s
created

LineBreakItem::setStyle()   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 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace PhpSchool\CliMenu\MenuItem;
4
5
use Assert\Assertion;
6
use PhpSchool\CliMenu\MenuStyle;
7
use PhpSchool\CliMenu\Style\DefaultStyle;
8
use PhpSchool\CliMenu\Style\ItemStyle;
9
10
/**
11
 * @author Michael Woodward <[email protected]>
12
 */
13
class LineBreakItem implements MenuItemInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $breakChar;
19
20
    /**
21
     * @var int
22
     */
23
    private $lines;
24
25
    /**
26
     * @var DefaultStyle
27
     */
28
    private $style;
29
30
    public function __construct(string $breakChar = ' ', int $lines = 1)
31
    {
32
        $this->breakChar = $breakChar;
33
        $this->lines = $lines;
34
35
        $this->style = new DefaultStyle();
36
    }
37
38
    /**
39
     * The output text for the item
40
     */
41
    public function getRows(MenuStyle $style, bool $selected = false) : array
42
    {
43
        return explode(
44
            "\n",
45
            rtrim(str_repeat(sprintf(
46
                "%s\n",
47
                mb_substr(str_repeat($this->breakChar, $style->getContentWidth()), 0, $style->getContentWidth())
48
            ), $this->lines))
49
        );
50
    }
51
52
    /**
53
     * Can the item be selected
54
     */
55
    public function canSelect() : bool
56
    {
57
        return false;
58
    }
59
60
    /**
61
     * Execute the items callable if required
62
     */
63
    public function getSelectAction() : ?callable
64
    {
65
        return null;
66
    }
67
68
    /**
69
     * Return the raw string of text
70
     */
71
    public function getText() : string
72
    {
73
        return $this->breakChar;
74
    }
75
76
    /**
77
     * Set the raw string of text
78
     */
79
    public function setText(string $text) : void
80
    {
81
        $this->breakChar = $text;
82
    }
83
84
    /**
85
     * Whether or not the menu item is showing the menustyle extra value
86
     */
87
    public function showsItemExtra() : bool
88
    {
89
        return false;
90
    }
91
92
    public function getLines() : int
93
    {
94
        return $this->lines;
95
    }
96
97
    /**
98
     * Enable showing item extra
99
     */
100
    public function showItemExtra() : void
101
    {
102
        //noop
103
    }
104
105
    /**
106
     * Disable showing item extra
107
     */
108
    public function hideItemExtra() : void
109
    {
110
        //noop
111
    }
112
113
    /**
114
     * @return DefaultStyle
115
     */
116
    public function getStyle() : ItemStyle
117
    {
118
        return $this->style;
119
    }
120
121
    public function setStyle(DefaultStyle $style) : void
122
    {
123
        $this->style = $style;
124
    }
125
}
126