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

ApiExtension   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 __construct() 0 3 1
A getMapping() 0 3 1
A render() 0 3 1
A getFunctions() 0 9 2
A getName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Ivory Google Api 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\ApiHelper;
17
use Twig\Extension\AbstractExtension;
18
use Twig\TwigFunction;
19
20
class ApiExtension extends AbstractExtension
21
{
22
    /** @var ApiHelper */
23
    private $apiHelper;
24
25 1
    public function __construct(ApiHelper $apiHelper)
26
    {
27 1
        $this->apiHelper = $apiHelper;
28 1
    }
29
30
    /** {@inheritdoc} */
31 1
    public function getFunctions(): array
32
    {
33 1
        $functions = [];
34
35 1
        foreach ($this->getMapping() as $name => $method) {
36 1
            $functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]);
37
        }
38
39 1
        return $functions;
40
    }
41
42 1
    public function render(array $objects): string
43
    {
44 1
        return $this->apiHelper->render($objects);
45
    }
46
47
    public function getName(): string
48
    {
49
        return 'ivory_google_api';
50
    }
51
52 1
    private function getMapping(): array
53
    {
54 1
        return ['ivory_google_api' => 'render'];
55
    }
56
}
57