WritableEvent   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 1
cbo 1
dl 0
loc 60
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A newInstance() 0 4 1
A __construct() 0 7 1
A toStreamData() 0 9 1
1
<?php
2
namespace EventStore;
3
4
use EventStore\ValueObjects\Identity\UUID;
5
6
/**
7
 * Class WritableEvent
8
 * @package EventStore
9
 */
10
final class WritableEvent implements WritableToStream
11
{
12
    /**
13
     * @var UUID
14
     */
15
    private $uuid;
16
17
    /**
18
     * @var string
19
     */
20
    private $type;
21
22
    /**
23
     * @var array
24
     */
25
    private $data;
26
27
    /**
28
     * @var array
29
     */
30
    private $metadata;
31
32
    /**
33
     * @param  string        $type
34
     * @param  array         $data
35
     * @param  array         $metadata
36
     * @return WritableEvent
37
     */
38 22
    public static function newInstance($type, array $data, array $metadata = [])
39
    {
40 22
        return new self(new UUID(), $type, $data, $metadata);
41
    }
42
43
    /**
44
     * @param UUID   $uuid
45
     * @param string $type
46
     * @param array  $data
47
     * @param array  $metadata
48
     */
49 24
    public function __construct(UUID $uuid, $type, array $data, array $metadata = [])
50
    {
51 24
        $this->uuid = $uuid;
52 24
        $this->type = $type;
53 24
        $this->data = $data;
54 24
        $this->metadata = $metadata;
55 24
    }
56
57
    /**
58
     * @return array
59
     */
60 24
    public function toStreamData()
61
    {
62
        return [
63 24
            'eventId'   => $this->uuid->toNative(),
64 24
            'eventType' => $this->type,
65 24
            'data'      => $this->data,
66 24
            'metadata'  => $this->metadata
67
        ];
68
    }
69
}
70