Passed
Push — master ( 8f83e8...e4d779 )
by Chema
02:15
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 Method

Rating   Name   Duplication   Size   Complexity  
A SegmentedValues::list() 0 3 1
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