CombinedStringList::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Funivan\CabbageCore\String\StringList\Combined;
6
7
use Funivan\CabbageCore\String\StringList\StringListInterface;
8
9
/**
10
 * In some cases we can not use CompositeStringList because of huge nested level
11
 * We need to use imperative style and merge items int __construct.
12
 */
13
class CombinedStringList implements StringListInterface
14
{
15
16
    /**
17
     * @var string[]
18
     */
19
    private $values;
20
21
22 1
    public function __construct(StringListInterface ...$items)
23
    {
24 1
        $values = [];
25 1
        foreach ($items as $item) {
26
            /** @noinspection SlowArrayOperationsInLoopInspection */
27 1
            $values = array_merge($values, iterator_to_array($item->all()));
28
        }
29 1
        $this->values = $values;
30 1
    }
31
32
33
    /**
34
     * @return string[]|\Generator
35
     */
36 1
    public function all(): \Generator
37
    {
38 1
        yield from $this->values;
39 1
    }
40
}
41