EventAwareTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 29
ccs 0
cts 7
cp 0
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

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