Passed
Branch issue/#1 (79b692)
by Koldo
02:14
created

EventDispatcherFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Event\Container;
6
7
use Antidot\Event\EventDispatcher;
8
use Antidot\Event\EventInterface;
9
use Antidot\Event\ListenerProvider;
10
use Psr\Container\ContainerInterface;
11
use Psr\EventDispatcher\EventDispatcherInterface;
12
13
class EventDispatcherFactory
14
{
15 1
    public function __invoke(ContainerInterface $container): EventDispatcherInterface
16
    {
17 1
        $config = $container->get('config')['app-events'];
18 1
        $listenerProvider = new ListenerProvider();
19
20 1
        foreach ($config['event-listeners'] as $eventName => $listeners) {
21 1
            foreach ($listeners as $listenerId) {
22 1
                $listenerProvider->addListener(
23 1
                    $eventName,
24
                    static function () use ($container, $listenerId): callable {
25 1
                        return $container->get($listenerId);
26 1
                    }
27
                );
28
            }
29
        }
30
31 1
        return new EventDispatcher($listenerProvider);
32
    }
33
}
34