1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Configuration; |
6
|
|
|
use Groundskeeper\Tokens\ElementTypes\FlowContent; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\HeadingContent; |
8
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
9
|
|
|
use Groundskeeper\Tokens\ElementTypes\SectioningContent; |
10
|
|
|
use Groundskeeper\Tokens\Token; |
11
|
|
|
use Psr\Log\LoggerInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* "address" element |
15
|
|
|
* |
16
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-address-element |
17
|
|
|
*/ |
18
|
|
|
class Address extends OpenElement implements FlowContent |
19
|
|
|
{ |
20
|
3 |
|
protected function removeInvalidChildren(LoggerInterface $logger) |
21
|
|
|
{ |
22
|
|
|
// No HeadingContent descendants |
23
|
|
|
// No SectioningContent descendants |
24
|
|
|
// No "header", "footer", or "address" element descendants. |
|
|
|
|
25
|
3 |
|
foreach ($this->children as $child) { |
26
|
3 |
|
if ($child instanceof HeadingContent) { |
27
|
1 |
|
$logger->debug('Removing ' . $child . '. Heading Content elements not allowed as "address" element child.'); |
28
|
1 |
|
$this->removeChild($child); |
|
|
|
|
29
|
|
|
|
30
|
1 |
|
continue; |
31
|
|
|
} |
32
|
|
|
|
33
|
3 |
|
if ($child instanceof SectioningContent) { |
34
|
1 |
|
$logger->debug('Removing ' . $child . '. Sectioning Content elements not allowed as "address" element child.'); |
35
|
1 |
|
$this->removeChild($child); |
|
|
|
|
36
|
|
|
|
37
|
1 |
|
continue; |
38
|
|
|
} |
39
|
|
|
|
40
|
3 |
|
if ($child->getType() == Token::ELEMENT) { |
41
|
2 |
|
if ($child->getName() == 'header' || |
42
|
2 |
|
$child->getName() == 'footer' || |
43
|
2 |
|
$child->getName() == 'address') { |
44
|
1 |
|
$logger->debug('Removing ' . $child . '. Elements "header", "footer", and "address" not allowed as "address" element child.'); |
45
|
1 |
|
$this->removeChild($child); |
46
|
|
|
|
47
|
1 |
|
continue; |
48
|
|
|
} |
49
|
1 |
|
} |
50
|
3 |
|
} |
51
|
3 |
|
} |
52
|
|
|
} |
53
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.