Command::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace League\CLImate\Decorator\Component;
4
5
class Command extends BaseDecorator
6
{
7
    /**
8
     * Commands that correspond to a color in the $colors property
9
     *
10
     * @var array
11
     */
12
    public $commands = [];
13
14
    /**
15
     * The default commands available
16
     *
17
     * @var array $defaults
18
     */
19
    protected $defaults = [
20
            'info'    => 'green',
21
            'comment' => 'yellow',
22
            'whisper' => 'light_gray',
23
            'shout'   => 'red',
24
            'error'   => 'light_red',
25
        ];
26
27
    /**
28
     * Add a command into the mix
29
     *
30
     * @param string $key
31
     * @param mixed  $value
32
     */
33 948
    public function add($key, $value)
34
    {
35 948
        $this->commands[$key] = $value;
36 948
    }
37
38
    /**
39
     * Retrieve all of the available commands
40
     *
41
     * @return array
42
     */
43 580
    public function all()
44
    {
45 580
        return $this->commands;
46
    }
47
48
    /**
49
     * Get the style that corresponds to the command
50
     *
51
     * @param  string  $val
52
     *
53
     * @return string
54
     */
55 32
    public function get($val)
56
    {
57 32
        if (array_key_exists($val, $this->commands)) {
58 24
            return $this->commands[$val];
59
        }
60
61 8
        return null;
62
    }
63
64
    /**
65
     * Set the currently used command
66
     *
67
     * @param  string       $val
68
     *
69
     * @return string|false
70
     */
71 24
    public function set($val)
72
    {
73
        // Return the code because it is a string corresponding
74
        // to a property in another class
75 24
        return ($code = $this->get($val)) ? $code : false;
76
    }
77
}
78