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

SegmentList   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 21
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fromRaw() 0 5 1
A withDefaultFactory() 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
/** @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