Completed
Pull Request — master (#100)
by
unknown
01:47
created

MenuStyle::getPadding()   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
    public static function getAvailableColours() : array
196
    {
197
        return array_keys(self::$availableBackgroundColors);
198
    }
199
200
    public function getDisabledItemText(string $text) : string
201
    {
202
        return sprintf(
203
            "\033[%sm%s\033[%sm",
204
            self::$availableOptions['dim']['set'],
205
            $text,
206
            self::$availableOptions['dim']['unset']
207
        );
208
    }
209
    
210
    /**
211
     * Get the colour code set for Bg and Fg
212
     */
213 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...
214
    {
215
        return sprintf(
216
            "\033[%sm",
217
            implode(';', [
218
                self::$availableBackgroundColors[$this->getFg()]['set'],
219
                self::$availableForegroundColors[$this->getBg()]['set'],
220
            ])
221
        );
222
    }
223
224
    /**
225
     * Get the colour unset code for Bg and Fg
226
     */
227 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...
228
    {
229
        return sprintf(
230
            "\033[%sm",
231
            implode(';', [
232
                self::$availableBackgroundColors[$this->getBg()]['unset'],
233
                self::$availableForegroundColors[$this->getFg()]['unset'],
234
            ])
235
        );
236
    }
237
238
    /**
239
     * Get the inverted colour code
240
     */
241 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...
242
    {
243
        return sprintf(
244
            "\033[%sm",
245
            implode(';', [
246
                self::$availableBackgroundColors[$this->getBg()]['set'],
247
                self::$availableForegroundColors[$this->getFg()]['set'],
248
            ])
249
        );
250
    }
251
252
    /**
253
     * Get the inverted colour unset code
254
     */
255 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...
256
    {
257
        return sprintf(
258
            "\033[%sm",
259
            implode(';', [
260
                self::$availableBackgroundColors[$this->getBg()]['unset'],
261
                self::$availableForegroundColors[$this->getFg()]['unset'],
262
            ])
263
        );
264
    }
265
266
    /**
267
     * Calculate the contents width
268
     */
269
    protected function calculateContentWidth() : void
270
    {
271
        $this->contentWidth = $this->width
272
            - ($this->padding*2)
273
            - ($this->margin*2)
274
            - ($this->borderRightWidth + $this->borderLeftWidth);
275
    }
276
277
    public function getFg() : string
278
    {
279
        return $this->fg;
280
    }
281
282
    public function setFg(string $fg) : self
283
    {
284
        $this->fg = $fg;
285
286
        return $this;
287
    }
288
289
    public function getBg() : string
290
    {
291
        return $this->bg;
292
    }
293
294
    public function setBg(string $bg) : self
295
    {
296
        $this->bg = $bg;
297
298
        return $this;
299
    }
300
301
    public function getWidth() : int
302
    {
303
        return $this->width;
304
    }
305
306
    public function setWidth(int $width) : self
307
    {
308
        $availableWidth = $this->terminal->getWidth()
309
            - ($this->margin * 2)
310
            - ($this->padding * 2)
311
            - ($this->borderRightWidth + $this->borderLeftWidth);
312
313
        if ($width >= $availableWidth) {
314
            $width = $availableWidth;
315
        }
316
317
        $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...
318
        $this->calculateContentWidth();
319
320
        return $this;
321
    }
322
323
    public function getPadding() : int
324
    {
325
        return $this->padding;
326
    }
327
328
    public function setPadding(int $padding) : self
329
    {
330
        $this->padding = $padding;
331
332
        $this->calculateContentWidth();
333
334
        return $this;
335
    }
336
337
    public function getMargin() : int
338
    {
339
        return $this->margin;
340
    }
341
342
    public function setMargin(int $margin) : self
343
    {
344
        $this->margin = $margin;
345
346
        $this->calculateContentWidth();
347
348
        return $this;
349
    }
350
351
    public function getContentWidth() : int
352
    {
353
        return $this->contentWidth;
354
    }
355
356
    /**
357
     * Get padding for right had side of content
358
     */
359
    public function getRightHandPadding(int $contentLength) : int
360
    {
361
        return $this->getContentWidth() - $contentLength + $this->getPadding();
362
    }
363
364
    public function getSelectedMarker() : string
365
    {
366
        return $this->selectedMarker;
367
    }
368
369
    public function setSelectedMarker(string $marker) : self
370
    {
371
        $this->selectedMarker = mb_substr($marker, 0, 1);
372
373
        return $this;
374
    }
375
376
    public function getUnselectedMarker() : string
377
    {
378
        return $this->unselectedMarker;
379
    }
380
381
    public function setUnselectedMarker(string $marker) : self
382
    {
383
        $this->unselectedMarker = mb_substr($marker, 0, 1);
384
385
        return $this;
386
    }
387
388
    /**
389
     * Get the correct marker for the item
390
     */
391
    public function getMarker(bool $selected) : string
392
    {
393
        return $selected ? $this->selectedMarker : $this->unselectedMarker;
394
    }
395
396
    public function setItemExtra(string $itemExtra) : self
397
    {
398
        $this->itemExtra = $itemExtra;
399
400
        return $this;
401
    }
402
403
    public function getItemExtra() : string
404
    {
405
        return $this->itemExtra;
406
    }
407
408
    public function getDisplaysExtra() : bool
409
    {
410
        return $this->displaysExtra;
411
    }
412
413
    public function setDisplaysExtra(bool $displaysExtra) : self
414
    {
415
        $this->displaysExtra = $displaysExtra;
416
417
        return $this;
418
    }
419
420
    public function getTitleSeparator() : string
421
    {
422
        return $this->titleSeparator;
423
    }
424
425
    public function setTitleSeparator(string $actionSeparator) : self
426
    {
427
        $this->titleSeparator = $actionSeparator;
428
429
        return $this;
430
    }
431
    
432
    /**
433
     * Shorthand function to set all borders values at once
434
     */
435
    public function setBorder(
436
        int $topWidth,
437
        $rightWidth = null,
438
        $bottomWidth = null,
439
        $leftWidth = null,
440
        string $colour = null
441
    ) : self {
442 View Code Duplication
        if (!is_int($rightWidth)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
443
            $colour = $rightWidth;
444
            $rightWidth = $bottomWidth = $leftWidth = $topWidth;
445
        } elseif (!is_int($bottomWidth)) {
446
            $colour = $bottomWidth;
447
            $bottomWidth = $topWidth;
448
            $leftWidth = $rightWidth;
449
        } elseif (!is_int($leftWidth)) {
450
            $colour = $leftWidth;
451
            $leftWidth = $rightWidth;
452
        }
453
454
        $this->borderTopWidth = $topWidth;
455
        $this->borderRightWidth = $rightWidth;
456
        $this->borderBottomWidth = $bottomWidth;
457
        $this->borderLeftWidth = $leftWidth;
458
459
        if (is_string($colour)) {
460
            $this->borderColour = $colour;
461
        }
462
463
        $this->calculateContentWidth();
464
465
        return $this;
466
    }
467
468
    public function setBorderTopWidth(int $width) : self
469
    {
470
        $this->borderTopWidth = $width;
471
472
        return $this;
473
    }
474
475
    public function setBorderRightWidth(int $width) : self
476
    {
477
        $this->borderRightWidth = $width;
478
        $this->calculateContentWidth();
479
480
        return $this;
481
    }
482
483
    public function setBorderBottomWidth(int $width) : self
484
    {
485
        $this->borderBottomWidth = $width;
486
487
        return $this;
488
    }
489
490
    public function setBorderLeftWidth(int $width) : self
491
    {
492
        $this->borderLeftWidth = $width;
493
        $this->calculateContentWidth();
494
495
        return $this;
496
    }
497
498
    public function setBorderColour(string $colour) : self
499
    {
500
        $this->borderColour = $colour;
501
502
        return $this;
503
    }
504
505
    public function getBorderTopWidth() : int
506
    {
507
        return $this->borderTopWidth;
508
    }
509
510
    public function getBorderRightWidth() : int
511
    {
512
        return $this->borderRightWidth;
513
    }
514
515
    public function getBorderBottomWidth() : int
516
    {
517
        return $this->borderBottomWidth;
518
    }
519
520
    public function getBorderLeftWidth() : int
521
    {
522
        return $this->borderLeftWidth;
523
    }
524
525
    public function getBorderColour() : string
526
    {
527
        return $this->borderColour;
528
    }
529
530
    public function getBorderColourCode() : string
531
    {
532
        return sprintf("\033[%sm", self::$availableBackgroundColors[$this->getBorderColour()]['set']);
533
    }
534
}
535