Passed
Push — master ( 8f83e8...e4d779 )
by Chema
02:15
created

SegmentedValues::list()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdifactParser;
6
7
use EdifactParser\Segments\CustomSegmentFactoryInterface;
8
use EdifactParser\Segments\SegmentFactory;
9
use EdifactParser\Segments\SegmentInterface;
10
11
final class SegmentedValues
12
{
13
    /** @var array */
14
    private $list;
15
16 7
    public static function fromRaw(
17
        array $rawArrays,
18
        ?CustomSegmentFactoryInterface $customSegmentsFactory = null
19
    ): self {
20 7
        $factory = new SegmentFactory($customSegmentsFactory);
21
22 7
        $self = new self();
23 7
        $segments = [];
24
25 7
        foreach ($rawArrays as $rawArray) {
26 7
            $segments[] = $factory->segmentFromArray($rawArray);
27
        }
28
29 7
        foreach ($segments as $segment) {
30 7
            $self->addSegment($segment);
31
        }
32
33 7
        return $self;
34
    }
35
36 7
    private function addSegment(SegmentInterface $segment): void
37
    {
38 7
        $this->list[] = $segment;
39 7
    }
40
41
    /** @return SegmentInterface[] */
42 7
    public function list(): array
43
    {
44 7
        return $this->list;
45
    }
46
}
47