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

MarkerRenderer::render()   A

Complexity

Conditions 6
Paths 24

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 6

Importance

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