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

AbstractService   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 226
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 23
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 226
rs 10

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getClient() 0 4 1
A setClient() 0 4 1
A getMessageFactory() 0 4 1
A setMessageFactory() 0 4 1
A getUrl() 0 8 2
A setUrl() 0 4 1
A isHttps() 0 4 1
A setHttps() 0 4 1
A getFormat() 0 4 1
A setFormat() 0 4 1
A getXmlParser() 0 4 1
A setXmlParser() 0 4 1
A hasKey() 0 4 1
A getKey() 0 4 1
A setKey() 0 4 1
A hasBusinessAccount() 0 4 1
A getBusinessAccount() 0 4 1
A setBusinessAccount() 0 4 1
A createRequest() 0 14 3
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\Service;
13
14
use Http\Client\HttpClient;
15
use Http\Message\MessageFactory;
16
use Ivory\GoogleMap\Service\Utility\XmlParser;
17
use Psr\Http\Message\RequestInterface;
18
19
/**
20
 * @author GeLo <[email protected]>
21
 */
22
abstract class AbstractService
23
{
24
    const FORMAT_JSON = 'json';
25
    const FORMAT_XML = 'xml';
26
27
    /**
28
     * @var HttpClient
29
     */
30
    private $client;
31
32
    /**
33
     * @var MessageFactory
34
     */
35
    private $messageFactory;
36
37
    /**
38
     * @var string
39
     */
40
    private $url;
41
42
    /**
43
     * @var bool
44
     */
45
    private $https = true;
46
47
    /**
48
     * @var string
49
     */
50
    private $format = self::FORMAT_JSON;
51
52
    /**
53
     * @var XmlParser
54
     */
55
    private $xmlParser;
56
57
    /**
58
     * @var string|null
59
     */
60
    private $key;
61
62
    /**
63
     * @var BusinessAccount|null
64
     */
65
    private $businessAccount;
66
67
    /**
68
     * @param HttpClient     $client
69
     * @param MessageFactory $messageFactory
70
     * @param string         $url
71
     */
72
    public function __construct(HttpClient $client, MessageFactory $messageFactory, $url)
73
    {
74
        $this->setClient($client);
75
        $this->setMessageFactory($messageFactory);
76
        $this->setUrl($url);
77
        $this->setXmlParser(new XmlParser());
78
    }
79
80
    /**
81
     * @return HttpClient
82
     */
83
    public function getClient()
84
    {
85
        return $this->client;
86
    }
87
88
    /**
89
     * @param HttpClient $client
90
     */
91
    public function setClient(HttpClient $client)
92
    {
93
        $this->client = $client;
94
    }
95
96
    /**
97
     * @return MessageFactory
98
     */
99
    public function getMessageFactory()
100
    {
101
        return $this->messageFactory;
102
    }
103
104
    /**
105
     * @param MessageFactory $messageFactory
106
     */
107
    public function setMessageFactory(MessageFactory $messageFactory)
108
    {
109
        $this->messageFactory = $messageFactory;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getUrl()
116
    {
117
        if ($this->isHttps()) {
118
            return str_replace('http://', 'https://', $this->url);
119
        }
120
121
        return $this->url;
122
    }
123
124
    /**
125
     * @param string $url
126
     */
127
    public function setUrl($url)
128
    {
129
        $this->url = $url;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function isHttps()
136
    {
137
        return $this->https;
138
    }
139
140
    /**
141
     * @param bool $https
142
     */
143
    public function setHttps($https)
144
    {
145
        $this->https = $https;
146
    }
147
148
    /**
149
     * @return string
150
     */
151
    public function getFormat()
152
    {
153
        return $this->format;
154
    }
155
156
    /**
157
     * @param string $format
158
     */
159
    public function setFormat($format)
160
    {
161
        $this->format = $format;
162
    }
163
164
    /**
165
     * @return XmlParser
166
     */
167
    public function getXmlParser()
168
    {
169
        return $this->xmlParser;
170
    }
171
172
    /**
173
     * @param XmlParser $xmlParser
174
     */
175
    public function setXmlParser(XmlParser $xmlParser)
176
    {
177
        $this->xmlParser = $xmlParser;
178
    }
179
180
    /**
181
     * @return bool
182
     */
183
    public function hasKey()
184
    {
185
        return $this->key !== null;
186
    }
187
188
    /**
189
     * @return string|null
190
     */
191
    public function getKey()
192
    {
193
        return $this->key;
194
    }
195
196
    /**
197
     * @param string|null $key
198
     */
199
    public function setKey($key)
200
    {
201
        $this->key = $key;
202
    }
203
204
    /**
205
     * @return bool
206
     */
207
    public function hasBusinessAccount()
208
    {
209
        return $this->businessAccount !== null;
210
    }
211
212
    /**
213
     * @return BusinessAccount
214
     */
215
    public function getBusinessAccount()
216
    {
217
        return $this->businessAccount;
218
    }
219
220
    /**
221
     * @param BusinessAccount $businessAccount
222
     */
223
    public function setBusinessAccount(BusinessAccount $businessAccount = null)
224
    {
225
        $this->businessAccount = $businessAccount;
226
    }
227
228
    /**
229
     * @param string[] $query
230
     *
231
     * @return RequestInterface
232
     */
233
    protected function createRequest(array $query)
234
    {
235
        if ($this->hasKey()) {
236
            $query['key'] = $this->key;
237
        }
238
239
        $url = $this->getUrl().'/'.$this->getFormat().'?'.http_build_query($query, '', '&');
240
241
        if ($this->hasBusinessAccount()) {
242
            $url = $this->businessAccount->signUrl($url);
243
        }
244
245
        return $this->messageFactory->createRequest('GET', $url);
246
    }
247
}
248