1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Configuration; |
6
|
|
|
use Groundskeeper\Tokens\Element; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\FlowContent; |
8
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
9
|
|
|
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting; |
10
|
|
|
use Groundskeeper\Tokens\Token; |
11
|
|
|
use Psr\Log\LoggerInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* "ol" element |
15
|
|
|
* |
16
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-ol-element |
17
|
|
|
*/ |
18
|
|
|
class Ol extends OpenElement implements FlowContent |
19
|
|
|
{ |
20
|
1 |
|
protected function getAllowedAttributes() |
21
|
|
|
{ |
22
|
|
|
$olAllowedAttributes = array( |
23
|
1 |
|
'/^reversed$/i' => Element::ATTR_BOOL, |
24
|
1 |
|
'/^start$/i' => Element::ATTR_INT, |
25
|
1 |
|
'/^type$/i' => Element::ATTR_CS_STRING, |
26
|
1 |
|
); |
27
|
|
|
|
28
|
1 |
|
return array_merge( |
29
|
1 |
|
$olAllowedAttributes, |
30
|
1 |
|
parent::getAllowedAttributes() |
31
|
1 |
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
View Code Duplication |
protected function doClean(LoggerInterface $logger) |
|
|
|
|
35
|
|
|
{ |
36
|
1 |
|
if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) { |
37
|
|
|
// Only "li" and ScriptSupporting elements allowed. |
38
|
1 |
|
foreach ($this->children as $child) { |
39
|
1 |
|
if ($child->getType() == Token::COMMENT) { |
40
|
1 |
|
continue; |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
if ($child->getType() != Token::ELEMENT) { |
44
|
1 |
|
$logger->debug('Removing ' . $child . '. Only elements "li" and script supporting elements allowed as children of "ol" element.'); |
45
|
1 |
|
$this->removeChild($child); |
46
|
|
|
|
47
|
1 |
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
if ($child->getName() == 'li' || $child instanceof ScriptSupporting) { |
51
|
1 |
|
continue; |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
$logger->debug('Removing ' . $child . '. Only elements "li" and script supporting elements allowed as children of "ol" element.'); |
55
|
1 |
|
$this->removeChild($child); |
56
|
1 |
|
} |
57
|
1 |
|
} |
58
|
|
|
|
59
|
1 |
|
return true; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.