Code Duplication    Length = 52-52 lines in 2 locations

src/Set/AttributeSet.php 1 location

@@ 7-58 (lines=52) @@
4
5
use RoyallTheFourth\HtmlDocument\Attribute\AttributeInterface;
6
7
final class AttributeSet implements SetInterface
8
{
9
    private $attributes = [];
10
11
    public function __construct(AttributeInterface $attribute = null)
12
    {
13
        if ($attribute) {
14
            $this->attributes[] = $attribute;
15
        }
16
    }
17
18
    public function iterate(): \Generator
19
    {
20
        foreach ($this->attributes as $attribute) {
21
            yield $attribute;
22
        }
23
    }
24
25
    /**
26
     * @param AttributeInterface $attribute
27
     * @return AttributeSet
28
     */
29
    public function add($attribute): AttributeSet
30
    {
31
        $this->attributes[] = $attribute;
32
        return $this;
33
    }
34
35
    /**
36
     * @param $set AttributeSet
37
     * @return AttributeSet
38
     */
39
    public function merge($set): AttributeSet
40
    {
41
        foreach ($set->iterate() as $attribute) {
42
            $this->add($attribute);
43
        }
44
45
        return $this;
46
    }
47
48
    public function render(): string
49
    {
50
        $output = '';
51
52
        foreach ($this->iterate() as $attribute) {
53
            $output .= ' ' . $attribute->render();
54
        }
55
56
        return $output;
57
    }
58
}
59

src/Set/ElementSet.php 1 location

@@ 7-58 (lines=52) @@
4
5
use RoyallTheFourth\HtmlDocument\Element\ElementInterface;
6
7
final class ElementSet implements SetInterface
8
{
9
    private $elements = [];
10
11
    public function __construct(ElementInterface $element = null)
12
    {
13
        if ($element) {
14
            $this->elements[] = $element;
15
        }
16
    }
17
18
    public function iterate(): \Generator
19
    {
20
        foreach ($this->elements as $element) {
21
            yield $element;
22
        }
23
    }
24
25
    /**
26
     * @param $element ElementInterface
27
     * @return ElementSet
28
     */
29
    public function add($element): ElementSet
30
    {
31
        $this->elements[] = $element;
32
        return $this;
33
    }
34
35
    /**
36
     * @param $set ElementSet
37
     * @return ElementSet
38
     */
39
    public function merge($set): ElementSet
40
    {
41
        foreach ($set->iterate() as $element) {
42
            $this->add($element);
43
        }
44
45
        return $this;
46
    }
47
48
    public function render(): string
49
    {
50
        $output = '';
51
52
        foreach ($this->iterate() as $element) {
53
            $output .= $element->render() . "\n";
54
        }
55
56
        return $output;
57
    }
58
}
59