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

MarkerStyleRenderer::render()   B

Complexity

Conditions 9
Paths 20

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 8.0555
cc 9
nc 20
nop 1
crap 9
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