GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#136)
by Eric
04:41 queued 01:49
created

LoaderRenderer::hasKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map 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\GoogleMap\Helper\Renderer;
13
14
use Ivory\GoogleMap\Helper\Formatter\Formatter;
15
use Ivory\JsonBuilder\JsonBuilder;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class LoaderRenderer extends AbstractJsonRenderer
21
{
22
    /**
23
     * @var string
24
     */
25
    private $language;
26
27
    /**
28
     * @var string|null
29
     */
30
    private $key;
31
32
    /**
33
     * @param Formatter   $formatter
34
     * @param JsonBuilder $jsonBuilder
35
     * @param string      $language
36
     * @param string|null $key
37
     */
38
    public function __construct(Formatter $formatter, JsonBuilder $jsonBuilder, $language = 'en', $key = null)
39
    {
40
        parent::__construct($formatter, $jsonBuilder);
41
42
        $this->setLanguage($language);
43
        $this->setKey($key);
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getLanguage()
50
    {
51
        return $this->language;
52
    }
53
54
    /**
55
     * @param string $language
56
     */
57
    public function setLanguage($language)
58
    {
59
        $this->language = $language;
60
    }
61
62
    /**
63
     * @return bool
64
     */
65
    public function hasKey()
66
    {
67
        return $this->key !== null;
68
    }
69
70
    /**
71
     * @return string|null
72
     */
73
    public function getKey()
74
    {
75
        return $this->key;
76
    }
77
78
    /**
79
     * @param string|null $key
80
     */
81
    public function setKey($key)
82
    {
83
        $this->key = $key;
84
    }
85
86
    /**
87
     * @param string   $name
88
     * @param string   $callback
89
     * @param string[] $libraries
90
     * @param bool     $newLine
91
     *
92
     * @return string
93
     */
94
    public function render(
95
        $name,
96
        $callback,
97
        array $libraries = [],
98
        $newLine = true
99
    ) {
100
        $formatter = $this->getFormatter();
101
        $jsonBuilder = $this->getJsonBuilder();
102
103
        $parameters = ['language' => $this->language];
104
105
        if ($this->hasKey()) {
106
            $parameters['key'] = $this->key;
107
        }
108
109
        if (!empty($libraries)) {
110
            $parameters['libraries'] = implode(',', $libraries);
111
        }
112
113
        $jsonBuilder
114
            ->setValue('[other_params]', urldecode(http_build_query($parameters, '', '&')))
115
            ->setValue('[callback]', $callback, false);
116
117
        return $formatter->renderClosure($formatter->renderCall($formatter->renderProperty('google', 'load'), [
118
            $formatter->renderEscape('maps'),
119
            $formatter->renderEscape('3'),
120
            $jsonBuilder->build(),
121
        ]), [], $name, true, $newLine);
122
    }
123
124
    /**
125
     * @param string $callback
126
     *
127
     * @return string
128
     */
129
    public function renderSource($callback)
130
    {
131
        return 'https://www.google.com/jsapi?callback='.$callback;
132
    }
133
}
134