Tags   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 72
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A all() 0 4 1
A value() 0 4 2
A regex() 0 4 1
A build() 0 8 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