Code Duplication    Length = 31-34 lines in 3 locations

src/Tokens/Elements/Source.php 1 location

@@ 15-48 (lines=34) @@
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' => Attribute::URI,
21
            '/^type$/i' => Attribute::CS_STRING,
22
            '/^srcset$/i' => Attribute::CS_STRING,
23
            '/^sizes$/i' => Attribute::CS_STRING,
24
            '/^media$/i' => Attribute::CS_STRING
25
        );
26
27
        return array_merge(
28
            $sourceAllowedAttributes,
29
            parent::getAllowedAttributes()
30
        );
31
    }
32
33
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
34
    {
35
        // Child of "picture" element.
36
        // Child of media element.
37
        $parent = $this->getParent();
38
        if ($parent !== null &&
39
            !$parent instanceof Picture &&
40
            !$parent instanceof MediaElement) {
41
            $logger->debug('Removing ' . $this . ' must be a child of "picture" element or a media element.');
42
43
            return true;
44
        }
45
46
        return false;
47
    }
48
}
49

src/Tokens/Elements/Track.php 1 location

@@ 14-46 (lines=33) @@
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' => Attribute::CS_STRING,
20
            '/^src$/i' => Attribute::URI,
21
            '/^srclang$/i' => Attribute::CS_STRING,
22
            '/^label$/i' => Attribute::CS_STRING,
23
            '/^default$/i' => Attribute::BOOL
24
        );
25
26
        return array_merge(
27
            $trackAllowedAttributes,
28
            parent::getAllowedAttributes()
29
        );
30
    }
31
32
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
33
    {
34
        // Must be child of "object" element.
35
        $parent = $this->getParent();
36
        if ($parent !== null &&
37
            !$parent instanceof Video &&
38
            !$parent instanceof Audio) {
39
            $logger->debug('Removing ' . $this . '. Must be a child of "video" or "audio" element.');
40
41
            return true;
42
        }
43
44
        return false;
45
    }
46
}
47

src/Tokens/Elements/Th.php 1 location

@@ 14-44 (lines=31) @@
11
 *
12
 * https://html.spec.whatwg.org/multipage/semantics.html#the-th-element
13
 */
14
class Th extends OpenElement
15
{
16
    protected function getAllowedAttributes()
17
    {
18
        $thAllowedAttributes = array(
19
            '/^colspan$/i' => Attribute::INT,
20
            '/^rowspan$/i' => Attribute::INT,
21
            '/^headers$/i' => Attribute::CS_STRING,
22
            '/^scope$/i' => Attribute::CS_STRING,
23
            '/^abbr$/i' => Attribute::CS_STRING
24
        );
25
26
        return array_merge(
27
            $thAllowedAttributes,
28
            parent::getAllowedAttributes()
29
        );
30
    }
31
32
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
33
    {
34
        // "tr" must be parent.
35
        $parent = $this->getParent();
36
        if ($parent !== null && !$parent instanceof Tr) {
37
            $logger->debug('Removing ' . $this . '. Must be a child of "tr" element.');
38
39
            return true;
40
        }
41
42
        return false;
43
    }
44
}
45