Background   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 57
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSymbol() 0 7 2
A isValid() 0 5 1
1
<?php declare(strict_types = 1);
2
3
4
namespace Console\Modifier;
5
6
7
class Background extends Modifier
8
{
9
    public const BLACK      = 'black';
10
11
    public const RED        = 'red';
12
13
    public const GREEN      = 'green';
14
15
    public const YELLOW     = 'yellow';
16
17
    public const BLUE       = 'blue';
18
19
    public const MAGENTA    = 'magenta';
20
21
    public const CYAN       = 'cyan';
22
23
    public const LIGHT_GRAY = 'light_gray';
24
25
    public static $background_colors = [
26
        self::BLACK      => '40',
27
        self::RED        => '41',
28
        self::GREEN      => '42',
29
        self::YELLOW     => '43',
30
        self::BLUE       => '44',
31
        self::MAGENTA    => '45',
32
        self::CYAN       => '46',
33
        self::LIGHT_GRAY => '47',
34
    ];
35
36
    /**
37
     * Returns specific symbol for output modification in console
38
     *
39
     * @param string $color
40
     *
41
     * @return string|null
42
     */
43
    public static function getSymbol(string $color): ?string
44
    {
45
        if (self::isValid($color)) {
46
            return self::$background_colors[$color];
47
        }
48
49
        return null;
50
    }
51
52
    /**
53
     * Method validates whether ot not color is valid
54
     *
55
     * @param string $color
56
     *
57
     * @return bool
58
     */
59
    public static function isValid(string $color): bool
60
    {
61
        $constants = self::getAll(__CLASS__);
62
63
        return \in_array($color, $constants, true);
64
    }
65
}