Passed
Push — master ( ed8f97...95efe5 )
by Chema
03:24
created

SegmentedValues::fromSegmentInterfaces()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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