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

TestingCustomSegmentFactory.php$0 ➔ name()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
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