Passed
Push — master ( ed8f97...95efe5 )
by Chema
03:24
created

TransactionMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A addSegment() 0 9 2
A segments() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdifactParser;
6
7
use EdifactParser\Segments\SegmentInterface;
8
9
final class TransactionMessage
10
{
11
    /**
12
     * First string: segment key
13
     * Second key: sub segment key.
14
     *
15
     * @var array<string, array<string,SegmentInterface>>
16
     */
17
    private $segments = [];
18
19 8
    public function __construct(array $segments = [])
20
    {
21 8
        foreach ($segments as $segment) {
22 6
            $this->addSegment($segment);
23
        }
24 8
    }
25
26 8
    public function addSegment(SegmentInterface $segment): void
27
    {
28 8
        $name = $segment->name();
29
30 8
        if (!isset($this->segments[$name])) {
31 8
            $this->segments[$name] = [];
32
        }
33
34 8
        $this->segments[$name][$segment->subSegmentKey()] = $segment;
35 8
    }
36
37
    /** @return array<string, array<string,SegmentInterface>> */
38 4
    public function segments(): array
39
    {
40 4
        return $this->segments;
41
    }
42
}
43