Passed
Push — master ( f31d6e...f89447 )
by Timm
01:52
created

App::echo()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Stefaminator\Cli;
5
6
7
abstract class App {
8
9
    public const EOL = "\n";
10
11
    /**
12
     * @return Cmd
13
     */
14
    abstract public function setup(): Cmd;
15
16 1
    public static function eol(): void {
17 1
        echo self::EOL;
18 1
    }
19
20 1
    public static function echo(string $str, ?string $foreground_color = null): void {
21
22 1
        $lines = preg_split("/\r\n|\n|\r/", $str);
23
24 1
        $output = [];
25 1
        foreach ($lines as $line) {
26 1
            if ($foreground_color !== null) {
27 1
                $line = Color::getColoredString($line, $foreground_color);
28
            }
29 1
            $output[] = $line;
30
        }
31
32 1
        echo implode(self::EOL, $output);
33 1
    }
34
35
36
}