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

SegmentFactory::__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\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