Passed
Pull Request — master (#3)
by Chema
07:57
created

SegmentedValues   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 30
rs 10
ccs 11
cts 11
cp 1
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A factory() 0 3 1
A fromRaw() 0 7 2
A list() 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\SegmentFactoryInterface;
9
use EdifactParser\Segments\SegmentInterface;
10
11
/** @psalmphp-immutable */
12
final class SegmentedValues
13
{
14
    /** @psalm-var list<SegmentInterface> */
15
    private array $list = [];
16
17
    private SegmentFactoryInterface $segmentFactory;
18
19 6
    public static function factory(?SegmentFactoryInterface $segmentFactory = null): self
20
    {
21 6
        return new self($segmentFactory ?? new SegmentFactory());
22
    }
23
24 7
    public function __construct(SegmentFactoryInterface $segmentFactory)
25
    {
26 7
        $this->segmentFactory = $segmentFactory;
27 7
    }
28
29 7
    public function fromRaw(array $rawArrays): self
30
    {
31 7
        foreach ($rawArrays as $rawArray) {
32 7
            $this->list[] = $this->segmentFactory->segmentFromArray($rawArray);
33
        }
34
35 7
        return $this;
36
    }
37
38
    /** @return SegmentInterface[] */
39 7
    public function list(): array
40
    {
41 7
        return $this->list;
42
    }
43
}
44