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

PlaceAutocompleteExtension   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 52
ccs 18
cts 20
cp 0.9
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getMapping() 0 6 1
A getFunctions() 0 9 2
A renderHtml() 0 5 1
A render() 0 5 1
A renderJavascript() 0 3 1
A __construct() 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\PlaceAutocompleteHelper;
17
use Ivory\GoogleMap\Place\Autocomplete;
18
use Twig\Extension\AbstractExtension;
19
use Twig\TwigFunction;
20
21
class PlaceAutocompleteExtension extends AbstractExtension
22
{
23
    /** @var PlaceAutocompleteHelper */
24
    private $placeAutocompleteHelper;
25
26 3
    public function __construct(PlaceAutocompleteHelper $placeAutocompleteHelper)
27
    {
28 3
        $this->placeAutocompleteHelper = $placeAutocompleteHelper;
29 3
    }
30
31
    /** {@inheritdoc} */
32 3
    public function getFunctions(): array
33
    {
34 3
        $functions = [];
35
36 3
        foreach ($this->getMapping() as $name => $method) {
37 3
            $functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]);
38
        }
39
40 3
        return $functions;
41
    }
42
43 1
    public function render(Autocomplete $autocomplete, array $attributes = []): string
44
    {
45 1
        $autocomplete->addInputAttributes($attributes);
46
47 1
        return $this->placeAutocompleteHelper->render($autocomplete);
48
    }
49
50 1
    public function renderHtml(Autocomplete $autocomplete, array $attributes = []): string
51
    {
52 1
        $autocomplete->addInputAttributes($attributes);
53
54 1
        return $this->placeAutocompleteHelper->renderHtml($autocomplete);
55
    }
56
57 1
    public function renderJavascript(Autocomplete $autocomplete): string
58
    {
59 1
        return $this->placeAutocompleteHelper->renderJavascript($autocomplete);
60
    }
61
62
    public function getName(): string
63
    {
64
        return 'ivory_google_place_autocomplete';
65
    }
66
67 3
    private function getMapping(): array
68
    {
69
        return [
70 3
            'ivory_google_place_autocomplete' => 'render',
71
            'ivory_google_place_autocomplete_container' => 'renderHtml',
72
            'ivory_google_place_autocomplete_js' => 'renderJavascript',
73
        ];
74
    }
75
}
76