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
Push — services ( fe049d )
by Eric
03:30
created

GeocoderResult   C

Complexity

Total Complexity 42

Size/Duplication

Total Lines 343
Duplicated Lines 0 %

Coupling/Cohesion

Components 7
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 42
c 1
b 0
f 0
lcom 7
cbo 1
dl 0
loc 343
rs 6.9315

33 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPlaceId() 0 4 1
A getPlaceId() 0 4 1
A setPlaceId() 0 4 1
A hasAddresses() 0 6 1
A getAddresses() 0 16 4
A setAddresses() 0 5 1
A addAddresses() 0 6 2
A hasAddress() 0 4 1
A addAddress() 0 6 2
A removeAddress() 0 5 1
A hasFormattedAddress() 0 4 1
A getFormattedAddress() 0 4 1
A setFormattedAddress() 0 4 1
A hasPostcodeLocalities() 0 4 1
A getPostcodeLocalities() 0 4 1
A setPostcodeLocalities() 0 5 1
A addPostcodeLocalities() 0 6 2
A hasPostcodeLocality() 0 4 1
A addPostcodeLocality() 0 6 2
A removePostcodeLocality() 0 5 1
A hasGeometry() 0 4 1
A getGeometry() 0 4 1
A setGeometry() 0 4 1
A hasPartialMatch() 0 4 1
A isPartialMatch() 0 4 1
A setPartialMatch() 0 4 1
A hasTypes() 0 4 1
A getTypes() 0 4 1
A setTypes() 0 5 1
A addTypes() 0 6 2
A hasType() 0 4 1
A addType() 0 6 2
A removeType() 0 5 1

How to fix   Complexity   

Complex Class

Complex classes like GeocoderResult often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use GeocoderResult, and based on these observations, apply Extract Interface, too.

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\Geocoder\Response;
13
14
/**
15
 * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderResult
16
 *
17
 * @author GeLo <[email protected]>
18
 */
