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

MarkerStyleRenderer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 13
c 1
b 0
f 0
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B render() 0 21 9
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\Renderer\Image\Overlay;
15
16
use Ivory\GoogleMap\Base\Point;
17
use Ivory\GoogleMap\Helper\Renderer\Image\Base\PointRenderer;
18
use Ivory\GoogleMap\Overlay\Icon;
19
use Ivory\GoogleMap\Overlay\Marker;
20
21
class MarkerStyleRenderer extends AbstractStyleRenderer
22
{
23
    /** @var PointRenderer */
24
    private $pointRenderer;
25
26 7
    public function __construct(PointRenderer $pointRenderer)
27
    {
28 7
        $this->pointRenderer = $pointRenderer;
29 7
    }
30
31 6
    public function render(Marker $marker): ?string
32
    {
33 6
        $options = $marker->hasStaticOption('styles') ? $marker->getStaticOption('styles') : [];
34
35 6
        if ($marker->hasIcon()) {
36 1
            $icon = $marker->getIcon();
37
38 1
            if (!isset($options['icon']) && Icon::DEFAULT_URL !== ($url = $icon->getUrl())) {
39 1
                $options['icon'] = $url;
40
            }
41
42 1
            if (!isset($options['anchor']) && $icon->hasAnchor()) {
43 1
                $options['anchor'] = $icon->getAnchor();
44
            }
45
        }
46
47 6
        if (isset($options['anchor']) && $options['anchor'] instanceof Point) {
48 1
            $options['anchor'] = $this->pointRenderer->render($options['anchor']);
49
        }
50
51 6
        return $this->renderStyle($options);
52
    }
53
}
54