Total Complexity | 7 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
9 | final class NodeValueListBuilder |
||
10 | { |
||
11 | |||
12 | private $outerIndexes = []; |
||
13 | |||
14 | /** |
||
15 | * @var NodeValueInterface[] |
||
16 | */ |
||
17 | private $values = []; |
||
18 | |||
19 | 7 | public function addValue(NodeValueInterface $value, int $outerIndex): self |
|
20 | { |
||
21 | 7 | if ($this->valueExists($value, $outerIndex)) { |
|
22 | 1 | return $this; |
|
23 | } |
||
24 | |||
25 | 7 | $this->outerIndexes[] = $outerIndex; |
|
26 | 7 | $this->values[] = $value; |
|
27 | |||
28 | 7 | return $this; |
|
29 | } |
||
30 | |||
31 | 7 | public function build(): NodeValueListInterface |
|
32 | { |
||
33 | 7 | return new NodeValueList(new IndexMap(...$this->outerIndexes), ...$this->values); |
|
34 | } |
||
35 | |||
36 | 7 | private function valueExists(NodeValueInterface $value, int $outerIndex): bool |
|
51 | } |
||
52 | } |
||
53 |