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

LineBreakItem::setText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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