Code Duplication    Length = 75-75 lines in 3 locations

src/Element/Button.php 1 location

@@ 15-89 (lines=75) @@
12
 * Class Button
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
14
 */
15
final class Button extends AbstractElement implements ParentElementInterface
16
{
17
    public function __construct(AttributeSet $attributes = null, ElementSet $children = null)
18
    {
19
        $this->attributes = $attributes ?? new AttributeSet();
20
        $this->children = $children ?? new ElementSet();
21
        $this->tag = new Standard('button', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Button
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Button($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Button
36
    {
37
        return new Button($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withAutoFocus($autoFocus): Button
41
    {
42
        return $this->withAttribute('autofocus', $autoFocus);
43
    }
44
45
    public function withDisabled(): Button
46
    {
47
        return $this->withAttribute('disabled');
48
    }
49
50
    public function withForm($formId): Button
51
    {
52
        return $this->withAttribute('form', $formId);
53
    }
54
55
    public function withFormAction($url): Button
56
    {
57
        return $this->withAttribute('formaction', $url);
58
    }
59
60
    public function withFormEncType($encoding): Button
61
    {
62
        return $this->withAttribute('formenctype', $encoding);
63
    }
64
65
    public function withFormNoValidate(): Button
66
    {
67
        return $this->withAttribute('formnovalidate');
68
    }
69
70
    public function withFormTarget($target): Button
71
    {
72
        return $this->withAttribute('formtarget', $target);
73
    }
74
75
    public function withName($name): Button
76
    {
77
        return $this->withAttribute('name', $name);
78
    }
79
80
    public function withType($type): Button
81
    {
82
        return $this->withAttribute('type', $type);
83
    }
84
85
    public function withValue($value): Button
86
    {
87
        return $this->withAttribute('value', $value);
88
    }
89
}
90

src/Element/Image.php 1 location

@@ 15-89 (lines=75) @@
12
 * Class Image
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
14
 */
15
final class Image extends AbstractElement implements ParentElementInterface
16
{
17
    public function __construct(AttributeSet $attributes = null, ElementSet $children = null)
18
    {
19
        $this->attributes = $attributes ?? new AttributeSet();
20
        $this->children = $children ?? new ElementSet();
21
        $this->tag = new Standard('image', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Image
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Image($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Image
36
    {
37
        return new Image($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withAlt(string $alt): Image
41
    {
42
        return $this->withAttribute('alt', $alt);
43
    }
44
45
    public function withCrossOrigin(string $policy = 'anonymous'): Image
46
    {
47
        return $this->withAttribute('crossorigin', $policy);
48
    }
49
50
    public function withHeight(int $pixels): Image
51
    {
52
        return $this->withAttribute('height', $pixels);
53
    }
54
55
    public function withIsMap(): Image
56
    {
57
        return $this->withAttribute('ismap');
58
    }
59
60
    public function withLongDesc(string $urlOrId): Image
61
    {
62
        return $this->withAttribute('longdesc', $urlOrId);
63
    }
64
65
    public function withSizes(string $sizes): Image
66
    {
67
        return $this->withAttribute('sizes', $sizes);
68
    }
69
70
    public function withSrc(string $url): Image
71
    {
72
        return $this->withAttribute('src', $url);
73
    }
74
75
    public function withSrcSet(string $srcSet): Image
76
    {
77
        return $this->withAttribute('srcset', $srcSet);
78
    }
79
80
    public function withWidth(int $pixels): Image
81
    {
82
        return $this->withAttribute('width', $pixels);
83
    }
84
85
    public function withUseMap(string $id): Image
86
    {
87
        return $this->withAttribute('usemap', $id);
88
    }
89
}
90

src/Element/Video.php 1 location

@@ 15-89 (lines=75) @@
12
 * Class Video
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video
14
 */
15
final class Video extends AbstractElement implements ParentElementInterface
16
{
17
    public function __construct(AttributeSet $attributes = null, ElementSet $children = null)
18
    {
19
        $this->attributes = $attributes ?? new AttributeSet();
20
        $this->children = $children ?? new ElementSet();
21
        $this->tag = new Standard('video', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Video
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Video($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Video
36
    {
37
        return new Video($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withControls(): Video
41
    {
42
        return $this->withAttribute('controls');
43
    }
44
45
    /**
46
     * @param string $policy
47
     * @return Video
48
     * @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes
49
     */
50
    public function withCrossOrigin(string $policy): Video
51
    {
52
        return $this->withAttribute('crossorigin', $policy);
53
    }
54
55
    public function withHeight($height): Video
56
    {
57
        return $this->withAttribute('height', $height);
58
    }
59
60
    public function withWidth($width): Video
61
    {
62
        return $this->withAttribute('width', $width);
63
    }
64
65
    public function withLoop(): Video
66
    {
67
        return $this->withAttribute('loop');
68
    }
69
70
    public function withMuted(): Video
71
    {
72
        return $this->withAttribute('muted');
73
    }
74
75
    public function withPreload(string $preload): Video
76
    {
77
        return $this->withAttribute('preload', $preload);
78
    }
79
80
    public function withPoster(string $url): Video
81
    {
82
        return $this->withAttribute('poster', $url);
83
    }
84
85
    public function withSrc(string $url): Video
86
    {
87
        return $this->withAttribute('src', $url);
88
    }
89
}
90