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

MenuStyle::getBorderBottomWidth()   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 0
1
<?php
2
3
namespace PhpSchool\CliMenu;
4
5
use PhpSchool\CliMenu\Exception\InvalidInstantiationException;
6
use PhpSchool\CliMenu\Terminal\TerminalFactory;
7
use PhpSchool\Terminal\Terminal;
8
9
//TODO: B/W fallback
10
11
/**
12
 * @author Michael Woodward <[email protected]>
13
 */
14
class MenuStyle
15
{
16
    /**
17
     * @var Terminal
18
     */
19
    protected $terminal;
20
21
    /**
22
     * @var string
23
     */
24
    protected $fg;
25
26
    /**
27
     * @var string
28
     */
29
    protected $bg;
30
31
    /**
32
     * @var int
33
     */
34
    protected $width;
35
36
    /**
37
     * @var int
38
     */
39
    protected $padding;
40
41
    /**
42
     * @var int
43
     */
44
    protected $margin;
45
46
    /**
47
     * @var int
48
     */
49
    protected $contentWidth;
50
51
    /**
52
     * @var string
53
     */
54
    private $selectedMarker;
55
56
    /**
57
     * @var string
58
     */
59
    private $unselectedMarker;
60
61
    /**
62
     * @var string
63
     */
64
    private $itemExtra;
65
66
    /**
67
     * @var bool
68
     */
69
    private $displaysExtra;
70
71
    /**
72
     * @var string
73
     */
74
    private $titleSeparator;
75
76
    /**
77
     * @var int
78
     */
79
    private $borderTopWidth;
80
81
    /**
82
     * @var int
83
     */
84
    private $borderRightWidth;
85
86
    /**
87
     * @var int
88
     */
89
    private $borderBottomWidth;
90
91
    /**
92
     * @var int
93
     */
94
    private $borderLeftWidth;
95
96
    /**
97
     * @var string
98
     */
99
    private $borderColour;
100
101
    /**
102
     * Default Values
103
     *
104
     * @var array
105
     */
106
    private static $defaultStyleValues = [
107
        'fg' => 'white',
108
        'bg' => 'blue',
109
        'width' => 100,
110
        'padding' => 2,
111
        'margin' => 2,
112
        'selectedMarker' => '●',
113
        'unselectedMarker' => '○',
114
        'itemExtra' => '✔',
115
        'displaysExtra' => false,
116
        'titleSeparator' => '=',
117
        'borderTopWidth' => 0,
118
        'borderRightWidth' => 0,
119
        'borderBottomWidth' => 0,
120
        'borderLeftWidth' => 0,
121
        'borderColour' => 'white',
122
    ];
123
124
    public static function getDefaultStyleValues() : array
125
    {
126
        return static::$defaultStyleValues;
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
127
    }
128
129
    /**
130
     * @var array
131
     */
132
    private static $availableForegroundColors = array(
133
        'black'   => array('set' => 30, 'unset' => 39),
134
        'red'     => array('set' => 31, 'unset' => 39),
135
        'green'   => array('set' => 32, 'unset' => 39),
136
        'yellow'  => array('set' => 33, 'unset' => 39),
137
        'blue'    => array('set' => 34, 'unset' => 39),
138
        'magenta' => array('set' => 35, 'unset' => 39),
139
        'cyan'    => array('set' => 36, 'unset' => 39),
140
        'white'   => array('set' => 37, 'unset' => 39),
141
        'default' => array('set' => 39, 'unset' => 39),
142
    );
143
144
    /**
145
     * @var array
146
     */
147
    private static $availableBackgroundColors = array(
148
        'black'   => array('set' => 40, 'unset' => 49),
149
        'red'     => array('set' => 41, 'unset' => 49),
150
        'green'   => array('set' => 42, 'unset' => 49),
151
        'yellow'  => array('set' => 43, 'unset' => 49),
152
        'blue'    => array('set' => 44, 'unset' => 49),
153
        'magenta' => array('set' => 45, 'unset' => 49),
154
        'cyan'    => array('set' => 46, 'unset' => 49),
155
        'white'   => array('set' => 47, 'unset' => 49),
156
        'default' => array('set' => 49, 'unset' => 49),
157
    );
158
159
    /**
160
     * @var array
161
     */
162
    private static $availableOptions = array(
163
        'bold'       => array('set' => 1, 'unset' => 22),
164
        'dim'        => array('set' => 2, 'unset' => 22),
165
        'underscore' => array('set' => 4, 'unset' => 24),
166
        'blink'      => array('set' => 5, 'unset' => 25),
167
        'reverse'    => array('set' => 7, 'unset' => 27),
168
        'conceal'    => array('set' => 8, 'unset' => 28)
169
    );
170
171
    /**
172
     * Initialise style
173
     */
174
    public function __construct(Terminal $terminal = null)
175
    {
176
        $this->terminal = $terminal ?: TerminalFactory::fromSystem();
177
178
        $this->setFg(static::$defaultStyleValues['fg']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
179
        $this->setBg(static::$defaultStyleValues['bg']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
180
        $this->setWidth(static::$defaultStyleValues['width']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
181
        $this->setPadding(static::$defaultStyleValues['padding']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
182
        $this->setMargin(static::$defaultStyleValues['margin']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
183
        $this->setSelectedMarker(static::$defaultStyleValues['selectedMarker']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
184
        $this->setUnselectedMarker(static::$defaultStyleValues['unselectedMarker']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
185
        $this->setItemExtra(static::$defaultStyleValues['itemExtra']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
186
        $this->setDisplaysExtra(static::$defaultStyleValues['displaysExtra']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
187
        $this->setTitleSeparator(static::$defaultStyleValues['titleSeparator']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
188
        $this->setBorderTopWidth(static::$defaultStyleValues['borderTopWidth']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
189
        $this->setBorderRightWidth(static::$defaultStyleValues['borderRightWidth']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
190
        $this->setBorderBottomWidth(static::$defaultStyleValues['borderBottomWidth']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
191
        $this->setBorderLeftWidth(static::$defaultStyleValues['borderLeftWidth']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
192
        $this->setBorderColour(static::$defaultStyleValues['borderColour']);
0 ignored issues
show
Bug introduced by
Since $defaultStyleValues is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultStyleValues to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
193
194
    }
195
196
    public static function getAvailableColours() : array
197
    {
198
        return array_keys(self::$availableBackgroundColors);
199
    }
200
201
    public function getDisabledItemText(string $text) : string
202
    {
203
        return sprintf(
204
            "\033[%sm%s\033[%sm",
205
            self::$availableOptions['dim']['set'],
206
            $text,
207
            self::$availableOptions['dim']['unset']
208
        );
209
    }
210
    
211
    /**
212
     * Get the colour code set for Bg and Fg
213
     */
214 View Code Duplication
    public function getSelectedSetCode() : string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
215
    {
216
        return sprintf(
217
            "\033[%sm",
218
            implode(';', [
219
                self::$availableBackgroundColors[$this->getFg()]['set'],
220
                self::$availableForegroundColors[$this->getBg()]['set'],
221
            ])
222
        );
223
    }
224
225
    /**
226
     * Get the colour unset code for Bg and Fg
227
     */
228 View Code Duplication
    public function getSelectedUnsetCode() : string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
229
    {
230
        return sprintf(
231
            "\033[%sm",
232
            implode(';', [
233
                self::$availableBackgroundColors[$this->getBg()]['unset'],
234
                self::$availableForegroundColors[$this->getFg()]['unset'],
235
            ])
236
        );
237
    }
238
239
    /**
240
     * Get the inverted colour code
241
     */
242 View Code Duplication
    public function getUnselectedSetCode() : string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
243
    {
244
        return sprintf(
245
            "\033[%sm",
246
            implode(';', [
247
                self::$availableBackgroundColors[$this->getBg()]['set'],
248
                self::$availableForegroundColors[$this->getFg()]['set'],
249
            ])
250
        );
251
    }
252
253
    /**
254
     * Get the inverted colour unset code
255
     */
256 View Code Duplication
    public function getUnselectedUnsetCode() : string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
257
    {
258
        return sprintf(
259
            "\033[%sm",
260
            implode(';', [
261
                self::$availableBackgroundColors[$this->getBg()]['unset'],
262
                self::$availableForegroundColors[$this->getFg()]['unset'],
263
            ])
264
        );
265
    }
266
267
    /**
268
     * Calculate the contents width
269
     */
270
    protected function calculateContentWidth() : void
271
    {
272
        $this->contentWidth = $this->width - ($this->padding*2) - ($this->margin*2) - ($this->borderRightWidth + $this->borderLeftWidth);
273
    }
274
275
    public function getFg() : string
276
    {
277
        return $this->fg;
278
    }
279
280
    public function setFg(string $fg) : self
281
    {
282
        $this->fg = $fg;
283
284
        return $this;
285
    }
286
287
    public function getBg() : string
288
    {
289
        return $this->bg;
290
    }
291
292
    public function setBg(string $bg) : self
293
    {
294
        $this->bg = $bg;
295
296
        return $this;
297
    }
298
299
    public function getWidth() : int
300
    {
301
        return $this->width;
302
    }
303
304
    public function setWidth(int $width) : self
305
    {
306
        $availableWidth = $this->terminal->getWidth() - ($this->margin * 2) - ($this->padding * 2) - ($this->borderRightWidth + $this->borderLeftWidth);
307
308
        if ($width >= $availableWidth) {
309
            $width = $availableWidth;
310
        }
311
312
        $this->width = $width;
0 ignored issues
show
Documentation Bug introduced by
It seems like $width can also be of type double. However, the property $width is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
313
        $this->calculateContentWidth();
314
315
        return $this;
316
    }
317
318
    public function getPadding() : int
319
    {
320
        return $this->padding;
321
    }
322
323
    public function setPadding(int $padding) : self
324
    {
325
        $this->padding = $padding;
326
327
        $this->calculateContentWidth();
328
329
        return $this;
330
    }
331
332
    public function getMargin() : int
333
    {
334
        return $this->margin;
335
    }
336
337
    public function setMargin(int $margin) : self
338
    {
339
        $this->margin = $margin;
340
341
        $this->calculateContentWidth();
342
343
        return $this;
344
    }
345
346
    public function getContentWidth() : int
347
    {
348
        return $this->contentWidth;
349
    }
350
351
    /**
352
     * Get padding for right had side of content
353
     */
354
    public function getRightHandPadding(int $contentLength) : int
355
    {
356
        return $this->getContentWidth() - $contentLength + $this->getPadding();
357
    }
358
359
    public function getSelectedMarker() : string
360
    {
361
        return $this->selectedMarker;
362
    }
363
364
    public function setSelectedMarker(string $marker) : self
365
    {
366
        $this->selectedMarker = mb_substr($marker, 0, 1);
367
368
        return $this;
369
    }
370
371
    public function getUnselectedMarker() : string
372
    {
373
        return $this->unselectedMarker;
374
    }
375
376
    public function setUnselectedMarker(string $marker) : self
377
    {
378
        $this->unselectedMarker = mb_substr($marker, 0, 1);
379
380
        return $this;
381
    }
382
383
    /**
384
     * Get the correct marker for the item
385
     */
386
    public function getMarker(bool $selected) : string
387
    {
388
        return $selected ? $this->selectedMarker : $this->unselectedMarker;
389
    }
390
391
    public function setItemExtra(string $itemExtra) : self
392
    {
393
        $this->itemExtra = $itemExtra;
394
395
        return $this;
396
    }
397
398
    public function getItemExtra() : string
399
    {
400
        return $this->itemExtra;
401
    }
402
403
    public function getDisplaysExtra() : bool
404
    {
405
        return $this->displaysExtra;
406
    }
407
408
    public function setDisplaysExtra(bool $displaysExtra) : self
409
    {
410
        $this->displaysExtra = $displaysExtra;
411
412
        return $this;
413
    }
414
415
    public function getTitleSeparator() : string
416
    {
417
        return $this->titleSeparator;
418
    }
419
420
    public function setTitleSeparator(string $actionSeparator) : self
421
    {
422
        $this->titleSeparator = $actionSeparator;
423
424
        return $this;
425
    }
426
    
427
    /**
428
     * Shorthand function to set all borders values at once
429
     */
430
    public function setBorder(int $topWidth, int $rightWidth = null, int $bottomWidth = null, int $leftWidth = null, string $colour = null) : self
431
    {
432
        $this->borderTopWidth = $topWidth;
433
        $this->borderRightWidth = $rightWidth ?? $topWidth;
434
        $this->borderBottomWidth = $bottomWidth ?? $topWidth;
435
        $this->borderLeftWidth = $leftWidth ?? $rightWidth ?? $topWidth;
436
        if ($colour !== null) {
437
            $this->borderColour = $colour;
438
        }
439
440
        return $this;
441
    }
442
    public function setBorderTopWidth(int $width) : self
443
    {
444
        $this->borderTopWidth = $width;
445
446
        return $this;
447
    }
448
    public function setBorderRightWidth(int $width) : self
449
    {
450
        $this->borderRightWidth = $width;
451
452
        return $this;
453
    }
454
    public function setBorderBottomWidth(int $width) : self
455
    {
456
        $this->borderBottomWidth = $width;
457
458
        return $this;
459
    }
460
    public function setBorderLeftWidth(int $width) : self
461
    {
462
        $this->borderLeftWidth = $width;
463
464
        return $this;
465
    }
466
    public function setBorderColour(string $colour) : self
467
    {
468
        $this->borderColour = $colour;
469
470
        return $this;
471
    }
472
    public function getBorderTopWidth() : int
473
    {
474
        return $this->borderTopWidth;
475
    }
476
    public function getBorderRightWidth() : int
477
    {
478
        return $this->borderRightWidth;
479
    }
480
    public function getBorderBottomWidth() : int
481
    {
482
        return $this->borderBottomWidth;
483
    }
484
    public function getBorderLeftWidth() : int
485
    {
486
        return $this->borderLeftWidth;
487
    }
488
    public function getBorderColour() : string
489
    {
490
        return $this->borderColour;
491
    }
492
    public function getBorderColourCode() : string
493
    {
494
        return sprintf("\033[%sm", self::$availableBackgroundColors[$this->getBorderColour()]['set']);
495
    }
496
}
497