Completed
Push — master ( 3c1d03...7e0a80 )
by Dmitry
14:29
created

EventAwareTrait::recordThat()   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 1
1
<?php
2
declare(strict_types=1);
3
4
namespace hiapi\event;
5
6
/**
7
 * Trait EventTrait
8
 *
9
 * @author Dmytro Naumenko <[email protected]>
10
 */
11
trait EventAwareTrait
12
{
13
    /**
14
     * @var EventInterface[]
15
     */
16
    private $events = [];
17
18
    /**
19
     * Registers that $event occurred
20
     * @param EventInterface $event
21
     */
22
    public function recordThat(EventInterface $event): void
23
    {
24
        $this->events[] = $event;
25
    }
26
27
    /**
28
     * @return EventInterface[] of occurred events
29
     */
30
    public function releaseEvents(): array
31
    {
32
        $events = $this->events;
33
        $this->events = [];
34
35
        return $events;
36
    }
37
}
38