Total Complexity | 9 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | final class Line |
||
8 | { |
||
9 | protected int $padding; |
||
10 | |||
11 | protected string $outPad; |
||
12 | protected string $outMessage; |
||
13 | |||
14 | protected bool $showResult; |
||
15 | |||
16 | public function __construct() |
||
17 | { |
||
18 | $this->showResult = false; |
||
19 | $this->padding = 0; |
||
20 | } |
||
21 | |||
22 | public function setShowResult(bool $showResult): bool |
||
26 | } |
||
27 | |||
28 | public function prefix(string $message = ''): string |
||
36 | } |
||
37 | |||
38 | public function suffix(bool $result = true): string |
||
39 | { |
||
40 | $totalLen = \strlen($this->outPad . $this->outMessage); |
||
41 | $output = null; |
||
42 | |||
43 | //overwrite current line |
||
44 | $output .= "\033[" . $totalLen . 'D'; |
||
45 | $output .= \str_repeat(' ', $this->padding); |
||
46 | $output .= $this->outMessage; |
||
47 | |||
48 | $padLen = 74 - $totalLen; |
||
49 | if (0 < $padLen) { |
||
50 | $output .= \str_repeat(' ', $padLen); |
||
51 | } |
||
52 | if ($this->showResult) { |
||
53 | $output .= '['; |
||
54 | $output .= $result |
||
55 | ? "\e[32mOK" |
||
56 | : "\e[31mKO"; |
||
57 | $output .= "\e[0m" . ']'; |
||
58 | } |
||
59 | |||
60 | $output .= "\r"; |
||
61 | |||
62 | return $output; |
||
63 | } |
||
64 | |||
65 | public function finish(): string |
||
68 | } |
||
69 | } |
||
70 |