EventManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 29
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A emit() 0 6 2
A add() 0 4 1
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