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

SegmentFactory::segmentFromArray()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 9

Importance

Changes 0
Metric Value
cc 9
eloc 19
c 0
b 0
f 0
nc 9
nop 1
dl 0
loc 24
rs 8.0555
ccs 20
cts 20
cp 1
crap 9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdifactParser\Segments;
6
7
/** @psalmphp-immutable */
8
final class SegmentFactory implements SegmentFactoryInterface
9
{
10 8
    public function segmentFromArray(array $rawArray): SegmentInterface
11
    {
12 8
        $name = $rawArray[0];
13
14 8
        switch ($name) {
15 8
            case 'UNH':
16 8
                return new UNHMessageHeader($rawArray);
17 7
            case 'DTM':
18 1
                return new DTMDateTimePeriod($rawArray);
19 7
            case 'NAD':
20 1
                return new NADNameAddress($rawArray);
21 7
            case 'MEA':
22 1
                return new MEADimensions($rawArray);
23 7
            case 'CNT':
24 4
                return new CNTControl($rawArray);
25 7
            case 'PCI':
26 1
                return new PCIPackageId($rawArray);
27 7
            case 'BGM':
28 1
                return new BGMBeginningOfMessage($rawArray);
29 7
            case 'UNT':
30 7
                return new UNTMessageFooter($rawArray);
31
        }
32
33 6
        return new UnknownSegment($rawArray);
34
    }
35
}
36