Passed
Push — master ( 33eb2b...9ab48b )
by Chema
02:30
created

SegmentList::factory()   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 10
    public static function withDefaultFactory(): self
18
    {
19 10
        return new self(SegmentFactory::withDefaultSegments());
20
    }
21
22 13
    public function __construct(SegmentFactoryInterface $segmentFactory)
23
    {
24 13
        $this->segmentFactory = $segmentFactory;
25 13
    }
26
27
    /** @return SegmentInterface[] */
28 13
    public function fromRaw(array $rawArrays): array
29
    {
30 13
        return array_map(
31 13
            fn (array $raw) => $this->segmentFactory->createSegmentFromArray($raw),
32
            $rawArrays
33
        );
34
    }
35
}
36