Passed
Push — master ( 8f83e8...e4d779 )
by Chema
02:15
created

TestingCustomSegmentFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 39
rs 10
c 1
b 0
f 0
wmc 5

7 Methods

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