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

Attribute::validForElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

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 4
ccs 0
cts 4
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Internet\Html\Element;
4
5
use BestServedCold\PhalueObjects\ValueObject;
6
7
class Attribute extends ValueObject
8
{
9
    /**
10
     * @var array $global
11
     */
12
    private $global = [
13
        'accesskey',
14
        'class',
15
        'contenteditable',
16
        'contextmenu',
17
        'data',
18
        'dir',
19
        'draggable',
20
        'hidden',
21
        'id',
22
        'is',
23
        'itemid',
24
        'itemprop',
25
        'itemref',
26
        'itemscope',
27
        'itemtype',
28
        'lang',
29
        'onabort',
30
        'onautocomplete',
31
        'onautocompleteerror',
32
        'onblur',
33
        'oncancel',
34
        'oncanplay',
35
        'oncanplaythrough',
36
        'onchange',
37
        'onclick',
38
        'onclose',
39
        'oncontextmenu',
40
        'oncuechange',
41
        'ondblclick',
42
        'ondrag',
43
        'ondragend',
44
        'ondragenter',
45
        'ondragexit',
46
        'ondragleave',
47
        'ondragover',
48
        'ondragstart',
49
        'ondrop',
50
        'ondurationchange',
51
        'onemptied',
52
        'onended',
53
        'onerror',
54
        'onfocus',
55
        'oninput',
56
        'oninvalid',
57
        'onkeydown',
58
        'onkeypress',
59
        'onkeyup',
60
        'onload',
61
        'onloadeddata',
62
        'onloadedmetadata',
63
        'onloadstart',
64
        'onmousedown',
65
        'onmouseenter',
66
        'onmouseleave',
67
        'onmousemove',
68
        'onmouseout',
69
        'onmouseover',
70
        'onmouseup',
71
        'onmousewheel',
72
        'onpause',
73
        'onplay',
74
        'onplaying',
75
        'onprogress',
76
        'onratechange',
77
        'onreset',
78
        'onresize',
79
        'onscroll',
80
        'onseeked',
81
        'onseeking',
82
        'onselect',
83
        'onshow',
84
        'onsort',
85
        'onstalled',
86
        'onsubmit',
87
        'onsuspend',
88
        'ontimeupdate',
89
        'ontoggle',
90
        'onvolumechange',
91
        'onwaiting',
92
        'spellcheck',
93
        'style',
94
        'tabindex',
95
        'title',
96
        'translate',
97
        'xml:lang',
98
        'xml:base'
99
    ];
100
101
    /**
102
     * @var array $elements
103
     */
104
    private $elements = [
105
        'accept'       => [ 'form', 'input' ],
106
        'accesskey'    => [ 'form' ],
107
        'action'       => [ 'form' ],
108
        'align'        => [ 'applet', 'caption', 'col', 'colgroup', 'hr', 'iframe', 'img', 'table', 'tbody', 'td',
109
            'tfoot', 'th', 'thead', 'tr' ],
110
        'alt'          => [ 'applet', 'area', 'img', 'input' ],
111
        'async'        => [ 'script' ],
112
        'autocomplete' => [ 'form', 'input' ],
113
        'autofocus'    => [ 'button', 'input', 'keygen', 'select', 'textarea' ],
114
        'autoplay'     => [ 'audio', 'video' ],
115
        'autosave'     => [ 'input' ],
116
        'bgcolor'      => [ 'body', 'col', 'colgroup', 'table', 'tbody', 'tfoot','td', 'th', 'tr' ],
117
        'border'       => [ 'img', 'object', 'table' ],
118
        'buffered'     => [ 'audio', 'video' ],
119
        'challenge'    => [ 'keygen' ],
120
        'charset'      => [ 'meta', 'script' ],
121
        'checked'      => [ 'command', 'input' ],
122
        'cite'         => [ 'blockquote', 'del', 'ins', 'q' ],
123
        'code'         => [ 'applet' ],
124
        'codebase'     => [ 'applet' ],
125
        'color'        => [ 'basefont', 'font', 'hr' ],
126
        'cols'         => [ 'textarea' ],
127
        'colspan'      => [ 'td', 'th' ],
128
        'content'      => [ 'meta' ],
129
        'controls'     => [ 'audio', 'video' ],
130
        'coords'       => [ 'area' ],
131
        'data'         => [ 'object' ],
132
        'datetime'     => [ 'del', 'ins', 'time' ],
133
        'default'      => [ 'track' ],
134
        'defer'        => [ 'script' ],
135
        'dirname'      => [ 'input', 'textarea' ],
136
        'disabled'     => [ 'button', 'command', 'fieldset', 'input', 'keygen', 'optgroup', 'option', 'select',
137
            'textearea' ],
138
        'download'     => [ 'a', 'area' ],
139
        'enctype'      => [ 'form' ],
140
        'for'          => [ 'label', 'output' ],
141
        'form'         => [ 'button', 'fieldset', 'input', 'keygen', 'label', 'meter', 'object', 'output', 'prgress',
142
            'select', 'textarea' ],
143
        'formaction'   => [ 'input', 'button' ],
144
        'headers'      => [ 'td', 'th' ],
145
        'height'       => [ 'canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video' ],
146
        'high'         => [ 'meter' ],
147
        'href'         => [ 'a', 'area', 'base', 'link' ],
148
        'hreflang'     => [ 'a', 'area', 'link' ],
149
        'http-equiv'   => [ 'meta' ],
150
        'icon'         => [ 'command' ],
151
        'integrity'    => [ 'link', 'script' ],
152
        'ismap'        => [ 'img' ],
153
        'keytype'      => [ 'keygen' ],
154
        'kind'         => [ 'track' ],
155
        'label'        => [ 'track' ],
156
        'lang'         => [ 'track' ],
157
        'language'     => [ 'script' ],
158
        'list'         => [ 'input' ],
159
        'loop'         => [ 'audio', 'bgsound', 'video' ],
160
        'low'          => [ 'meter' ],
161
        'manifest'     => [ 'html' ],
162
        'max'          => [ 'input', 'meter', 'progress' ],
163
        'maxlength'    => [ 'input', 'textarea' ],
164
        'media'        => [ 'a', 'area', 'link', 'source', 'style' ],
165
        'method'       => [ 'form' ],
166
        'min'          => [ 'input', 'meter' ],
167
        'multiple'     => [ 'input', 'select' ],
168
        'muted'        => [ 'video' ],
169
        'name'         => [ 'button', 'form', 'fieldset', 'iframe', 'input', 'keygen', 'object', 'output', 'select',
170
            'textarea', 'map', 'meta', 'param' ],
171
        'novalidate'   => [ 'form' ],
172
        'open'         => [ 'details' ],
173
        'optimum'      => [ 'meter' ],
174
        'pattern'      => [ 'input' ],
175
        'ping'         => [ 'a', 'area' ],
176
        'placeholder'  => [ 'input', 'textarea' ],
177
        'poster'       => [ 'video' ],
178
        'preload'      => [ 'audio', 'video' ],
179
        'radiogroup'   => [ 'command' ],
180
        'readonly'     => [ 'input', 'textarea' ],
181
        'rel'          => [ 'a', 'area', 'link' ],
182
        'required'     => [ 'input', 'select', 'textarea' ],
183
        'reversed'     => [ 'ol' ],
184
        'rows'         => [ 'textarea' ],
185
        'rowspan'      => [ 'td', 'th' ],
186
        'sandbox'      => [ 'iframe' ],
187
        'scope'        => [ 'th' ],
188
        'scoped'       => [ 'style' ],
189
        'seamless'     => [ 'iframe' ],
190
        'selected'     => [ 'option' ],
191
        'shape'        => [ 'a', 'area' ],
192
        'size'         => [ 'input', 'select' ],
193
        'sizes'        => [ 'link', 'img', 'source' ],
194
        'span'         => [ 'col', 'colgroup' ],
195
        'src'          => [ 'audio', 'embed', 'iframe', 'img', 'input', 'script', 'source', 'track', 'video' ],
196
        'srcdoc'       => [ 'iframe' ],
197
        'srclang'      => [ 'track' ],
198
        'srcset'       => [ 'img' ],
199
        'start'        => [ 'ol' ],
200
        'step'         => [ 'input' ],
201
        'summary'      => [ 'table' ],
202
        'target'       => [ 'a', 'area', 'base', 'form' ],
203
        'type'         => [ 'button', 'input', 'command', 'embed', 'object', 'script', 'source', 'style', 'menu' ],
204
        'usemap'       => [ 'img', 'input', 'object' ],
205
        'value'        => [ 'button', 'option', 'input', 'li', 'meter', 'progress', 'param' ],
206
        'width'        => [ 'canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video' ],
207
        'wrap'         => [ 'textarea' ]
208
    ];
209
210
    /**
211
     * Attribute constructor.
212
     * 
213
     * @param $value
214
     */
215
    public function __construct($value)
216
    {
217
        if (! in_array($value, array_merge($this->global, array_keys($this->elements)))) {
218
            throw new \InvalidArgumentException('[' . $value . '] is not a valid HTML Attribute');
219
        }
220
221
        parent::__construct($value);
222
    }
223
224
    /**
225
     * @param  $element
226
     * @return bool
227
     */
228
    public function validForElement($element)
0 ignored issues
show
Coding Style introduced by
function validForElement() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
229
    {
230
        return in_array($element, $this->global) || in_array($element, $this->elements[ $element ]);
231
    }
232
}
233