Completed
Pull Request — master (#15)
by Mathieu
16:37 queued 14:28
created

Console::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 16
ccs 0
cts 11
cp 0
crap 12
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Suricate;
6
7
class Console
8
{
9
    /** @var Suricate */
10
    private $app;
11
12
    /** @var array */
13
    private $args;
14
15
    public function __construct(Suricate $app, array $args)
16
    {
17
        $this->app = $app;
18
        $this->args = $args;
19
        array_shift($this->args);
20
    }
21
22
    public function execute()
23
    {
24
        $command = $this->args[0] ?: '';
25
26
        switch ($command) {
27
            case 'route':
28
                $command = new Console\Route($this->app);
29
                $retval = $command->execute();
30
                break;
31
            default:
32
                echo "Unknown command";
33
                $retval = 1;
34
                break;
35
        }
36
37
        return $retval;
38
    }
39
40
    public static function coloredString(string $string, $color)
41
    {
42
        $availableColors = [
43
            'black' => '0;30',
44
            'dark_gray' => '1;30',
45
            'blue' => '0;34',
46
            'light_blue' => '1;34',
47
            'green' => '0;32',
48
            'light_green' => '1;32',
49
            'cyan' => '0;36',
50
            'light_cyan' => '1;36',
51
            'red' => '0;31',
52
            'light_red' => '1;31',
53
            'purple' => '0;35',
54
            'light_purple' => '1;35',
55
            'brown' => '0;33',
56
            'yellow' => '1;33',
57
            'light_gray' => '0;37',
58
            'white' => '1;37'
59
        ];
60
        $shellColor = $availableColors[$color] ?: $availableColors['white'];
61
62
        return sprintf("\033[%sm%s\033[0m", $shellColor, $string);
63
    }
64
}
65