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

MapExtension   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 58
ccs 20
cts 22
cp 0.9091
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A renderJavascript() 0 3 1
A renderHtml() 0 5 1
A getName() 0 3 1
A render() 0 5 1
A renderStylesheet() 0 3 1
A __construct() 0 3 1
A getFunctions() 0 9 2
A getMapping() 0 7 1
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