EventManager::emit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPExtra\EventManager;
6
7
final class EventManager implements EventEmitter
8
{
9
    /**
10
     * @var array
11
     */
12
    private $listeners = [];
13
14
    /**
15
     * @var Notifier
16
     */
17
    private $notifier;
18
19
    public function __construct()
20
    {
21
        $this->notifier = new Notifier();
22
    }
23
24
    public function emit(Event $event): void
25
    {
26
        foreach ($this->listeners as $listener) {
27
            $this->notifier->notify($listener, $event);
28
        }
29
    }
30
31
    public function add(Listener $listener): void
32
    {
33
        $this->listeners[] = $listener;
34
    }
35
}
36