19
class GeocoderResult
20
{
21
    /**
22
     * @var string|null
23
     */
24
    private $placeId;
25
26
    /**
27
     * @var GeocoderAddress[]
28
     */
29
    private $addresses = [];
30
31
    /**
32
     * @var string|null
33
     */
34
    private $formattedAddress;
35
36
    /**
37
     * @var string[]
38
     */
39
    private $postcodeLocalities = [];
40
41
    /**
42
     * @var GeocoderGeometry|null
43
     */
44
    private $geometry;
45
46
    /**
47
     * @var bool|null
48
     */
49
    private $partialMatch;
50
51
    /**
52
     * @var string[]
53
     */
54
    private $types = [];
55
56
    /**
57
     * @return bool
58
     */
59
    public function hasPlaceId()
60
    {
61
        return $this->placeId !== null;
62
    }
63
64
    /**
65
     * @return string|null
66
     */
67
    public function getPlaceId()
68
    {
69
        return $this->placeId;
70
    }
71
72
    /**
73
     * @param string|null $placeId
74
     */
75
    public function setPlaceId($placeId)
76
    {
77
        $this->placeId = $placeId;
78
    }
79
80
    /**
81
     * @param string|null $type
82
     *
83
     * @return bool
84
     */
85
    public function hasAddresses($type = null)
86
    {
87
        $addresses = $this->getAddresses($type);
88
89
        return !empty($addresses);
90
    }
91
92
    /**
93
     * @param string|null $type
94
     *
95
     * @return GeocoderAddress[]
96
     */
97
    public function getAddresses($type = null)
98
    {
99
        if ($type === null) {
100
            return $this->addresses;
101
        }
102
103
        $addresses = [];
104
105
        foreach ($this->addresses as $address) {
106
            if (in_array($type, $address->getTypes(), true)) {
107
                $addresses[] = $address;
108
            }
109
        }
110
111
        return $addresses;
112
    }
113
114
    /**
115
     * @param GeocoderAddress[] $addresses
116
     */
117
    public function setAddresses(array $addresses)
118
    {
119
        $this->addresses = [];
120
        $this->addAddresses($addresses);
121
    }
122
123
    /**
124
     * @param GeocoderAddress[] $addresses
125
     */
126
    public function addAddresses(array $addresses)
127
    {
128
        foreach ($addresses as $address) {
129
            $this->addAddress($address);
130
        }
131
    }
132
133
    /**
134
     * @param GeocoderAddress $address
135
     *
136
     * @return bool
137
     */
138
    public function hasAddress(GeocoderAddress $address)
139
    {
140
        return in_array($address, $this->addresses, true);
141
    }
142
143
    /**
144
     * @param GeocoderAddress $address
145
     */
146
    public function addAddress(GeocoderAddress $address)
147
    {
148
        if (!$this->hasAddress($address)) {
149
            $this->addresses[] = $address;
150
        }
151
    }
152
153
    /**
154
     * @param GeocoderAddress $address
155
     */
156
    public function removeAddress(GeocoderAddress $address)
157
    {
158
        unset($this->addresses[array_search($address, $this->addresses, true)]);
159
        $this->addresses = array_values($this->addresses);
160
    }
161
162
    /**
163
     * @return bool
164
     */
165
    public function hasFormattedAddress()
166
    {
167
        return !empty($this->formattedAddress);
168
    }
169
170
    /**
171
     * @return string|null
172
     */
173
    public function getFormattedAddress()
174
    {
175
        return $this->formattedAddress;
176
    }
177
178
    /**
179
     * @param string|null $formattedAddress
180
     */
181
    public function setFormattedAddress($formattedAddress = null)
182
    {
183
        $this->formattedAddress = $formattedAddress;
184
    }
185
186
    /**
187
     * @return bool
188
     */
189
    public function hasPostcodeLocalities()
190
    {
191
        return !empty($this->postcodeLocalities);
192
    }
193
194
    /**
195
     * @return string[]
196
     */
197
    public function getPostcodeLocalities()
198
    {
199
        return $this->postcodeLocalities;
200
    }
201
202
    /**
203
     * @param string[] $postcodeLocalities
204
     */
205
    public function setPostcodeLocalities(array $postcodeLocalities)
206
    {
207
        $this->postcodeLocalities = [];
208
        $this->addPostcodeLocalities($postcodeLocalities);
209
    }
210
211
    /**
212
     * @param string[] $postcodeLocalities
213
     */
214
    public function addPostcodeLocalities(array $postcodeLocalities)
215
    {
216
        foreach ($postcodeLocalities as $postcodeLocality) {
217
            $this->addPostcodeLocality($postcodeLocality);
218
        }
219
    }
220
221
    /**
222
     * @param string $postcodeLocality
223
     *
224
     * @return bool
225
     */
226
    public function hasPostcodeLocality($postcodeLocality)
227
    {
228
        return in_array($postcodeLocality, $this->postcodeLocalities, true);
229
    }
230
231
    /**
232
     * @param string $postcodeLocality
233
     */
234
    public function addPostcodeLocality($postcodeLocality)
235
    {
236
        if (!$this->hasPostcodeLocality($postcodeLocality)) {
237
            $this->postcodeLocalities[] = $postcodeLocality;
238
        }
239
    }
240
241
    /**
242
     * @param string $postcodeLocality
243
     */
244
    public function removePostcodeLocality($postcodeLocality)
245
    {
246
        unset($this->postcodeLocalities[array_search($postcodeLocality, $this->postcodeLocalities, true)]);
247
        $this->postcodeLocalities = array_values($this->postcodeLocalities);
248
    }
249
250
    /**
251
     * @return bool
252
     */
253
    public function hasGeometry()
254
    {
255
        return $this->geometry !== null;
256
    }
257
258
    /**
259
     * @return GeocoderGeometry|null
260
     */
261
    public function getGeometry()
262
    {
263
        return $this->geometry;
264
    }
265
266
    /**
267
     * @param GeocoderGeometry|null $geometry
268
     */
269
    public function setGeometry(GeocoderGeometry $geometry = null)
270
    {
271
        $this->geometry = $geometry;
272
    }
273
274
    /**
275
     * @return bool
276
     */
277
    public function hasPartialMatch()
278
    {
279
        return $this->partialMatch !== null;
280
    }
281
282
    /**
283
     * @return bool
284
     */
285
    public function isPartialMatch()
286
    {
287
        return $this->partialMatch;
288
    }
289
290
    /**
291
     * @param bool|null $partialMatch
292
     */
293
    public function setPartialMatch($partialMatch = null)
294
    {
295
        $this->partialMatch = $partialMatch;
296
    }
297
298
    /**
299
     * @return bool
300
     */
301
    public function hasTypes()
302
    {
303
        return !empty($this->types);
304
    }
305
306
    /**
307
     * @return string[]
308
     */
309
    public function getTypes()
310
    {
311
        return $this->types;
312
    }
313
314
    /**
315
     * @param string[] $types
316
     */
317
    public function setTypes(array $types)
318
    {
319
        $this->types = [];
320
        $this->addTypes($types);
321
    }
322
323
    /**
324
     * @param string[] $types
325
     */
326
    public function addTypes(array $types)
327
    {
328
        foreach ($types as $type) {
329
            $this->addType($type);
330
        }
331
    }
332
333
    /**
334
     * @param string $type
335
     *
336
     * @return bool
337
     */
338
    public function hasType($type)
339
    {
340
        return in_array($type, $this->types, true);
341
    }
342
343
    /**
344
     * @param string $type
345
     */
346
    public function addType($type)
347
    {
348
        if (!$this->hasType($type)) {
349
            $this->types[] = $type;
350
        }
351
    }
352
353
    /**
354
     * @param string $type
355
     */
356
    public function removeType($type)
357
    {
358
        unset($this->types[array_search($type, $this->types, true)]);
359
        $this->types = array_values($this->types);
360
    }
361
}
362