EventRecorder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 3 1
A clear() 0 3 1
A releaseEvents() 0 6 1
A record() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Simple EventStore Manager package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace SimpleEventStoreManager\Domain\EventRecorder;
12
13
use SimpleEventStoreManager\Domain\Model\Event;
14
use SimpleEventStoreManager\Domain\Model\AggregateUuid;
15
use SimpleEventStoreManager\Domain\EventRecorder\Contracts\EventRecorderInterface;
16
17
class EventRecorder implements EventRecorderInterface
18
{
19
    /**
20
     * @var Event[]
21
     */
22
    private $recordedEvents;
23
24
    /**
25
     * @return mixed
26
     */
27
    public function clear()
28
    {
29
        $this->recordedEvents = [];
30
    }
31
32
    /**
33
     * @param AggregateUuid $eventUuid
34
     * @return mixed
35
     */
36
    public function delete(AggregateUuid $eventUuid)
37
    {
38
        unset($this->recordedEvents[(string) $eventUuid]);
39
    }
40
41
    /**
42
     * @param Event $event
43
     *
44
     * @return mixed
45
     */
46
    public function record(Event $event)
47
    {
48
        $eventUuid = $event->uuid();
49
        $this->recordedEvents[(string) $eventUuid] = $event;
50
    }
51
52
    /**
53
     * @return Event[]
54
     */
55
    public function releaseEvents()
56
    {
57
        $events = $this->recordedEvents;
58
        $this->clear();
59
60
        return $events;
61
    }
62
}
63