PlaceAutocompleteExtension::renderHtml()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map bundle package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMapBundle\Twig;
13
14
use Ivory\GoogleMap\Helper\PlaceAutocompleteHelper;
15
use Ivory\GoogleMap\Place\Autocomplete;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class PlaceAutocompleteExtension extends \Twig_Extension
21
{
22
    /**
23
     * @var PlaceAutocompleteHelper
24
     */
25
    private $placeAutocompleteHelper;
26
27
    /**
28
     * @param PlaceAutocompleteHelper $placeAutocompleteHelper
29
     */
30 3
    public function __construct(PlaceAutocompleteHelper $placeAutocompleteHelper)
31
    {
32 3
        $this->placeAutocompleteHelper = $placeAutocompleteHelper;
33 3
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function getFunctions()
39
    {
40 3
        $functions = [];
41
42 3
        foreach ($this->getMapping() as $name => $method) {
43 3
            $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]);
44
        }
45
46 3
        return $functions;
47
    }
48
49
    /**
50
     * @param Autocomplete $autocomplete
51
     * @param string[]     $attributes
52
     *
53
     * @return string
54
     */
55 1
    public function render(Autocomplete $autocomplete, array $attributes = [])
56
    {
57 1
        $autocomplete->addInputAttributes($attributes);
58
59 1
        return $this->placeAutocompleteHelper->render($autocomplete);
60
    }
61
62
    /**
63
     * @param Autocomplete $autocomplete
64
     * @param string[]     $attributes
65
     *
66
     * @return string
67
     */
68 1
    public function renderHtml(Autocomplete $autocomplete, array $attributes = [])
69
    {
70 1
        $autocomplete->addInputAttributes($attributes);
71
72 1
        return $this->placeAutocompleteHelper->renderHtml($autocomplete);
73
    }
74
75
    /**
76
     * @param Autocomplete $autocomplete
77
     *
78
     * @return string
79
     */
80 1
    public function renderJavascript(Autocomplete $autocomplete)
81
    {
82 1
        return $this->placeAutocompleteHelper->renderJavascript($autocomplete);
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88 3
    public function getName()
89
    {
90 3
        return 'ivory_google_place_autocomplete';
91
    }
92
93
    /**
94
     * @return string[]
95
     */
96 3
    private function getMapping()
97
    {
98
        return [
99 3
            'ivory_google_place_autocomplete'           => 'render',
100
            'ivory_google_place_autocomplete_container' => 'renderHtml',
101
            'ivory_google_place_autocomplete_js'        => 'renderJavascript',
102
        ];
103
    }
104
}
105