Passed
Push — master ( 13ac76...f27e95 )
by Chema
12:22 queued 12s
created

TransactionMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 11
c 1
b 1
f 0
dl 0
loc 35
rs 10
ccs 13
cts 13
cp 1
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A withSegments() 0 9 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
     * @psalm-var array<string, array<string,SegmentInterface>>
16
     */
17
    private array $segments = [];
18
19 6
    public static function withSegments(SegmentInterface...$segments): self
20
    {
21 6
        $self = new self();
22
23 6
        foreach ($segments as $segment) {
24 6
            $self->addSegment($segment);
25
        }
26
27 6
        return $self;
28
    }
29
30 9
    public function addSegment(SegmentInterface $segment): void
31
    {
32 9
        $name = $segment->name();
33
34 9
        if (!isset($this->segments[$name])) {
35 9
            $this->segments[$name] = [];
36
        }
37
38 9
        $this->segments[$name][$segment->subSegmentKey()] = $segment;
39 9
    }
40
41 5
    public function segments(): array
42
    {
43 5
        return $this->segments;
44
    }
45
}
46