Passed
Push — feature/v4 ( 2fc063...abe85a )
by Samuel
05:52
created

MapExtension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Ivory Google Map bundle 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\GoogleMapBundle\Twig;
15
16
use Ivory\GoogleMap\Helper\MapHelper;
17
use Ivory\GoogleMap\Map;
18
use Twig\Extension\AbstractExtension;
19
use Twig\TwigFunction;
20
21
class MapExtension extends AbstractExtension
22
{
23
    /** @var MapHelper */
24
    private $mapHelper;
25
26 4
    public function __construct(MapHelper $mapHelper)
27
    {
28 4
        $this->mapHelper = $mapHelper;
29 4
    }
30
31
    /** {@inheritdoc} */
32 4
    public function getFunctions(): array
33
    {
34 4
        $functions = [];
35
36 4
        foreach ($this->getMapping() as $name => $method) {
37 4
            $functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]);
38
        }
39
40 4
        return $functions;
41
    }
42
43 1
    public function render(Map $map, array $attributes = []): string
44
    {
45 1
        $map->addHtmlAttributes($attributes);
46
47 1
        return $this->mapHelper->render($map);
48
    }
49
50 1
    public function renderHtml(Map $map, array $attributes = []): string
51
    {
52 1
        $map->addHtmlAttributes($attributes);
53
54 1
        return $this->mapHelper->renderHtml($map);
55
    }
56
57 1
    public function renderStylesheet(Map $map): string
58
    {
59 1
        return $this->mapHelper->renderStylesheet($map);
60
    }
61
62 1
    public function renderJavascript(Map $map): string
63
    {
64 1
        return $this->mapHelper->renderJavascript($map);
65
    }
66
67
    public function getName(): string
68
    {
69
        return 'ivory_google_map';
70
    }
71
72 4
    private function getMapping(): array
73
    {
74
        return [
75 4
            'ivory_google_map' => 'render',
76
            'ivory_google_map_container' => 'renderHtml',
77
            'ivory_google_map_css' => 'renderStylesheet',
78
            'ivory_google_map_js' => 'renderJavascript',
79
        ];
80
    }
81
}
82