Test Setup Failed
Push — master ( f52cce...34890a )
by Royall
02:32
created

AttributeSet::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace RoyallTheFourth\HtmlDocument\Set;
4
5
use RoyallTheFourth\HtmlDocument\Attribute\AttributeInterface;
6
7 View Code Duplication
final class AttributeSet implements SetInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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