Passed
Pull Request — master (#1)
by Alex
02:05
created

ImmutableEventDispatcherFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 25
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasEvent\Factory;
6
7
use Arp\EventDispatcher\ImmutableEventDispatcher;
8
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
9
use Laminas\ServiceManager\ServiceLocatorInterface;
10
use Psr\Container\ContainerInterface;
11
use Psr\EventDispatcher\ListenerProviderInterface;
12
13
/**
14
 * @author  Alex Patterson <[email protected]>
15
 * @package Arp\LaminasEvent\Factory
16
 */
17
final class ImmutableEventDispatcherFactory extends AbstractEventDispatcherFactory
18
{
19
    /**
20
     * @param ContainerInterface&ServiceLocatorInterface $container
21
     * @param string                                     $requestedName
22
     * @param array<mixed>|null                          $options
23
     *
24
     * @return ImmutableEventDispatcher
25
     *
26
     * @throws ServiceNotCreatedException
27
     */
28
    public function __invoke(
29
        ContainerInterface $container,
30
        string $requestedName,
31
        array $options = null
32
    ): ImmutableEventDispatcher {
33
        $options = $options ?? $this->getServiceOptions($container, $requestedName, 'event_dispatchers');
34
35
        $listenerProvider = $this->getListenerProvider(
36
            $container,
37
            $options['listener_provider'] ?? ListenerProviderInterface::class,
38
            $requestedName
39
        );
40
41
        return new ImmutableEventDispatcher($listenerProvider);
42
    }
43
}
44