Style   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 19
dl 0
loc 59
ccs 0
cts 22
cp 0
rs 10
c 2
b 0
f 1
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 5 1
A tokenize() 0 12 2
A contains() 0 3 1
A parse() 0 9 2
A remove() 0 5 1
A get() 0 3 1
1
<?php
2
3
namespace WebTheory\Html\Attributes;
4
5
use WebTheory\Html\Contracts\HtmlAttributeInterface;
6
7
class Style extends AbstractHtmlAttribute implements HtmlAttributeInterface
8
{
9
    protected string $name = 'style';
10
11
    protected array $value = [];
12
13
    /**
14
     * @return $this
15
     */
16
    public function set($style, $value): Style
17
    {
18
        $this->value[$style] = $value;
19
20
        return $this;
21
    }
22
23
    public function get($style)
24
    {
25
        return $this->value[$style];
26
    }
27
28
    /**
29
     * @return $this
30
     */
31
    public function remove($style): Style
32
    {
33
        unset($this->value[$style]);
34
35
        return $this;
36
    }
37
38
    public function contains($style): bool
39
    {
40
        return isset($this->value[$style]);
41
    }
42
43
    public function parse(): string
44
    {
45
        $str = '';
46
47
        foreach ($this->value as $style => $value) {
48
            $str .= "{$style}: {$value}; ";
49
        }
50
51
        return rtrim($str, ' ');
52
    }
53
54
    public function tokenize(string $styles): array
55
    {
56
        $styles = explode(';', $styles);
57
        $value = [];
58
59
        foreach ($styles as $style) {
60
            $style = explode(':', $style);
61
62
            $value[ltrim($style[0])] = ltrim($style[1]);
63
        }
64
65
        return $value;
66
    }
67
}
68