CenterSubscriber::handleMap()   A
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 11
cp 0
rs 9.3554
c 0
b 0
f 0
cc 5
nc 9
nop 1
crap 30
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Helper\Subscriber\Image;
13
14
use Ivory\GoogleMap\Base\Coordinate;
15
use Ivory\GoogleMap\Helper\Event\StaticMapEvent;
16
use Ivory\GoogleMap\Helper\Event\StaticMapEvents;
17
use Ivory\GoogleMap\Helper\Renderer\Image\Base\CoordinateRenderer;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class CenterSubscriber implements EventSubscriberInterface
24
{
25
    /**
26
     * @var CoordinateRenderer
27
     */
28
    private $coordinateRenderer;
29
30 4
    public function __construct(CoordinateRenderer $coordinateRenderer)
31
    {
32 4
        $this->coordinateRenderer = $coordinateRenderer;
33 4
    }
34
35
    public function handleMap(StaticMapEvent $event)
36
    {
37
        $map = $event->getMap();
38
39
        if ($map->hasStaticOption('center')) {
40
            $center = $map->getStaticOption('center');
41
        } elseif (!$map->isAutoZoom()) {
42
            $center = $map->getCenter();
43
        }
44
45
        if (isset($center)) {
46
            if ($center instanceof Coordinate) {
47
                $center = $this->coordinateRenderer->render($center);
48
            }
49
50
            $event->setParameter('center', $center);
51
        }
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 4
    public static function getSubscribedEvents()
58
    {
59 4
        return [StaticMapEvents::CENTER => 'handleMap'];
60
    }
61
}
62