Color   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 7

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 96
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A all() 0 4 1
A get() 0 13 3
A set() 0 12 2
1
<?php
2
3
namespace League\CLImate\Decorator\Component;
4
5
class Color extends BaseDecorator
6
{
7
    /**
8
     * The available colors
9
     *
10
     * @var array
11
     */
12
    protected $colors = [];
13
14
    /**
15
     * An array of default colors
16
     *
17
     * @var array $defaults
18
     */
19
    protected $defaults = [
20
            'default'       => 39,
21
            'black'         => 30,
22
            'red'           => 31,
23
            'green'         => 32,
24
            'yellow'        => 33,
25
            'blue'          => 34,
26
            'magenta'       => 35,
27
            'cyan'          => 36,
28
            'light_gray'    => 37,
29
            'dark_gray'     => 90,
30
            'light_red'     => 91,
31
            'light_green'   => 92,
32
            'light_yellow'  => 93,
33
            'light_blue'    => 94,
34
            'light_magenta' => 95,
35
            'light_cyan'    => 96,
36
            'white'         => 97,
37
        ];
38
39
    /**
40
     * Add a color into the mix
41
     *
42
     * @param string  $key
43
     * @param integer $value
44
     */
45 948
    public function add($key, $value)
46
    {
47 948
        $this->colors[$key] = (int) $value;
48 948
    }
49
50
    /**
51
     * Retrieve all of available colors
52
     *
53
     * @return array
54
     */
55 576
    public function all()
56
    {
57 576
        return $this->colors;
58
    }
59
60
    /**
61
     * Get the code for the color
62
     *
63
     * @param  string  $val
64
     *
65
     * @return string
66
     */
67 576
    public function get($val)
68
    {
69
        // If we already have the code, just return that
70 576
        if (is_numeric($val)) {
71
            return $val;
72
        }
73
74 576
        if (array_key_exists($val, $this->colors)) {
75 576
            return $this->colors[$val];
76
        }
77
78 56
        return null;
79
    }
80
81
    /**
82
     * Set the current color
83
     *
84
     * @param  string   $val
85
     *
86
     * @return boolean
87
     */
88 92
    public function set($val)
89
    {
90 92
        $code = $this->get($val);
91
92 92
        if ($code) {
93 92
            $this->current = [$code];
94
95 92
            return true;
96
        }
97
98 52
        return false;
99
    }
100
}
101