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

Message   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A withMetadata() 0 7 1
A metadataValue() 0 4 1
A event() 0 4 1
A metadata() 0 4 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
}