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

Console   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 56
ccs 0
cts 20
cp 0
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 16 3
A coloredString() 0 23 2
A __construct() 0 5 1
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