1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Tokens\Attribute; |
6
|
|
|
use Groundskeeper\Tokens\Element; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
8
|
|
|
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting; |
9
|
|
|
use Groundskeeper\Tokens\NonParticipating; |
10
|
|
|
use Psr\Log\LoggerInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* "optgroup" element |
14
|
|
|
* |
15
|
|
|
* https://html.spec.whatwg.org/multipage/forms.html#the-optgroup-element |
16
|
|
|
*/ |
17
|
|
|
class Optgroup extends OpenElement |
18
|
|
|
{ |
19
|
|
|
protected function getAllowedAttributes() |
20
|
|
|
{ |
21
|
|
|
$optgroupAllowedAttributes = array( |
22
|
|
|
'/^disabled$/i' => Attribute::BOOL, |
23
|
|
|
'/^label$/i' => Attribute::CS_STRING |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
return array_merge( |
27
|
|
|
$optgroupAllowedAttributes, |
28
|
|
|
parent::getAllowedAttributes() |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
protected function removeInvalidChildren(LoggerInterface $logger) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
foreach ($this->children as $child) { |
35
|
|
|
if ($child instanceof NonParticipating || |
36
|
|
|
$child instanceof Option || |
37
|
|
|
$child instanceof ScriptSupporting) { |
38
|
|
|
continue; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$logger->debug('Removing ' . $child . '. Only "option" and script supporting elements allowed as children of a "optgroup" element.'); |
42
|
|
|
$this->removeChild($child); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function removeInvalidSelf(LoggerInterface $logger) |
47
|
|
|
{ |
48
|
|
|
$parent = $this->getParent(); |
49
|
|
|
if ($parent !== null && !$parent instanceof Select) { |
50
|
|
|
$logger->debug('Removing ' . $this . '. Only "select" element allowed as parent of "optgroup" element.'); |
51
|
|
|
|
52
|
|
|
return true; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.