1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Tokens\Element; |
6
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\SectioningRoot; |
8
|
|
|
use Groundskeeper\Tokens\Token; |
9
|
|
|
use Psr\Log\LoggerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* "body" element |
13
|
|
|
* |
14
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-body-element |
15
|
|
|
*/ |
16
|
|
|
class Body extends OpenElement implements SectioningRoot |
17
|
|
|
{ |
18
|
1 |
|
protected function getAllowedAttributes() |
19
|
|
|
{ |
20
|
|
|
$bodyAllowedAttributes = array( |
21
|
1 |
|
'/^onafterprint$/i' => Element::ATTR_JS, |
22
|
1 |
|
'/^onbeforeprint$/i' => Element::ATTR_JS, |
23
|
1 |
|
'/^onbeforeunload$/i' => Element::ATTR_JS, |
24
|
1 |
|
'/^onhashchange$/i' => Element::ATTR_JS, |
25
|
1 |
|
'/^onlanguagechange$/i' => Element::ATTR_JS, |
26
|
1 |
|
'/^onmessage$/i' => Element::ATTR_JS, |
27
|
1 |
|
'/^onoffline$/i' => Element::ATTR_JS, |
28
|
1 |
|
'/^ononline$/i' => Element::ATTR_JS, |
29
|
1 |
|
'/^onpagehide$/i' => Element::ATTR_JS, |
30
|
1 |
|
'/^onpageshow$/i' => Element::ATTR_JS, |
31
|
1 |
|
'/^onpopstate$/i' => Element::ATTR_JS, |
32
|
1 |
|
'/^onrejectionhandled$/i' => Element::ATTR_JS, |
33
|
1 |
|
'/^onstorage$/i' => Element::ATTR_JS, |
34
|
1 |
|
'/^onunhandledrejection$/i' => Element::ATTR_JS, |
35
|
|
|
'/^onunload$/i' => Element::ATTR_JS |
36
|
1 |
|
); |
37
|
|
|
|
38
|
1 |
|
return array_merge( |
39
|
1 |
|
$bodyAllowedAttributes, |
40
|
1 |
|
parent::getAllowedAttributes() |
41
|
1 |
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
33 |
View Code Duplication |
protected function removeInvalidSelf(LoggerInterface $logger) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
// "body" element must be a child of "html" element. |
47
|
33 |
|
if ($this->getParent() !== null && |
48
|
33 |
|
$this->getParent()->getType() === Token::ELEMENT && |
49
|
33 |
|
$this->getParent()->getName() != 'html') { |
|
|
|
|
50
|
|
|
$logger->debug($this . ' must be a child of "html" element.'); |
51
|
|
|
|
52
|
|
|
return true; |
53
|
|
|
} |
54
|
|
|
|
55
|
33 |
|
return false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function doClean(LoggerInterface $logger) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
|
61
|
|
|
return true; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
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.