Passed
Push — master ( f27e95...6a73f4 )
by Chema
08:35 queued 11s
created

SegmentList::__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
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
/** @psalm-immutable */
12
final class SegmentList
13
{
14
    private SegmentFactoryInterface $segmentFactory;
15
16
    /** @psalm-pure */
17 8
    public static function factory(?SegmentFactoryInterface $segmentFactory = null): self
18
    {
19 8
        return new self($segmentFactory ?? new SegmentFactory());
20
    }
21
22 8
    private function __construct(SegmentFactoryInterface $segmentFactory)
23
    {
24 8
        $this->segmentFactory = $segmentFactory;
25 8
    }
26
27
    /** @return SegmentInterface[] */
28 8
    public function fromRaw(array $rawArrays): array
29
    {
30 8
        return array_map(
31 8
            fn (array $raw) => $this->segmentFactory->segmentFromArray($raw),
32
            $rawArrays
33
        );
34
    }
35
}
36