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

TestingSegmentFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 39
rs 10
wmc 5

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hp$0 ➔ name() 0 3 1
A hp$0 ➔ subSegmentKey() 0 3 1
A hp$0 ➔ __construct() 0 3 1
A hp$0 ➔ rawValues() 0 3 1
A hp$0 ➔ segmentFromArray() 0 27 1
segmentFromArray() 0 27 ?
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdifactParser\Tests\Functional;
6
7
use EdifactParser\Segments\SegmentFactory;
8
use EdifactParser\Segments\SegmentFactoryInterface;
9
use EdifactParser\Segments\SegmentInterface;
10
11
final class TestingSegmentFactory implements SegmentFactoryInterface
12
{
13
    private string $customKey;
14
15
    private SegmentFactory $defaultFactory;
16
17
    public function __construct(string $customKey)
18
    {
19
        $this->customKey = $customKey;
20
        $this->defaultFactory = new SegmentFactory();
21
    }
22
23
    public function segmentFromArray(array $rawArray): SegmentInterface
24
    {
25
        if ($this->customKey !== $rawArray[0]) {
26
            return $this->defaultFactory->segmentFromArray($rawArray);
27
        }
28
29
        return new class($rawArray) implements SegmentInterface {
30
            private array $rawArray;
31
32
            public function __construct(array $rawArray)
33
            {
34
                $this->rawArray = $rawArray;
35
            }
36
37
            public function name(): string
38
            {
39
                return $this->rawArray[0];
40
            }
41
42
            public function subSegmentKey(): string
43
            {
44
                return $this->rawArray[1];
45
            }
46
47
            public function rawValues(): array
48
            {
49
                return $this->rawArray;
50
            }
51
        };
52
    }
53
}
54