Attribute   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 230
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 230
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

2 Methods

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