Flank::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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