EventRecorderCapabilities::eraseEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace BornFree\TacticianDomainEvent\Recorder;
4
5
/**
6
 * Use this trait in classes which implement ContainsRecordedEvents to record and later release events.
7
 */
8
trait EventRecorderCapabilities
9
{
10
    /**
11
     * @var array
12
     */
13
    private $recordedEvents = [];
14
15
    /**
16
     * Release and clear recorded events
17
     *
18
     * @return array
19
     */
20
    public function releaseEvents()
21
    {
22
        $events = $this->recordedEvents;
23
24
        $this->recordedEvents = [];
25
26
        return $events;
27
    }
28
29
    /**
30
     * Erase all events
31
     */
32
    public function eraseEvents()
33
    {
34
        $this->recordedEvents = [];
35
    }
36
37
    /**
38
     * Record an event.
39
     *
40
     * @param mixed $event
41
     */
42
    protected function record($event)
43
    {
44
        $this->recordedEvents[] = $event;
45
    }
46
}
47