EventAwareTrait::releaseEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * PHP Billing Library
6
 *
7
 * @link      https://github.com/hiqdev/php-billing
8
 * @package   php-billing
9
 * @license   BSD-3-Clause
10
 * @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
11
 */
12
13
namespace hiqdev\php\billing\event;
14
15
use League\Event\EventInterface;
16
17
/**
18
 * Trait EventTrait
19
 *
20
 * @author Dmytro Naumenko <[email protected]>
21
 */
22
trait EventAwareTrait
23
{
24
    /**
25
     * @var EventInterface[]
26
     */
27
    private $events = [];
28
29
    /**
30
     * Registers that $event occurred
31
     */
32
    public function recordThat(EventInterface $event): void
33
    {
34
        $this->events[] = $event;
35
    }
36
37
    /**
38
     * @return EventInterface[] of occurred events
39
     */
40
    public function releaseEvents(): array
41
    {
42
        $events = $this->events;
43
        $this->events = [];
44
45
        return $events;
46
    }
47
48
    public function hasEvents(): bool
49
    {
50
        return !empty($this->events);
51
    }
52
}
53