Passed
Push — master ( 4efef9...68b614 )
by Matthias
03:31
created

EventRecordingCapabilities::recordThat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TalisOrm\DomainEvents;
4
5
/**
6
 * Use this trait to prevent code duplication in any aggregate that implements RecordsEvents.
7
 *
8
 * @see \TalisOrm\Aggregate::releaseEvents()
9
 */
10
trait EventRecordingCapabilities
11
{
12
    private $events = [];
13
14
    /**
15
     * Use this method inside your aggregate to record new domain events.
16
     */
17 24
    protected function recordThat(object $event): void
18
    {
19 24
        $this->events[] = $event;
20 24
    }
21
22
    /**
23
     * @see \TalisOrm\Aggregate::releaseEvents()
24
     * @return object[]
25
     */
26 23
    public function releaseEvents(): array
27
    {
28 23
        $events = $this->events;
29
30 23
        $this->events = [];
31
32 23
        return $events;
33
    }
34
}
35