Completed
Pull Request — master (#436)
by
unknown
03:28
created

dispatchUpdateGeoCoordinatesCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace CultuurNet\UDB3\Organizer\Manager;
4
5
use Broadway\Domain\DomainMessage;
6
use Broadway\EventHandling\EventListenerInterface;
7
use Broadway\CommandHandling\CommandBusInterface;
8
use CultuurNet\UDB3\Organizer\Commands\UpdateGeoCoordinatesFromAddress;
9
use CultuurNet\UDB3\Organizer\Events\AddressUpdated;
10
11
class GeoCoordinatesProcessManager implements EventListenerInterface
12
{
13
    /**
14
     * @var CommandBusInterface
15
     */
16
    private $commandBus;
17
18
    public function __construct(CommandBusInterface $commandBus)
19
    {
20
        $this->commandBus = $commandBus;
21
    }
22
23
    public function handle(DomainMessage $domainMessage)
24
    {
25
        $event = $domainMessage->getPayload();
26
27
        if ($event instanceof AddressUpdated) {
28
            $this->dispatchUpdateGeoCoordinatesCommand($event);
29
        }
30
    }
31
32
    public function dispatchUpdateGeoCoordinatesCommand(AddressUpdated $event): void
33
    {
34
        $this->commandBus->dispatch(
35
            new UpdateGeoCoordinatesFromAddress(
36
                $event->getOrganizerId(),
37
                $event->getAddress()
38
            )
39
        );
40
    }
41
}
42