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

StyleSubscriber::handleMap()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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