Completed
Push — master ( 2be9b1...e01315 )
by Adam
03:03
created

Element::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Internet\Html;
4
5
use BestServedCold\PhalueObjects\ValueObject;
6
7
class Element extends ValueObject
8
{
9
    /**
10
     * @var array $elements
11
     */
12
    private  $elements = [
13
        'a',
14
        'abbr',
15
        'address',
16
        'area',
17
        'article',
18
        'aside',
19
        'audio',
20
        'b',
21
        'base',
22
        'bdi',
23
        'bdo',
24
        'blockquote',
25
        'body',
26
        'br',
27
        'button',
28
        'canvas',
29
        'caption',
30
        'cite',
31
        'code',
32
        'col',
33
        'colgroup',
34
        'datalist',
35
        'dd',
36
        'del',
37
        'details',
38
        'dfn',
39
        'dialog',
40
        'div',
41
        'dl',
42
        'dt',
43
        'em',
44
        'embed',
45
        'fieldset',
46
        'figcaption',
47
        'figure',
48
        'footer',
49
        'form',
50
        'h1',
51
        'h2',
52
        'h3',
53
        'h4',
54
        'h5',
55
        'h6',
56
        'head',
57
        'header',
58
        'hr',
59
        'html',
60
        'i',
61
        'iframe',
62
        'img',
63
        'input',
64
        'ins',
65
        'kbd',
66
        'keygen',
67
        'label',
68
        'legend',
69
        'li',
70
        'link',
71
        'main',
72
        'map',
73
        'mark',
74
        'menu',
75
        'menuitem',
76
        'meta',
77
        'meter',
78
        'nav',
79
        'noscript',
80
        'object',
81
        'ol',
82
        'optgroup',
83
        'option',
84
        'output',
85
        'p',
86
        'param',
87
        'picture',
88
        'pre',
89
        'progress',
90
        'q',
91
        'rp',
92
        'rt',
93
        'ruby',
94
        's',
95
        'samp',
96
        'script',
97
        'section',
98
        'select',
99
        'small',
100
        'source',
101
        'span',
102
        'strong',
103
        'style',
104
        'sub',
105
        'summary',
106
        'sup',
107
        'table',
108
        'tbody',
109
        'td',
110
        'textarea',
111
        'tfoot',
112
        'th',
113
        'thead',
114
        'time',
115
        'title',
116
        'tr',
117
        'track',
118
        'u',
119
        'ul',
120
        'var',
121
        'video',
122
        'wbr'
123
    ];
124
125
    /**
126
     * @var array $voidElements
127
     */
128
    private  $voidElements = [
129
        'area',
130
        'base',
131
        'br',
132
        'col',
133
        'command',
134
        'embed',
135
        'hr',
136
        'img',
137
        'input',
138
        'keygen',
139
        'link',
140
        'meta',
141
        'param',
142
        'source',
143
        'track',
144
        'wbr'
145
    ];
146
147
    /**
148
     * Element constructor.
149
     * 
150
     * @param $value
151
     */
152
    public function __construct($value)
153
    {
154
        if (! in_array($value, $this->elements)) {
155
            throw new \InvalidArgumentException('[' . $value . '] is not a valid HTML element');
156
        }
157
158
        parent::__construct($value);
159
    }
160
161
    /**
162
     * @return bool
163
     */
164
    public function isVoid()
165
    {
166
        return in_array($this->getValue(), $this->voidElements);
167
    }
168
}
169