Border::result()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3
1
<?php
2
3
namespace League\CLImate\TerminalObject\Basic;
4
5
class Border extends BasicTerminalObject
6
{
7
    /**
8
     * The character to repeat for the border
9
     *
10
     * @var string $char
11
     */
12
    protected $char = '-';
13
14
    /**
15
     * The length of the border
16
     *
17
     * @var integer $length
18
     */
19
    protected $length;
20
21 44
    public function __construct($char = null, $length = null)
22
    {
23 44
        $this->char($char)->length($length);
24 44
    }
25
26
    /**
27
     * Set the character to repeat for the border
28
     *
29
     * @param string $char
30
     *
31
     * @return Border
32
     */
33 44
    public function char($char)
34
    {
35 44
        $this->set('char', $char);
36
37 44
        return $this;
38
    }
39
40
    /**
41
     * Set the length of the border
42
     *
43
     * @param integer $length
44
     *
45
     * @return Border
46
     */
47 44
    public function length($length)
48
    {
49 44
        $this->set('length', $length);
50
51 44
        return $this;
52
    }
53
54
    /**
55
     * Return the border
56
     *
57
     * @return string
58
     */
59 44
    public function result()
60
    {
61 44
        $length = $this->length ?: $this->util->width() ?: 100;
62 44
        $str    = str_repeat($this->char, $length);
63 44
        $str    = substr($str, 0, $length);
64
65 44
        return $str;
66
    }
67
}
68