Completed
Push — master ( bbb956...f4fb75 )
by Julián
01:28 queued 11s
created

EventBehaviour::getRecordedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * aggregate (https://github.com/phpgears/aggregate).
5
 * Aggregate base.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/aggregate
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Aggregate;
15
16
use Gears\Event\Event;
17
use Gears\Event\EventArrayCollection;
18
use Gears\Event\EventCollection;
19
20
/**
21
 * Recorded events trait.
22
 */
23
trait EventBehaviour
24
{
25
    /**
26
     * @var Event[]
27
     */
28
    private $recordedEvents = [];
29
30
    /**
31
     * Record event.
32
     *
33
     * @param Event $event
34
     */
35
    final protected function recordEvent(Event $event): void
36
    {
37
        $this->recordedEvents[] = $event;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    final public function getRecordedEvents(): EventCollection
44
    {
45
        return new EventArrayCollection($this->recordedEvents);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    final public function clearRecordedEvents(): void
52
    {
53
        $this->recordedEvents = [];
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    final public function collectRecordedEvents(): EventCollection
60
    {
61
        $events = new EventArrayCollection($this->recordedEvents);
62
63
        $this->recordedEvents = [];
64
65
        return $events;
66
    }
67
}
68