EventRecordingCapabilities::recordThat()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
    /**
13
     * @var object[]
14
     */
15
    private $events = [];
16
17
    /**
18
     * Use this method inside your aggregate to record new domain events.
19
     */
20 26
    protected function recordThat(object $event): void
21
    {
22 26
        $this->events[] = $event;
23 26
    }
24
25
    /**
26
     * @see \TalisOrm\Aggregate::releaseEvents()
27
     * @return object[]
28
     */
29 25
    public function releaseEvents(): array
30
    {
31 25
        $events = $this->events;
32
33 25
        $this->events = [];
34
35 25
        return $events;
36
    }
37
}
38