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

EventAwareTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

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