| Conditions | 4 |
| Paths | 6 |
| Total Lines | 23 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | 4 | public function __invoke(ContainerInterface $container): EventDispatcherInterface |
|
| 17 | { |
||
| 18 | try { |
||
| 19 | 4 | $config = $container->get('config')['app-events']; |
|
| 20 | 3 | $listenerProvider = new ListenerProvider(); |
|
| 21 | 3 | foreach ($config['event-listeners'] ?? [] as $eventClass => $listeners) { |
|
| 22 | 2 | foreach ($listeners ?? [] as $listenerId) { |
|
| 23 | 1 | $listenerProvider->addListener( |
|
| 24 | 1 | $eventClass, |
|
| 25 | 1 | static function () use ($container, $listenerId): callable { |
|
| 26 | 1 | return $container->get($listenerId); |
|
| 27 | 1 | } |
|
| 28 | ); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | 3 | return new EventDispatcher($listenerProvider); |
|
| 33 | 1 | } catch (Throwable $exception) { |
|
| 34 | 1 | throw new RuntimeException(sprintf( |
|
| 35 | 'Something went wrong constructing an instance of %s, review config related to \'app-events\'' |
||
| 36 | 1 | . ' and see the previous exception for more info.', |
|
| 37 | 1 | EventDispatcher::class |
|
| 38 | 1 | ), 0, $exception); |
|
| 39 | } |
||
| 42 |