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 — place-services ( fedba7 )
by Eric
03:31
created

GeocoderResult   C

Complexity

Total Complexity 42

Size/Duplication

Total Lines 343
Duplicated Lines 4.66 %

Coupling/Cohesion

Components 7
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 42
c 2
b 0
f 1
lcom 7
cbo 1
dl 16
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 hasAddressComponents() 0 6 1
A getAddressComponents() 16 16 4
A setAddressComponents() 0 5 1
A addAddressComponents() 0 6 2
A hasAddressComponent() 0 4 1
A addAddressComponent() 0 6 2
A removeAddressComponent() 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   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

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
use Ivory\GoogleMap\Service\Base\AddressComponent;
15
use Ivory\GoogleMap\Service\Base\Geometry;
16
17
/**
18
 * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderResult
19
 *
20
 * @author GeLo <[email protected]>
21
 */
22
class GeocoderResult
23
{
24
    /**
25
     * @var string|null
26
     */
27
    private $placeId;
28
29
    /**
30
     * @var AddressComponent[]
31
     */
32
    private $addressComponents = [];
33
34
    /**
35
     * @var string|null
36
     */
37
    private $formattedAddress;
38
39
    /**
40
     * @var string[]
41
     */
42
    private $postcodeLocalities = [];
43
44
    /**
45
     * @var Geometry|null
46
     */
47
    private $geometry;
48
49
    /**
50
     * @var bool|null
51
     */
52
    private $partialMatch;
53
54
    /**
55
     * @var string[]
56
     */
57
    private $types = [];
58
59
    /**
60
     * @return bool
61
     */
62
    public function hasPlaceId()
63
    {
64
        return $this->placeId !== null;
65
    }
66
67
    /**
68
     * @return string|null
69
     */
70
    public function getPlaceId()
71
    {
72
        return $this->placeId;
73
    }
74
75
    /**
76
     * @param string|null $placeId
77
     */
78
    public function setPlaceId($placeId)
79
    {
80
        $this->placeId = $placeId;
81
    }
82
83
    /**
84
     * @param string|null $type
85
     *
86
     * @return bool
87
     */
88
    public function hasAddressComponents($type = null)
89
    {
90
        $addresses = $this->getAddressComponents($type);
91
92
        return !empty($addresses);
93
    }
94
95
    /**
96
     * @param string|null $type
97
     *
98
     * @return AddressComponent[]
99
     */
100 View Code Duplication
    public function getAddressComponents($type = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
    {
102
        if ($type === null) {
103
            return $this->addressComponents;
104
        }
105
106
        $addressComponents = [];
107
108
        foreach ($this->addressComponents as $addressComponent) {
109
            if (in_array($type, $addressComponent->getTypes(), true)) {
110
                $addressComponents[] = $addressComponent;
111
            }
112
        }
113
114
        return $addressComponents;
115
    }
116
117
    /**
118
     * @param AddressComponent[] $addressComponents
119
     */
120
    public function setAddressComponents(array $addressComponents)
121
    {
122
        $this->addressComponents = [];
123
        $this->addAddressComponents($addressComponents);
124
    }
125
126
    /**
127
     * @param AddressComponent[] $addressComponents
128
     */
129
    public function addAddressComponents(array $addressComponents)
130
    {
131
        foreach ($addressComponents as $addressComponent) {
132
            $this->addAddressComponent($addressComponent);
133
        }
134
    }
135
136
    /**
137
     * @param AddressComponent $addressComponent
138
     *
139
     * @return bool
140
     */
141
    public function hasAddressComponent(AddressComponent $addressComponent)
142
    {
143
        return in_array($addressComponent, $this->addressComponents, true);
144
    }
145
146
    /**
147
     * @param AddressComponent $addressComponent
148
     */
149
    public function addAddressComponent(AddressComponent $addressComponent)
150
    {
151
        if (!$this->hasAddressComponent($addressComponent)) {
152
            $this->addressComponents[] = $addressComponent;
153
        }
154
    }
155
156
    /**
157
     * @param AddressComponent $addressComponent
158
     */
159
    public function removeAddressComponent(AddressComponent $addressComponent)
160
    {
161
        unset($this->addressComponents[array_search($addressComponent, $this->addressComponents, true)]);
162
        $this->addressComponents = array_values($this->addressComponents);
163
    }
164
165
    /**
166
     * @return bool
167
     */
168
    public function hasFormattedAddress()
169
    {
170
        return !empty($this->formattedAddress);
171
    }
172
173
    /**
174
     * @return string|null
175
     */
176
    public function getFormattedAddress()
177
    {
178
        return $this->formattedAddress;
179
    }
180
181
    /**
182
     * @param string|null $formattedAddress
183
     */
184
    public function setFormattedAddress($formattedAddress = null)
185
    {
186
        $this->formattedAddress = $formattedAddress;
187
    }
188
189
    /**
190
     * @return bool
191
     */
192
    public function hasPostcodeLocalities()
193
    {
194
        return !empty($this->postcodeLocalities);
195
    }
196
197
    /**
198
     * @return string[]
199
     */
200
    public function getPostcodeLocalities()
201
    {
202
        return $this->postcodeLocalities;
203
    }
204
205
    /**
206
     * @param string[] $postcodeLocalities
207
     */
208
    public function setPostcodeLocalities(array $postcodeLocalities)
209
    {
210
        $this->postcodeLocalities = [];
211
        $this->addPostcodeLocalities($postcodeLocalities);
212
    }
213
214
    /**
215
     * @param string[] $postcodeLocalities
216
     */
217
    public function addPostcodeLocalities(array $postcodeLocalities)
218
    {
219
        foreach ($postcodeLocalities as $postcodeLocality) {
220
            $this->addPostcodeLocality($postcodeLocality);
221
        }
222
    }
223
224
    /**
225
     * @param string $postcodeLocality
226
     *
227
     * @return bool
228
     */
229
    public function hasPostcodeLocality($postcodeLocality)
230
    {
231
        return in_array($postcodeLocality, $this->postcodeLocalities, true);
232
    }
233
234
    /**
235
     * @param string $postcodeLocality
236
     */
237
    public function addPostcodeLocality($postcodeLocality)
238
    {
239
        if (!$this->hasPostcodeLocality($postcodeLocality)) {
240
            $this->postcodeLocalities[] = $postcodeLocality;
241
        }
242
    }
243
244
    /**
245
     * @param string $postcodeLocality
246
     */
247
    public function removePostcodeLocality($postcodeLocality)
248
    {
249
        unset($this->postcodeLocalities[array_search($postcodeLocality, $this->postcodeLocalities, true)]);
250
        $this->postcodeLocalities = array_values($this->postcodeLocalities);
251
    }
252
253
    /**
254
     * @return bool
255
     */
256
    public function hasGeometry()
257
    {
258
        return $this->geometry !== null;
259
    }
260
261
    /**
262
     * @return Geometry|null
263
     */
264
    public function getGeometry()
265
    {
266
        return $this->geometry;
267
    }
268
269
    /**
270
     * @param Geometry|null $geometry
271
     */
272
    public function setGeometry(Geometry $geometry = null)
273
    {
274
        $this->geometry = $geometry;
275
    }
276
277
    /**
278
     * @return bool
279
     */
280
    public function hasPartialMatch()
281
    {
282
        return $this->partialMatch !== null;
283
    }
284
285
    /**
286
     * @return bool
287
     */
288
    public function isPartialMatch()
289
    {
290
        return $this->partialMatch;
291
    }
292
293
    /**
294
     * @param bool|null $partialMatch
295
     */
296
    public function setPartialMatch($partialMatch = null)
297
    {
298
        $this->partialMatch = $partialMatch;
299
    }
300
301
    /**
302
     * @return bool
303
     */
304
    public function hasTypes()
305
    {
306
        return !empty($this->types);
307
    }
308
309
    /**
310
     * @return string[]
311
     */
312
    public function getTypes()
313
    {
314
        return $this->types;
315
    }
316
317
    /**
318
     * @param string[] $types
319
     */
320
    public function setTypes(array $types)
321
    {
322
        $this->types = [];
323
        $this->addTypes($types);
324
    }
325
326
    /**
327
     * @param string[] $types
328
     */
329
    public function addTypes(array $types)
330
    {
331
        foreach ($types as $type) {
332
            $this->addType($type);
333
        }
334
    }
335
336
    /**
337
     * @param string $type
338
     *
339
     * @return bool
340
     */
341
    public function hasType($type)
342
    {
343
        return in_array($type, $this->types, true);
344
    }
345
346
    /**
347
     * @param string $type
348
     */
349
    public function addType($type)
350
    {
351
        if (!$this->hasType($type)) {
352
            $this->types[] = $type;
353
        }
354
    }
355
356
    /**
357
     * @param string $type
358
     */
359
    public function removeType($type)
360
    {
361
        unset($this->types[array_search($type, $this->types, true)]);
362
        $this->types = array_values($this->types);
363
    }
364
}
365