-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestingSegmentFactory.php
53 lines (41 loc) · 1.31 KB
/
TestingSegmentFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace EdifactParser\Tests\Functional;
use EdifactParser\Segments\SegmentFactory;
use EdifactParser\Segments\SegmentFactoryInterface;
use EdifactParser\Segments\SegmentInterface;
final class TestingSegmentFactory implements SegmentFactoryInterface
{
private string $customKey;
private SegmentFactory $defaultFactory;
public function __construct(string $customKey)
{
$this->customKey = $customKey;
$this->defaultFactory = new SegmentFactory();
}
public function segmentFromArray(array $rawArray): SegmentInterface
{
if ($this->customKey !== $rawArray[0]) {
return $this->defaultFactory->segmentFromArray($rawArray);
}
return new class($rawArray) implements SegmentInterface {
private array $rawArray;
public function __construct(array $rawArray)
{
$this->rawArray = $rawArray;
}
public function name(): string
{
return $this->rawArray[0];
}
public function subSegmentKey(): string
{
return $this->rawArray[1];
}
public function rawValues(): array
{
return $this->rawArray;
}
};
}
}