BackgroundColor   A
last analyzed

↳ Parent: Project

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 68
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 2
A set() 0 4 1
A all() 0 10 2
A strip() 0 4 1
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 560
    public function all()
51
    {
52 560
        $colors = [];
53
54 560
        foreach ($this->colors as $color => $code) {
55 560
            $colors['background_' . $color] = $code + self::ADD;
56 560
        }
57
58 560
        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