Completed
Pull Request — master (#340)
by Luc
11:03
created

AbstractGeoCoordinatesProcessManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
getEventHandlers() 0 1 ?
A handle() 0 11 2
1
<?php
2
3
namespace CultuurNet\UDB3\Offer;
4
5
use Broadway\CommandHandling\CommandBusInterface;
6
use Broadway\Domain\DomainMessage;
7
use Broadway\EventHandling\EventListenerInterface;
8
use CultuurNet\UDB3\Address\CultureFeedAddressFactoryInterface;
9
use Psr\Log\LoggerInterface;
10
11
abstract class AbstractGeoCoordinatesProcessManager implements EventListenerInterface
12
{
13
    /**
14
     * @var CommandBusInterface
15
     */
16
    protected $commandBus;
17
18
    /**
19
     * @var CultureFeedAddressFactoryInterface
20
     */
21
    protected $addressFactory;
22
23
    /**
24
     * @var LoggerInterface
25
     */
26
    protected $logger;
27
28
    /**
29
     * @param CommandBusInterface $commandBus
30
     * @param CultureFeedAddressFactoryInterface $addressFactory
31
     * @param LoggerInterface $logger
32
     */
33
    public function __construct(
34
        CommandBusInterface $commandBus,
35
        CultureFeedAddressFactoryInterface $addressFactory,
36
        LoggerInterface $logger
37
    ) {
38
        $this->commandBus = $commandBus;
39
        $this->addressFactory = $addressFactory;
40
        $this->logger = $logger;
41
    }
42
43
    protected abstract function getEventHandlers();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
44
45
    /**
46
     * @param DomainMessage $domainMessage
47
     */
48
    public function handle(DomainMessage $domainMessage)
49
    {
50
        $payload = $domainMessage->getPayload();
51
        $className = get_class($payload);
52
        $eventHandlers = $this->getEventHandlers();
53
54
        if (isset($eventHandlers[$className])) {
55
            $eventHandler = $eventHandlers[$className];
56
            call_user_func([$this, $eventHandler], $payload);
57
        }
58
    }
59
}