ManualEventSubscriber   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 37
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A subscribeToEvent() 0 4 1
A getListenersForEvent() 0 16 3
A getMethodName() 0 6 1
1
<?php
2
/******************************************************************************
3
 * Copyright (c) 2016 Constantin Galbenu <[email protected]>             *
4
 ******************************************************************************/
5
6
namespace Gica\Cqrs\Event\EventSubscriber;
7
8
9
use Gica\Cqrs\Event\EventSubscriber;
10
11
class ManualEventSubscriber implements EventSubscriber
12
{
13
    private $eventListeners = [];
14
15 1
    public function subscribeToEvent($listener)
16
    {
17 1
        $this->eventListeners[] = $listener;
18 1
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23 5
    public function getListenersForEvent($event)
24
    {
25 5
        $result = [];
26
27 5
        foreach ($this->eventListeners as $eventListener) {
28 1
            $methodName = $this->getMethodName($event);
29
30 1
            $method = [$eventListener, $methodName];
31
32 1
            if (is_callable($method)) {
33 1
                $result[] = $method;
34
            }
35
        }
36
37 5
        return $result;
38
    }
39
40 1
    private function getMethodName($event)
41
    {
42 1
        $parts = explode('\\', get_class($event));
43
44 1
        return 'handle' . end($parts);
45
    }
46
47
}