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
|
|
|
class Body extends OpenElement implements SectioningRoot |
12
|
|
|
{ |
13
|
|
|
protected function getAllowedAttributes() |
14
|
|
|
{ |
15
|
|
|
$bodyAllowedAttributes = array( |
16
|
|
|
'/^onafterprint$/i' => Element::ATTR_JS, |
17
|
|
|
'/^onbeforeprint$/i' => Element::ATTR_JS, |
18
|
|
|
'/^onbeforeunload$/i' => Element::ATTR_JS, |
19
|
|
|
'/^onhashchange$/i' => Element::ATTR_JS, |
20
|
|
|
'/^onlanguagechange$/i' => Element::ATTR_JS, |
21
|
|
|
'/^onmessage$/i' => Element::ATTR_JS, |
22
|
|
|
'/^onoffline$/i' => Element::ATTR_JS, |
23
|
|
|
'/^ononline$/i' => Element::ATTR_JS, |
24
|
|
|
'/^onpagehide$/i' => Element::ATTR_JS, |
25
|
|
|
'/^onpageshow$/i' => Element::ATTR_JS, |
26
|
|
|
'/^onpopstate$/i' => Element::ATTR_JS, |
27
|
|
|
'/^onrejectionhandled$/i' => Element::ATTR_JS, |
28
|
|
|
'/^onstorage$/i' => Element::ATTR_JS, |
29
|
|
|
'/^onunhandledrejection$/i' => Element::ATTR_JS, |
30
|
|
|
'/^onunload$/i' => Element::ATTR_JS |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
return array_merge( |
34
|
|
|
$bodyAllowedAttributes, |
35
|
|
|
parent::getAllowedAttributes() |
36
|
|
|
); |
37
|
|
|
} |
38
|
16 |
|
|
39
|
|
|
protected function doClean(LoggerInterface $logger) |
40
|
|
|
{ |
41
|
16 |
|
// "body" element must be a child of "html" element. |
42
|
16 |
View Code Duplication |
if ($this->getParent() !== null && |
|
|
|
|
43
|
16 |
|
$this->getParent()->getType() === Token::ELEMENT && |
44
|
|
|
$this->getParent()->getName() != 'html') { |
|
|
|
|
45
|
|
|
$logger->debug('Element "body" must be a child of "html" element.'); |
46
|
|
|
|
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return true; |
51
|
16 |
|
} |
52
|
|
|
} |
53
|
|
|
|
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.