MapExtension::renderJavascript()   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 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map bundle 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\GoogleMapBundle\Twig;
13
14
use Ivory\GoogleMap\Helper\MapHelper;
15
use Ivory\GoogleMap\Map;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class MapExtension extends \Twig_Extension
21
{
22
    /**
23
     * @var MapHelper
24
     */
25
    private $mapHelper;
26
27
    /**
28
     * @param MapHelper $mapHelper
29
     */
30 4
    public function __construct(MapHelper $mapHelper)
31
    {
32 4
        $this->mapHelper = $mapHelper;
33 4
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 4
    public function getFunctions()
39
    {
40 4
        $functions = [];
41
42 4
        foreach ($this->getMapping() as $name => $method) {
43 4
            $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]);
44
        }
45
46 4
        return $functions;
47
    }
48
49
    /**
50
     * @param Map      $map
51
     * @param string[] $attributes
52
     *
53
     * @return string
54
     */
55 1
    public function render(Map $map, array $attributes = [])
56
    {
57 1
        $map->addHtmlAttributes($attributes);
58
59 1
        return $this->mapHelper->render($map);
60
    }
61
62
    /**
63
     * @param Map      $map
64
     * @param string[] $attributes
65
     *
66
     * @return string
67
     */
68 1
    public function renderHtml(Map $map, array $attributes = [])
69
    {
70 1
        $map->addHtmlAttributes($attributes);
71
72 1
        return $this->mapHelper->renderHtml($map);
73
    }
74
75
    /**
76
     * @param Map $map
77
     *
78
     * @return string
79
     */
80 1
    public function renderStylesheet(Map $map)
81
    {
82 1
        return $this->mapHelper->renderStylesheet($map);
83
    }
84
85
    /**
86
     * @param Map $map
87
     *
88
     * @return string
89
     */
90 1
    public function renderJavascript(Map $map)
91
    {
92 1
        return $this->mapHelper->renderJavascript($map);
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98 4
    public function getName()
99
    {
100 4
        return 'ivory_google_map';
101
    }
102
103
    /**
104
     * @return string[]
105
     */
106 4
    private function getMapping()
107
    {
108
        return [
109 4
            'ivory_google_map'           => 'render',
110
            'ivory_google_map_container' => 'renderHtml',
111
            'ivory_google_map_css'       => 'renderStylesheet',
112
            'ivory_google_map_js'        => 'renderJavascript',
113
        ];
114
    }
115
}
116