MarkerRenderer::getAnimationRenderer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Overlay;
13
14
use Ivory\GoogleMap\Helper\Formatter\Formatter;
15
use Ivory\GoogleMap\Helper\Renderer\AbstractJsonRenderer;
16
use Ivory\GoogleMap\Map;
17
use Ivory\GoogleMap\Overlay\Marker;
18
use Ivory\JsonBuilder\JsonBuilder;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class MarkerRenderer extends AbstractJsonRenderer
24
{
25
    /**
26
     * @var AnimationRenderer
27
     */
28
    private $animationRenderer;
29
30 24
    public function __construct(
31
        Formatter $formatter,
32
        JsonBuilder $jsonBuilder,
33
        AnimationRenderer $animationRenderer
34
    ) {
35 24
        parent::__construct($formatter, $jsonBuilder);
36
37 24
        $this->setAnimationRenderer($animationRenderer);
38 24
    }
39
40
    /**
41
     * @return AnimationRenderer
42
     */
43 4
    public function getAnimationRenderer()
44
    {
45 4
        return $this->animationRenderer;
46
    }
47
48 24
    public function setAnimationRenderer(AnimationRenderer $animationRenderer)
49
    {
50 24
        $this->animationRenderer = $animationRenderer;
51 24
    }
52
53
    /**
54
     * @return string
55
     */
56 12
    public function render(Marker $marker, Map $map = null)
57
    {
58 12
        $formatter = $this->getFormatter();
59 12
        $jsonBuilder = $this->getJsonBuilder()
60 12
            ->setValue('[position]', $marker->getPosition()->getVariable(), false);
61
62 12
        if (null !== $map) {
63 8
            $jsonBuilder->setValue('[map]', $map->getVariable(), false);
64
        }
65
66 12
        if ($marker->hasAnimation()) {
67 8
            $jsonBuilder->setValue(
68 8
                '[animation]',
69 8
                $this->animationRenderer->render($marker->getAnimation()),
70 8
                false
71
            );
72
        }
73
74 12
        if ($marker->hasIcon()) {
75 4
            $jsonBuilder->setValue('[icon]', $marker->getIcon()->getVariable(), false);
76 8
        } elseif ($marker->hasSymbol()) {
77 4
            $jsonBuilder->setValue('[icon]', $marker->getSymbol()->getVariable(), false);
78
        }
79
80 12
        if ($marker->hasShape()) {
81 8
            $jsonBuilder->setValue('[shape]', $marker->getShape()->getVariable(), false);
82
        }
83
84 12
        $jsonBuilder->setValues($marker->getOptions());
85
86 12
        return $formatter->renderObjectAssignment($marker, $formatter->renderObject('Marker', [
87 12
            $jsonBuilder->build(),
88
        ]));
89
    }
90
}
91