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

StyleSubscriber   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 33
ccs 5
cts 15
cp 0.3333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 3 1
A handleMap() 0 16 4
A __construct() 0 3 1
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