ExtendableSubscriber   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 35.29%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 47
ccs 6
cts 17
cp 0.3529
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handleMap() 0 20 5
A getSubscribedEvents() 0 4 1
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\Helper\Collector\Image\ExtendableCollector;
15
use Ivory\GoogleMap\Helper\Event\StaticMapEvent;
16
use Ivory\GoogleMap\Helper\Event\StaticMapEvents;
17
use Ivory\GoogleMap\Helper\Renderer\Image\Overlay\ExtendableRenderer;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class ExtendableSubscriber implements EventSubscriberInterface
24
{
25
    /**
26
     * @var ExtendableCollector
27
     */
28
    private $extendableCollector;
29
30
    /**
31
     * @var ExtendableRenderer
32
     */
33
    private $extendableRenderer;
34
35 4
    public function __construct(ExtendableCollector $extendableCollector, ExtendableRenderer $extendableRenderer)
36
    {
37 4
        $this->extendableCollector = $extendableCollector;
38 4
        $this->extendableRenderer = $extendableRenderer;
39 4
    }
40
41
    public function handleMap(StaticMapEvent $event)
42
    {
43
        $map = $event->getMap();
44
45
        if (!$map->isAutoZoom()) {
46
            return;
47
        }
48
49
        $extendables = $map->hasStaticOption('visible') ? $map->getStaticOption('visible') : [];
50
51
        if (!is_array($extendables)) {
52
            $extendables = [$extendables];
53
        }
54
55
        $extendables = $this->extendableCollector->collect($map, $extendables);
56
57
        if (!empty($extendables)) {
58
            $event->setParameter('visible', $this->extendableRenderer->render($extendables));
59
        }
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 4
    public static function getSubscribedEvents()
66
    {
67 4
        return [StaticMapEvents::EXTENDABLE => 'handleMap'];
68
    }
69
}
70