BorderStyle::ascii()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 19

Duplication

Lines 23
Ratio 100 %

Code Coverage

Tests 19
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 23
loc 23
ccs 19
cts 19
cp 1
rs 9.0856
cc 2
eloc 19
nc 2
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the webmozart/console package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\Console\UI\Style;
13
14
use Webmozart\Console\Api\Formatter\Style;
15
16
/**
17
 * Defines the style of a border.
18
 *
19
 * Use {@link none()}, {@link ascii()} or {@link solid()} to obtain predefined
20
 * border styles.
21
 *
22
 * @since  1.0
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 */
26
class BorderStyle
27
{
28
    /**
29
     * @var BorderStyle
30
     */
31
    private static $none;
32
33
    /**
34
     * @var BorderStyle
35
     */
36
    private static $ascii;
37
38
    /**
39
     * @var BorderStyle
40
     */
41
    private static $solid;
42
43
    /**
44
     * @var string
45
     */
46
    private $lineHTChar = '-';
47
48
    /**
49
     * @var string
50
     */
51
    private $lineHCChar = '-';
52
53
    /**
54
     * @var string
55
     */
56
    private $lineHBChar = '-';
57
58
    /**
59
     * @var string
60
     */
61
    private $lineVLChar = '|';
62
63
    /**
64
     * @var string
65
     */
66
    private $lineVCChar = '|';
67
68
    /**
69
     * @var string
70
     */
71
    private $lineVRChar = '|';
72
73
    /**
74
     * @var string
75
     */
76
    private $cornerTLChar = '+';
77
78
    /**
79
     * @var string
80
     */
81
    private $cornerTRChar = '+';
82
83
    /**
84
     * @var string
85
     */
86
    private $cornerBLChar = '+';
87
88
    /**
89
     * @var string
90
     */
91
    private $cornerBRChar = '+';
92
93
    /**
94
     * @var string
95
     */
96
    private $crossingCChar = '+';
97
98
    /**
99
     * @var string
100
     */
101
    private $crossingLChar = '+';
102
103
    /**
104
     * @var string
105
     */
106
    private $crossingRChar = '+';
107
108
    /**
109
     * @var string
110
     */
111
    private $crossingTChar = '+';
112
113
    /**
114
     * @var string
115
     */
116
    private $crossingBChar = '+';
117
118
    /**
119
     * @var Style
120
     */
121
    private $style;
122
123
    /**
124
     * A borderless style.
125
     *
126
     * @return BorderStyle The style.
127
     */
128 2 View Code Duplication
    public static function none()
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...
129
    {
130 2
        if (!self::$none) {
131 1
            self::$none = new static();
132 1
            self::$none->lineVLChar = '';
133 1
            self::$none->lineVCChar = ' ';
134 1
            self::$none->lineVRChar = '';
135 1
            self::$none->lineHTChar = '';
136 1
            self::$none->lineHCChar = '';
137 1
            self::$none->lineHBChar = '';
138 1
            self::$none->cornerTLChar = '';
139 1
            self::$none->cornerTRChar = '';
140 1
            self::$none->cornerBLChar = '';
141 1
            self::$none->cornerBRChar = '';
142 1
            self::$none->crossingCChar = '';
143 1
            self::$none->crossingLChar = '';
144 1
            self::$none->crossingRChar = '';
145 1
            self::$none->crossingTChar = '';
146 1
            self::$none->crossingBChar = '';
147
        }
148
149 2
        return clone self::$none;
150
    }
151
152
    /**
153
     * A style that uses ASCII characters only.
154
     *
155
     * @return BorderStyle The style.
156
     */
157 2 View Code Duplication
    public static function ascii()
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...
158
    {
159 2
        if (!self::$ascii) {
160 1
            self::$ascii = new static();
161 1
            self::$ascii->lineVLChar = '|';
162 1
            self::$ascii->lineVCChar = '|';
163 1
            self::$ascii->lineVRChar = '|';
164 1
            self::$ascii->lineHTChar = '-';
165 1
            self::$ascii->lineHCChar = '-';
166 1
            self::$ascii->lineHBChar = '-';
167 1
            self::$ascii->cornerTLChar = '+';
168 1
            self::$ascii->cornerTRChar = '+';
169 1
            self::$ascii->cornerBLChar = '+';
170 1
            self::$ascii->cornerBRChar = '+';
171 1
            self::$ascii->crossingCChar = '+';
172 1
            self::$ascii->crossingLChar = '+';
173 1
            self::$ascii->crossingRChar = '+';
174 1
            self::$ascii->crossingTChar = '+';
175 1
            self::$ascii->crossingBChar = '+';
176
        }
177
178 2
        return clone self::$ascii;
179
    }
180
181
    /**
182
     * A style that uses Unicode characters to draw solid lines.
183
     *
184
     * @return BorderStyle The style.
185
     */
186 2 View Code Duplication
    public static function solid()
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...
187
    {
188 2
        if (!self::$solid) {
189 1
            self::$solid = new static();
190 1
            self::$solid->lineVLChar = '│';
191 1
            self::$solid->lineVCChar = '│';
192 1
            self::$solid->lineVRChar = '│';
193 1
            self::$solid->lineHTChar = '─';
194 1
            self::$solid->lineHCChar = '─';
195 1
            self::$solid->lineHBChar = '─';
196 1
            self::$solid->cornerTLChar = '┌';
197 1
            self::$solid->cornerTRChar = '┐';
198 1
            self::$solid->cornerBLChar = '└';
199 1
            self::$solid->cornerBRChar = '┘';
200 1
            self::$solid->crossingCChar = '┼';
201 1
            self::$solid->crossingLChar = '├';
202 1
            self::$solid->crossingRChar = '┤';
203 1
            self::$solid->crossingTChar = '┬';
204 1
            self::$solid->crossingBChar = '┴';
205
        }
206
207 2
        return clone self::$solid;
208
    }
209
210
    /**
211
     * Returns the character used to draw a horizontal line at the top.
212
     *
213
     * @return string The line character.
214
     */
215 21
    public function getLineHTChar()
216
    {
217 21
        return $this->lineHTChar;
218
    }
219
220
    /**
221
     * Sets the character used to draw a horizontal line at the top.
222
     *
223
     * @param string $char The line character.
224
     *
225
     * @return static The current instance.
226
     */
227
    public function setLineHTChar($char)
228
    {
229
        $this->lineHTChar = $char;
230
231
        return $this;
232
    }
233
234
    /**
235
     * Returns the character used to draw a horizontal line at the center.
236
     *
237
     * @return string The line character.
238
     */
239 20
    public function getLineHCChar()
240
    {
241 20
        return $this->lineHCChar;
242
    }
243
244
    /**
245
     * Sets the character used to draw a horizontal line at the center.
246
     *
247
     * @param string $char The line character.
248
     *
249
     * @return static The current instance.
250
     */
251 1
    public function setLineHCChar($char)
252
    {
253 1
        $this->lineHCChar = $char;
254
255 1
        return $this;
256
    }
257
258
    /**
259
     * Returns the character used to draw a horizontal line at the bottom.
260
     *
261
     * @return string The line character.
262
     */
263 21
    public function getLineHBChar()
264
    {
265 21
        return $this->lineHBChar;
266
    }
267
268
    /**
269
     * Sets the character used to draw a horizontal line at the bottom.
270
     *
271
     * @param string $char The line character.
272
     *
273
     * @return static The current instance.
274
     */
275
    public function setLineHBChar($char)
276
    {
277
        $this->lineHBChar = $char;
278
279
        return $this;
280
    }
281
282
    /**
283
     * Returns the character used to draw a vertical line on the left.
284
     *
285
     * @return string The line character.
286
     */
287 21
    public function getLineVLChar()
288
    {
289 21
        return $this->lineVLChar;
290
    }
291
292
    /**
293
     * Sets the character used to draw a vertical line on the left.
294
     *
295
     * @param string $char The line character.
296
     *
297
     * @return static The current instance.
298
     */
299
    public function setLineVLChar($char)
300
    {
301
        $this->lineVLChar = $char;
302
303
        return $this;
304
    }
305
306
    /**
307
     * Returns the character used to draw a vertical line in the middle.
308
     *
309
     * @return string The line character.
310
     */
311 21
    public function getLineVCChar()
312
    {
313 21
        return $this->lineVCChar;
314
    }
315
316
    /**
317
     * Sets the character used to draw a vertical line in the middle.
318
     *
319
     * @param string $char The line character.
320
     *
321
     * @return static The current instance.
322
     */
323 1
    public function setLineVCChar($char)
324
    {
325 1
        $this->lineVCChar = $char;
326
327 1
        return $this;
328
    }
329
330
    /**
331
     * Returns the character used to draw a vertical line on the right.
332
     *
333
     * @return string The line character.
334
     */
335 21
    public function getLineVRChar()
336
    {
337 21
        return $this->lineVRChar;
338
    }
339
340
    /**
341
     * Sets the character used to draw a vertical line on the right.
342
     *
343
     * @param string $char The line character.
344
     *
345
     * @return static The current instance.
346
     */
347
    public function setLineVRChar($char)
348
    {
349
        $this->lineVRChar = $char;
350
351
        return $this;
352
    }
353
354
    /**
355
     * Returns the character used to draw a corner on the top left.
356
     *
357
     * @return string The corner character.
358
     */
359 21
    public function getCornerTLChar()
360
    {
361 21
        return $this->cornerTLChar;
362
    }
363
364
    /**
365
     * Sets the character used to draw a corner on the top left.
366
     *
367
     * @param string $char The corner character.
368
     *
369
     * @return static The current instance.
370
     */
371
    public function setCornerTLChar($char)
372
    {
373
        $this->cornerTLChar = $char;
374
375
        return $this;
376
    }
377
378
    /**
379
     * Returns the character used to draw a corner on the top right.
380
     *
381
     * @return string The corner character.
382
     */
383 21
    public function getCornerTRChar()
384
    {
385 21
        return $this->cornerTRChar;
386
    }
387
388
    /**
389
     * Sets the character used to draw a corner on the top right.
390
     *
391
     * @param string $char The corner character.
392
     *
393
     * @return static The current instance.
394
     */
395
    public function setCornerTRChar($char)
396
    {
397
        $this->cornerTRChar = $char;
398
399
        return $this;
400
    }
401
402
    /**
403
     * Returns the character used to draw a corner on the bottom left.
404
     *
405
     * @return string The corner character.
406
     */
407 21
    public function getCornerBLChar()
408
    {
409 21
        return $this->cornerBLChar;
410
    }
411
412
    /**
413
     * Sets the character used to draw a corner on the bottom left.
414
     *
415
     * @param string $char The corner character.
416
     *
417
     * @return static The current instance.
418
     */
419
    public function setCornerBLChar($char)
420
    {
421
        $this->cornerBLChar = $char;
422
423
        return $this;
424
    }
425
426
    /**
427
     * Returns the character used to draw a corner on the bottom right.
428
     *
429
     * @return string The corner character.
430
     */
431 21
    public function getCornerBRChar()
432
    {
433 21
        return $this->cornerBRChar;
434
    }
435
436
    /**
437
     * Sets the character used to draw a corner on the bottom right.
438
     *
439
     * @param string $char The corner character.
440
     *
441
     * @return static The current instance.
442
     */
443
    public function setCornerBRChar($char)
444
    {
445
        $this->cornerBRChar = $char;
446
447
        return $this;
448
    }
449
450
    /**
451
     * Returns the character used to draw a crossing at the center.
452
     *
453
     * @return string The crossing character.
454
     */
455 20
    public function getCrossingCChar()
456
    {
457 20
        return $this->crossingCChar;
458
    }
459
460
    /**
461
     * Sets the character used to draw a crossing at the center.
462
     *
463
     * @param string $char The crossing character.
464
     *
465
     * @return static The current instance.
466
     */
467 1
    public function setCrossingCChar($char)
468
    {
469 1
        $this->crossingCChar = $char;
470
471 1
        return $this;
472
    }
473
474
    /**
475
     * Returns the character used to draw a crossing on the left.
476
     *
477
     * @return string The crossing character.
478
     */
479 20
    public function getCrossingLChar()
480
    {
481 20
        return $this->crossingLChar;
482
    }
483
484
    /**
485
     * Sets the character used to draw a crossing on the left.
486
     *
487
     * @param string $char The crossing character.
488
     *
489
     * @return static The current instance.
490
     */
491
    public function setCrossingLChar($char)
492
    {
493
        $this->crossingLChar = $char;
494
495
        return $this;
496
    }
497
498
    /**
499
     * Returns the character used to draw a crossing on the right.
500
     *
501
     * @return string The crossing character.
502
     */
503 20
    public function getCrossingRChar()
504
    {
505 20
        return $this->crossingRChar;
506
    }
507
508
    /**
509
     * Sets the character used to draw a crossing on the right.
510
     *
511
     * @param string $char The crossing character.
512
     *
513
     * @return static The current instance.
514
     */
515
    public function setCrossingRChar($char)
516
    {
517
        $this->crossingRChar = $char;
518
519
        return $this;
520
    }
521
522
    /**
523
     * Returns the character used to draw a crossing at the top.
524
     *
525
     * @return string The crossing character.
526
     */
527 21
    public function getCrossingTChar()
528
    {
529 21
        return $this->crossingTChar;
530
    }
531
532
    /**
533
     * Sets the character used to draw a crossing at the top.
534
     *
535
     * @param string $char The crossing character.
536
     *
537
     * @return static The current instance.
538
     */
539
    public function setCrossingTChar($char)
540
    {
541
        $this->crossingTChar = $char;
542
543
        return $this;
544
    }
545
546
    /**
547
     * Returns the character used to draw a crossing at the bottom.
548
     *
549
     * @return string The crossing character.
550
     */
551 21
    public function getCrossingBChar()
552
    {
553 21
        return $this->crossingBChar;
554
    }
555
556
    /**
557
     * Sets the character used to draw a crossing at the bottom.
558
     *
559
     * @param string $char The crossing character.
560
     *
561
     * @return static The current instance.
562
     */
563
    public function setCrossingBChar($char)
564
    {
565
        $this->crossingBChar = $char;
566
567
        return $this;
568
    }
569
570
    /**
571
     * Returns the border style.
572
     *
573
     * @return Style The border style.
574
     */
575 21
    public function getStyle()
576
    {
577 21
        return $this->style;
578
    }
579
580
    /**
581
     * Sets the border style.
582
     *
583
     * @param Style $style The border style.
584
     *
585
     * @return static The current instance.
586
     */
587
    public function setStyle(Style $style)
588
    {
589
        $this->style = $style;
590
591
        return $this;
592
    }
593
}
594