EventDispatcher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatchEvent() 0 5 3
A registerListener() 0 3 1
1
<?php
2
3
namespace TwoDojo\ModuleManager\Support;
4
5
use TwoDojo\Module\Contracts\EventListener;
6
7
class EventDispatcher
8
{
9
    protected $listeners = [];
10
11
    public function registerListener(EventListener $listener)
12
    {
13
        $this->listeners[] = $listener;
14
    }
15
16
    /**
17
     * Dispatch an event
18
     *
19
     * @param string $group
20
     * @param string $event
21
     * @param array $arguments
22
     */
23
    public function dispatchEvent(string $group, string $event, array $arguments = [])
24
    {
25
        foreach ($this->listeners as $listener) {
26
            if ($listener->getEventGroup() === $group) {
27
                $listener->onEventReceived($event, $arguments);
28
            }
29
        }
30
    }
31
}
32