Completed
Push — master ( 77f666...54a2d4 )
by Mike
03:21
created

ListenerProvider::provideListener()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Xervice\Event\Business\Model\Listener;
5
6
7
use DataProvider\EventDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\EventDataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Xervice\Event\Communication\Plugin\Listener\EventListenerInterface;
9
10
class ListenerProvider implements ListenerProviderInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $listener;
16
17
    /**
18
     * ListenerProvider constructor.
19
     *
20
     * @param array $listener
21
     */
22 2
    public function __construct(array $listener)
23
    {
24 2
        $this->listener = $listener;
25 2
    }
26
27
    /**
28
     * @param \DataProvider\EventDataProvider $eventDataProvider
29
     */
30 2
    public function provideListener(EventDataProvider $eventDataProvider): void
31
    {
32 2
        $eventName = $eventDataProvider->getName();
33
34 2
        foreach ($this->getEventListenerList($eventName) as $listener) {
35 2
            $listener = $this->getEventListenerFromClass($listener);
36 2
            $listener->handleEvent($eventDataProvider);
37
        }
38 2
    }
39
40
    /**
41
     * @param string $listenerClass
42
     *
43
     * @return \Xervice\Event\Communication\Plugin\Listener\EventListenerInterface
44
     */
45 2
    private function getEventListenerFromClass(string $listenerClass): EventListenerInterface
46
    {
47 2
        return new $listenerClass();
48
    }
49
50
    /**
51
     * @param string $eventName
52
     *
53
     * @return string[]
54
     */
55 2
    private function getEventListenerList(string $eventName): array
56
    {
57 2
        return $this->listener[$eventName] ?? [];
58
    }
59
}