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

ListenerProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 48
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A provideListener() 0 7 2
A getEventListenerList() 0 3 1
A getEventListenerFromClass() 0 3 1
A __construct() 0 3 1
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
}