Completed
Push — master ( a4ef19...191941 )
by Frank
05:13
created

Message::aggregateRootId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace EventSauce\EventSourcing;
4
5
final class Message
6
{
7
    /**
8
     * @var Event
9
     */
10
    private $event;
11
12
    /**
13
     * @var array
14
     */
15
    private $headers;
16
17 11
    public function __construct(Event $event, array $metadata = [])
18
    {
19 11
        $this->event = $event;
20 11
        $this->headers = $metadata;
21 11
    }
22
23 3
    public function withHeader(string $key, $value): Message
24
    {
25 3
        $clone = clone $this;
26 3
        $clone->headers[$key] = $value;
27
28 3
        return $clone;
29
    }
30
31 5
    public function withHeaders(array $headers): Message
32
    {
33 5
        $clone = clone $this;
34 5
        $clone->headers = $headers + $clone->headers;
35
36 5
        return $clone;
37
    }
38
39 1
    public function aggregateRootId(): ?AggregateRootId
40
    {
41 1
        return $this->headers[Header::AGGREGATE_ROOT_ID] ?? null;
42
    }
43
44 8
    public function header(string $key)
45
    {
46 8
        return $this->headers[$key] ?? null;
47
    }
48
49 3
    public function headers(): array
50
    {
51 3
        return $this->headers;
52
    }
53
54 9
    public function event(): Event
55
    {
56 9
        return $this->event;
57
    }
58
}