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

ImmutableEventDispatcherFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 14
rs 10
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