Completed
Push — master ( 23d8bc...a157cc )
by Frank
13s
created

Message::metadata()   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 $metadata;
16
17 7
    public function __construct(Event $event, array $metadata = [])
18
    {
19 7
        $this->event = $event;
20 7
        $this->metadata = $metadata;
21 7
    }
22
23 2
    public function withMetadata(string $key, $value)
24
    {
25 2
        $clone = clone $this;
26 2
        $clone->metadata[$key] = $value;
27
28 2
        return $clone;
29
    }
30
31 5
    public function metadataValue(string $key)
32
    {
33 5
        return $this->metadata[$key] ?? null;
34
    }
35
36 6
    public function event(): Event
37
    {
38 6
        return $this->event;
39
    }
40
41 2
    public function metadata(): array
42
    {
43 2
        return $this->metadata;
44
    }
45
}