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.

StaticMapHelper::setClientId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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;
13
14
use Ivory\GoogleMap\Helper\Event\StaticMapEvent;
15
use Ivory\GoogleMap\Helper\Event\StaticMapEvents;
16
use Ivory\GoogleMap\Map;
17
use Ivory\GoogleMap\Service\UrlSigner;
18
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class StaticMapHelper extends AbstractHelper
24
{
25
    /**
26
     * @var string|null
27
     */
28
    private $secret;
29
30
    /**
31
     * @var string|null
32
     */
33
    private $clientId;
34
35
    /**
36
     * @var string|null
37
     */
38
    private $channel;
39
40
    /**
41
     * @param EventDispatcherInterface $eventDispatcher
42
     * @param string|null              $secret
43
     * @param string|null              $clientId
44
     * @param string|null              $channel
45
     */
46 104
    public function __construct(
47
        EventDispatcherInterface $eventDispatcher,
48
        $secret = null,
49
        $clientId = null,
50
        $channel = null
51
    ) {
52 104
        parent::__construct($eventDispatcher);
53
54 104
        $this->secret = $secret;
55 104
        $this->clientId = $clientId;
56 104
        $this->channel = $channel;
57 104
    }
58
59
    /**
60
     * @return bool
61
     */
62 100
    public function hasSecret()
63
    {
64 100
        return $this->secret !== null;
65
    }
66
67
    /**
68
     * @return string|null
69
     */
70
    public function getSecret()
71
    {
72
        return $this->secret;
73
    }
74
75
    /**
76
     * @param string|null $secret
77
     */
78
    public function setSecret($secret)
79
    {
80
        $this->secret = $secret;
81
    }
82
83
    /**
84
     * @return bool
85
     */
86
    public function hasClientId()
87
    {
88
        return $this->clientId !== null;
89
    }
90
91
    /**
92
     * @return string|null
93
     */
94
    public function getClientId()
95
    {
96
        return $this->clientId;
97
    }
98
99
    /**
100
     * @param string|null $clientId
101
     */
102
    public function setClientId($clientId)
103
    {
104
        $this->clientId = $clientId;
105
    }
106
107
    /**
108
     * @return bool
109
     */
110
    public function hasChannel()
111
    {
112
        return $this->channel !== null;
113
    }
114
115
    /**
116
     * @return string|null
117
     */
118
    public function getChannel()
119
    {
120
        return $this->channel;
121
    }
122
123
    /**
124
     * @param string|null $channel
125
     */
126
    public function setChannel($channel)
127
    {
128
        $this->channel = $channel;
129
    }
130
131
    /**
132
     * @param Map $map
133
     *
134
     * @return string
135
     */
136 100
    public function render(Map $map)
137
    {
138 100
        $this->getEventDispatcher()->dispatch(StaticMapEvents::HTML, $event = new StaticMapEvent($map));
139
140 100
        $query = preg_replace('/(%5B[0-9]+%5D)+=/', '=', http_build_query($event->getParameters(), '', '&'));
141 100
        $url = 'https://maps.googleapis.com/maps/api/staticmap?'.$query;
142
143 100
        if ($this->hasSecret()) {
144 4
            $url = UrlSigner::sign($url, $this->secret, $this->clientId, $this->channel);
145 2
        }
146
147 100
        return $url;
148
    }
149
}
150