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

EventRecordingBehaviour   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 26
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A recordThat() 0 5 1
A releaseEvents() 0 7 1
apply() 0 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
}