Completed
Push — master ( b87198...f2f319 )
by Frank
02:38
created

EventRecordingBehaviour::recordThat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace EventSauce\EventSourcing\AggregateRootBehaviour;
4
5
use EventSauce\EventSourcing\Event;
6
7
trait EventRecordingBehaviour
8
{
9
    /**
10
     * @var Event[]
11
     */
12
    private $recordedEvents = [];
13
14 3
    protected function recordThat(Event $event)
15
    {
16 3
        $this->apply($event);
17 3
        $this->recordedEvents[] = $event;
18 3
    }
19
20
    /**
21
     * @return Event[]
22
     */
23 7
    public function releaseEvents(): array
24
    {
25 7
        $releasedEvents = $this->recordedEvents;
26 7
        $this->recordedEvents = [];
27
28 7
        return $releasedEvents;
29
    }
30
31
    abstract protected function apply(Event $event);
32
}