Code Duplication    Length = 35-45 lines in 12 locations

src/Element/Canvas.php 1 location

@@ 15-49 (lines=35) @@
12
 * Class Canvas
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas
14
 */
15
final class Canvas 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('canvas', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Canvas
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Canvas($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Canvas
36
    {
37
        return new Canvas($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withHeight($height): Canvas
41
    {
42
        return $this->withAttribute('height', $height);
43
    }
44
45
    public function withWidth($width): Canvas
46
    {
47
        return $this->withAttribute('width', $width);
48
    }
49
}
50

src/Element/Deleted.php 1 location

@@ 15-49 (lines=35) @@
12
 * Class Deleted
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del
14
 */
15
final class Deleted 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('del', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Deleted
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Deleted($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Deleted
36
    {
37
        return new Deleted($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withCite(string $url): Deleted
41
    {
42
        return $this->withAttribute('cite', $url);
43
    }
44
45
    public function withDateTime(string $dateTime): Deleted
46
    {
47
        return $this->withAttribute('datetime', $dateTime);
48
    }
49
}
50

src/Element/FieldSet.php 1 location

@@ 15-54 (lines=40) @@
12
 * Class FieldSet
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset
14
 */
15
final class FieldSet 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('fieldset', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): FieldSet
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new FieldSet($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): FieldSet
36
    {
37
        return new FieldSet($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withDisabled(): FieldSet
41
    {
42
        return $this->withAttribute('disabled');
43
    }
44
45
    public function withForm(string $id): FieldSet
46
    {
47
        return $this->withAttribute('form', $id);
48
    }
49
50
    public function withName(string $name): FieldSet
51
    {
52
        return $this->withAttribute('name', $name);
53
    }
54
}
55

src/Element/Inserted.php 1 location

@@ 15-49 (lines=35) @@
12
 * Class Inserted
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins
14
 */
15
final class Inserted 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('ins', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Inserted
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Inserted($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Inserted
36
    {
37
        return new Inserted($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withCite(string $url): Inserted
41
    {
42
        return $this->withAttribute('cite', $url);
43
    }
44
45
    public function withDateTime(string $dateTime): Inserted
46
    {
47
        return $this->withAttribute('datetime', $dateTime);
48
    }
49
}
50

src/Element/Option.php 1 location

@@ 15-59 (lines=45) @@
12
 * Class Option
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
14
 */
15
final class Option 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('option', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Option
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Option($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Option
36
    {
37
        return new Option($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withDisabled(): Option
41
    {
42
        return $this->withAttribute('disabled');
43
    }
44
45
    public function withLabel(string $label): Option
46
    {
47
        return $this->withAttribute('label', $label);
48
    }
49
50
    public function withSelected(): Option
51
    {
52
        return $this->withAttribute('selected');
53
    }
54
55
    public function withLValue(string $value): Option
56
    {
57
        return $this->withAttribute('value', $value);
58
    }
59
}
60

src/Element/OptionGroup.php 1 location

@@ 15-49 (lines=35) @@
12
 * Class OptionGroup
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup
14
 */
15
final class OptionGroup 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('optgroup', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): OptionGroup
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new OptionGroup($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): OptionGroup
36
    {
37
        return new OptionGroup($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withDisabled(): OptionGroup
41
    {
42
        return $this->withAttribute('disabled');
43
    }
44
45
    public function withLabel(string $label): OptionGroup
46
    {
47
        return $this->withAttribute('label', $label);
48
    }
49
}
50

src/Element/OrderedList.php 1 location

@@ 15-54 (lines=40) @@
12
 * Class OrderedList
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol
14
 */
15
final class OrderedList 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('ol', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): OrderedList
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new OrderedList($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): OrderedList
36
    {
37
        return new OrderedList($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withReversed(): OrderedList
41
    {
42
        return $this->withAttribute('reversed');
43
    }
44
45
    public function withStart(int $start): OrderedList
46
    {
47
        return $this->withAttribute('start', $start);
48
    }
49
50
    public function withType(string $type): OrderedList
51
    {
52
        return $this->withAttribute('type', $type);
53
    }
54
}
55

src/Element/Output.php 1 location

@@ 15-54 (lines=40) @@
12
 * Class Output
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/output
14
 */
15
final class Output 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('output', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Output
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Output($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Output
36
    {
37
        return new Output($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withFor(string $ids): Output
41
    {
42
        return $this->withAttribute('for', $ids);
43
    }
44
45
    public function withForm(string $id): Output
46
    {
47
        return $this->withAttribute('form', $id);
48
    }
49
50
    public function withName(string $name): Output
51
    {
52
        return $this->withAttribute('name', $name);
53
    }
54
}
55

src/Element/Progress.php 1 location

@@ 15-49 (lines=35) @@
12
 * Class Progress
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress
14
 */
15
final class Progress 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('progress', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Progress
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Progress($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Progress
36
    {
37
        return new Progress($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withMax($number): Progress
41
    {
42
        return $this->withAttribute('max', $number);
43
    }
44
45
    public function withValue($number): Progress
46
    {
47
        return $this->withAttribute('value', $number);
48
    }
49
}
50

src/Element/Style.php 1 location

@@ 15-54 (lines=40) @@
12
 * Class Style
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
14
 */
15
final class Style 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('style', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): Style
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new Style($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): Style
36
    {
37
        return new Style($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withType(string $mime = 'text/css'): Style
41
    {
42
        return $this->withAttribute('type', $mime);
43
    }
44
45
    /**
46
     * @param string $query
47
     * @return Style
48
     * @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
49
     */
50
    public function withMedia(string $query = 'all'): Style
51
    {
52
        return $this->withAttribute('media', $query);
53
    }
54
}
55

src/Element/TableCell.php 1 location

@@ 15-54 (lines=40) @@
12
 * Class TableCell
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td
14
 */
15
final class TableCell 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('td', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): TableCell
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new TableCell($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): TableCell
36
    {
37
        return new TableCell($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withColSpan(int $span): TableCell
41
    {
42
        return $this->withAttribute('colspan', $span);
43
    }
44
45
    public function withRowSpan(int $span): TableCell
46
    {
47
        return $this->withAttribute('rowspan', $span);
48
    }
49
50
    public function withHeaders(string $ids): TableCell
51
    {
52
        return $this->withAttribute('headers', $ids);
53
    }
54
}
55

src/Element/TableHeaderCell.php 1 location

@@ 15-59 (lines=45) @@
12
 * Class TableHeaderCell
13
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
14
 */
15
final class TableHeaderCell 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('th', $attributes, $children);
22
    }
23
24
    public function withAttribute(string $name, string $value = null): TableHeaderCell
25
    {
26
        if ($value) {
27
            $attribute = new StandardAttribute($name, $value);
28
        } else {
29
            $attribute = new BooleanAttribute($name);
30
        }
31
32
        return new TableHeaderCell($this->attributes->add($attribute), $this->children);
33
    }
34
35
    public function withChild(ElementInterface $element): TableHeaderCell
36
    {
37
        return new TableHeaderCell($this->attributes, $this->children->add($element));
38
    }
39
40
    public function withColSpan(int $span): TableHeaderCell
41
    {
42
        return $this->withAttribute('colspan', $span);
43
    }
44
45
    public function withRowSpan(int $span): TableHeaderCell
46
    {
47
        return $this->withAttribute('rowspan', $span);
48
    }
49
50
    public function withHeaders(string $ids): TableHeaderCell
51
    {
52
        return $this->withAttribute('headers', $ids);
53
    }
54
55
    public function withScope(string $scope): TableHeaderCell
56
    {
57
        return $this->withAttribute('scope', $scope);
58
    }
59
}
60