Code Duplication    Length = 34-36 lines in 3 locations

src/Tokens/Elements/Source.php 1 location

@@ 15-50 (lines=36) @@
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-source-element
14
 */
15
class Source extends ClosedElement
16
{
17
    protected function getAllowedAttributes()
18
    {
19
        $sourceAllowedAttributes = array(
20
            '/^src$/i' => Element::ATTR_URI,
21
            '/^type$/i' => Element::ATTR_CS_STRING,
22
            '/^srcset$/i' => Element::ATTR_CS_STRING,
23
            '/^sizes$/i' => Element::ATTR_CS_STRING,
24
            '/^media$/i' => Element::ATTR_CS_STRING
25
        );
26
27
        return array_merge(
28
            $sourceAllowedAttributes,
29
            parent::getAllowedAttributes()
30
        );
31
    }
32
33
    protected function doClean(LoggerInterface $logger)
34
    {
35
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
36
            // Child of "picture" element.
37
            // Child of media element.
38
            $parent = $this->getParent();
39
            if ($parent !== null &&
40
                $parent->getName() != 'picture' &&
41
                !$parent instanceof MediaElement) {
42
                $logger->debug('Element "picture" must be a child of "picture" element or a media element.');
43
44
                return false;
45
            }
46
        }
47
48
        return true;
49
    }
50
}
51

src/Tokens/Elements/Th.php 1 location

@@ 15-48 (lines=34) @@
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-th-element
14
 */
15
class Th extends OpenElement
16
{
17
    protected function getAllowedAttributes()
18
    {
19
        $thAllowedAttributes = array(
20
            '/^colspan$/i' => Element::ATTR_INT,
21
            '/^rowspan$/i' => Element::ATTR_INT,
22
            '/^headers$/i' => Element::ATTR_CS_STRING,
23
            '/^scope$/i' => Element::ATTR_CS_STRING,
24
            '/^abbr$/i' => Element::ATTR_CS_STRING
25
        );
26
27
        return array_merge(
28
            $thAllowedAttributes,
29
            parent::getAllowedAttributes()
30
        );
31
    }
32
33
    protected function doClean(LoggerInterface $logger)
34
    {
35
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
36
            // "tr" must be parent.
37
            $parent = $this->getParent();
38
            if ($parent !== null &&
39
                $parent->getName() != 'tr') {
40
                $logger->debug('Element "th" must be a child of "tr" element.');
41
42
                return false;
43
            }
44
        }
45
46
        return true;
47
    }
48
}
49

src/Tokens/Elements/Track.php 1 location

@@ 14-48 (lines=35) @@
11
 *
12
 * https://html.spec.whatwg.org/multipage/semantics.html#the-track-element
13
 */
14
class Track extends ClosedElement
15
{
16
    protected function getAllowedAttributes()
17
    {
18
        $trackAllowedAttributes = array(
19
            '/^kind$/i' => Element::ATTR_CS_STRING,
20
            '/^src$/i' => Element::ATTR_URI,
21
            '/^srclang$/i' => Element::ATTR_CS_STRING,
22
            '/^label$/i' => Element::ATTR_CS_STRING,
23
            '/^default$/i' => Element::ATTR_BOOL
24
        );
25
26
        return array_merge(
27
            $trackAllowedAttributes,
28
            parent::getAllowedAttributes()
29
        );
30
    }
31
32
    protected function doClean(LoggerInterface $logger)
33
    {
34
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
35
            // Must be child of "object" element.
36
            $parent = $this->getParent();
37
            if ($parent !== null &&
38
                $parent->getName() !== 'video' &&
39
                $parent->getName() !== 'audio') {
40
                $logger->debug('Element "track" must be a child of "video" or "audio" element.');
41
42
                return false;
43
            }
44
        }
45
46
        return true;
47
    }
48
}
49