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

SegmentedValues::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 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