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

StaticMapExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 35
ccs 12
cts 14
cp 0.8571
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMapping() 0 3 1
A getFunctions() 0 9 2
A __construct() 0 3 1
A render() 0 3 1
A getName() 0 3 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\StaticMapHelper;
17
use Ivory\GoogleMap\Map;
18
use Twig\Extension\AbstractExtension;
19
use Twig\TwigFunction;
20
21
class StaticMapExtension extends AbstractExtension
22
{
23
    /** @var StaticMapHelper */
24
    private $staticMapHelper;
25
26 1
    public function __construct(StaticMapHelper $staticMapHelper)
27
    {
28 1
        $this->staticMapHelper = $staticMapHelper;
29 1
    }
30
31
    /** {@inheritdoc} */
32 1
    public function getFunctions(): array
33
    {
34 1
        $functions = [];
35
36 1
        foreach ($this->getMapping() as $name => $method) {
37 1
            $functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]);
38
        }
39
40 1
        return $functions;
41
    }
42
43 1
    public function render(Map $map): string
44
    {
45 1
        return $this->staticMapHelper->render($map);
46
    }
47
48
    public function getName(): string
49
    {
50
        return 'ivory_google_map_static';
51
    }
52
53 1
    private function getMapping(): array
54
    {
55 1
        return ['ivory_google_map_static' => 'render'];
56
    }
57
}
58