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

SegmentedValues   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 36
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromSegmentInterfaces() 0 9 2
A fromRaw() 0 9 2
A list() 0 3 1
A addSegment() 0 3 1
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