Tags::value()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace League\CLImate\Decorator;
4
5
class Tags
6
{
7
    /**
8
     * Original keys passed in to build tags
9
     *
10
     * @var array $tags
11
     */
12
13
    protected $keys = [];
14
15
    /**
16
     * Available tags and their values
17
     *
18
     * @var array $tags
19
     */
20
21
    protected $tags = [];
22
23 580
    public function __construct(array $keys)
24
    {
25 580
        $this->keys = $keys;
26 580
        $this->build();
27 580
    }
28
29
    /**
30
     * Get all available tags
31
     *
32
     * @return array
33
     */
34
35 104
    public function all()
36
    {
37 104
        return $this->tags;
38
    }
39
40
    /**
41
     * Get the value of the requested tag
42
     *
43
     * @param string $key
44
     *
45
     * @return string|null
46
     */
47
48 72
    public function value($key)
49
    {
50 72
        return (array_key_exists($key, $this->tags)) ? $this->tags[$key] : null;
51
    }
52
53
    /**
54
     * Get the regular expression that can be used to parse the string for tags
55
     *
56
     * @return string
57
     */
58
59 564
    public function regex()
60
    {
61 564
        return '(<(?:(?:(?:\\\)*\/)*(?:' . implode('|', array_keys($this->keys)) . '))>)';
62
    }
63
64
    /**
65
     * Build the search and replace for all of the various style tags
66
     */
67
68 580
    protected function build()
69
    {
70 580
        foreach ($this->keys as $tag => $code) {
71 576
            $this->tags["<{$tag}>"]    = $code;
72 576
            $this->tags["</{$tag}>"]   = $code;
73 576
            $this->tags["<\\/{$tag}>"] = $code;
74 580
        }
75 580
    }
76
}
77