Passed
Push — feature/v4 ( e5e380...dac4aa )
by Samuel
11:37
created

ExtendableSubscriber   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 35.29%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 15
c 1
b 0
f 0
dl 0
loc 39
ccs 6
cts 17
cp 0.3529
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 3 1
A handleMap() 0 18 5
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Ivory Google Map package.
7
 *
8
 * (c) Eric GELOEN <[email protected]>
9
 *
10
 * For the full copyright and license information, please read the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ivory\GoogleMap\Helper\Subscriber\Image;
15
16
use Ivory\GoogleMap\Helper\Collector\Image\ExtendableCollector;
17
use Ivory\GoogleMap\Helper\Event\StaticMapEvent;
18
use Ivory\GoogleMap\Helper\Event\StaticMapEvents;
19
use Ivory\GoogleMap\Helper\Renderer\Image\Overlay\ExtendableRenderer;
20
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
21
22
class ExtendableSubscriber implements EventSubscriberInterface
23
{
24
    /** @var ExtendableCollector */
25
    private $extendableCollector;
26
27
    /** @var ExtendableRenderer */
28
    private $extendableRenderer;
29
30 1
    public function __construct(ExtendableCollector $extendableCollector, ExtendableRenderer $extendableRenderer)
31
    {
32 1
        $this->extendableCollector = $extendableCollector;
33 1
        $this->extendableRenderer  = $extendableRenderer;
34 1
    }
35
36
    public function handleMap(StaticMapEvent $event): void
37
    {
38
        $map = $event->getMap();
39
40
        if (!$map->isAutoZoom()) {
41
            return;
42
        }
43
44
        $extendables = $map->hasStaticOption('visible') ? $map->getStaticOption('visible') : [];
45
46
        if (!is_array($extendables)) {
47
            $extendables = [$extendables];
48
        }
49
50
        $extendables = $this->extendableCollector->collect($map, $extendables);
51
52
        if (!empty($extendables)) {
53
            $event->setParameter('visible', $this->extendableRenderer->render($extendables));
54
        }
55
    }
56
57
    /** {@inheritdoc} */
58 1
    public static function getSubscribedEvents(): array
59
    {
60 1
        return [StaticMapEvents::EXTENDABLE => 'handleMap'];
61
    }
62
}
63