Format::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace League\CLImate\Decorator\Component;
4
5
class Format extends BaseDecorator
6
{
7
    /**
8
     * The available formatting options
9
     *
10
     * @var array
11
     */
12
    protected $formats = [];
13
14
    /**
15
     * An array of default formats
16
     *
17
     * @var array $defaults
18
     */
19
    protected $defaults = [
20
            'bold'          => 1,
21
            'dim'           => 2,
22
            'underline'     => 4,
23
            'blink'         => 5,
24
            'invert'        => 7,
25
            'hidden'        => 8,
26
        ];
27
28
    /**
29
     * Add a format into the mix
30
     *
31
     * @param string $key
32
     * @param mixed  $value
33
     */
34 948
    public function add($key, $value)
35
    {
36 948
        $this->formats[$key] = (int) $value;
37 948
    }
38
39
    /**
40
     * Retrieve all of the available formats
41
     *
42
     * @return array
43
     */
44 576
    public function all()
45
    {
46 576
        return $this->formats;
47
    }
48
49
    /**
50
     * Get the code for the format
51
     *
52
     * @param  string  $val
53
     *
54
     * @return string
55
     */
56 576
    public function get($val)
57
    {
58
        // If we already have the code, just return that
59 576
        if (is_numeric($val)) {
60
            return $val;
61
        }
62
63 576
        if (array_key_exists($val, $this->formats)) {
64 36
            return $this->formats[$val];
65
        }
66
67 576
        return null;
68
    }
69
70
    /**
71
     * Set the current format
72
     *
73
     * @param  string $val
74
     *
75
     * @return boolean
76
     */
77 112
    public function set($val)
78
    {
79 112
        $code = $this->get($val);
80
81 112
        if ($code) {
82 32
            $this->current[] = $code;
83
84 32
            return true;
85
        }
86
87 92
        return false;
88
    }
89
}
90