EventRecorderCapabilities   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A releaseEvents() 0 6 1
A record() 0 4 1
A clear() 0 3 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\Contracts\EventInterface;
14
15
trait EventRecorderCapabilities
16
{
17
    /**
18
     * @var EventInterface[]
19
     */
20
    private $recordedEvents;
21
22
    /**
23
     * @return mixed
24
     */
25
    public function clear()
26
    {
27
        $this->recordedEvents = [];
28
    }
29
30
    /**
31
     * @param EventInterface $event
32
     *
33
     * @return mixed
34
     */
35
    public function record(EventInterface $event)
36
    {
37
        $eventUuid = $event->uuid();
38
        $this->recordedEvents[(string) $eventUuid] = $event;
39
    }
40
41
    /**
42
     * @return EventInterface[]
43
     */
44
    public function releaseEvents()
45
    {
46
        $events = $this->recordedEvents;
47
        $this->clear();
48
49
        return $events;
50
    }
51
}
52