BackgroundColor::all()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace League\CLImate\Decorator\Component;
4
5
class BackgroundColor extends Color
6
{
7
    /**
8
     * The difference to add to a foreground color code
9
     * to get a background color code
10
     *
11
     * @const integer ADD
12
     */
13
    const ADD = 10;
14
15
    /**
16
     * Get the code for the requested color
17
     *
18
     * @param  mixed $val
19
     *
20
     * @return mixed
21
     */
22 56
    public function get($val)
23
    {
24 56
        $color = parent::get($this->strip($val));
25
26 56
        if ($color) {
27 44
            $color += self::ADD;
28 44
        }
29
30 56
        return $color;
31
    }
32
33
    /**
34
     * Set the current background color
35
     *
36
     * @param  mixed   $val
37
     *
38
     * @return boolean
39
     */
40 52
    public function set($val)
41
    {
42 52
        return parent::set($this->strip($val));
43
    }
44
45
    /**
46
     * Get all of the available background colors
47
     *
48
     * @return array
49
     */
50 576
    public function all()
51
    {
52 576
        $colors = [];
53
54 576
        foreach ($this->colors as $color => $code) {
55 576
            $colors['background_' . $color] = $code + self::ADD;
56 576
        }
57
58 576
        return $colors;
59
    }
60
61
    /**
62
     * Strip the color of any prefixes
63
     *
64
     * @param  string $val
65
     *
66
     * @return string
67
     */
68 56
    protected function strip($val)
69
    {
70 56
        return str_replace('background_', '', $val);
71
    }
72
}
73