StyleSubscriber::handleMap()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 10
cp 0
rs 9.6666
c 0
b 0
f 0
cc 4
nc 5
nop 1
crap 20
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\Event\StaticMapEvent;
15
use Ivory\GoogleMap\Helper\Event\StaticMapEvents;
16
use Ivory\GoogleMap\Helper\Renderer\Image\StyleRenderer;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
19
/**
20
 * @author GeLo <[email protected]>
21
 */
22
class StyleSubscriber implements EventSubscriberInterface
23
{
24
    /**
25
     * @var StyleRenderer
26
     */
27
    private $styleRenderer;
28
29 4
    public function __construct(StyleRenderer $styleRenderer)
30
    {
31 4
        $this->styleRenderer = $styleRenderer;
32 4
    }
33
34
    public function handleMap(StaticMapEvent $event)
35
    {
36
        $map = $event->getMap();
37
38
        if (!$map->hasMapOption('styles')) {
39
            return;
40
        }
41
42
        $styles = [];
43
44
        foreach ($map->getStaticOption('styles') as $style) {
45
            $styles[] = $this->styleRenderer->render($style);
46
        }
47
48
        if (!empty($styles)) {
49
            $event->setParameter('style', $styles);
50
        }
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 4
    public static function getSubscribedEvents()
57
    {
58 4
        return [StaticMapEvents::STYLE => 'handleMap'];
59
    }
60
}
61