MarkerStyleRenderer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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\Renderer\Image\Overlay;
13
14
use Ivory\GoogleMap\Base\Point;
15
use Ivory\GoogleMap\Helper\Renderer\Image\Base\PointRenderer;
16
use Ivory\GoogleMap\Overlay\Icon;
17
use Ivory\GoogleMap\Overlay\Marker;
18
19
/**
20
 * @author GeLo <[email protected]>
21
 */
22
class MarkerStyleRenderer extends AbstractStyleRenderer
23
{
24
    /**
25
     * @var PointRenderer
26
     */
27
    private $pointRenderer;
28
29 28
    public function __construct(PointRenderer $pointRenderer)
30
    {
31 28
        $this->pointRenderer = $pointRenderer;
32 28
    }
33
34
    /**
35
     * @return string
36
     */
37 24
    public function render(Marker $marker)
38
    {
39 24
        $options = $marker->hasStaticOption('styles') ? $marker->getStaticOption('styles') : [];
40
41 24
        if ($marker->hasIcon()) {
42 4
            $icon = $marker->getIcon();
43
44 4
            if (!isset($options['icon']) && Icon::DEFAULT_URL !== ($url = $icon->getUrl())) {
45 4
                $options['icon'] = $url;
46
            }
47
48 4
            if (!isset($options['anchor']) && $icon->hasAnchor()) {
49 4
                $options['anchor'] = $icon->getAnchor();
50
            }
51
        }
52
53 24
        if (isset($options['anchor']) && $options['anchor'] instanceof Point) {
54 4
            $options['anchor'] = $this->pointRenderer->render($options['anchor']);
55
        }
56
57 24
        return $this->renderStyle($options);
58
    }
59
}
60