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 — master ( 8dd986...688c26 )
by Eric
04:44
created

DirectionRoute   C

Complexity

Total Complexity 40

Size/Duplication

Total Lines 344
Duplicated Lines 0 %

Coupling/Cohesion

Components 8
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 40
c 1
b 0
f 0
lcom 8
cbo 0
dl 0
loc 344
rs 6.5517

35 Methods

Rating   Name   Duplication   Size   Complexity  
A hasBound() 0 4 1
A getBound() 0 4 1
A setBound() 0 4 1
A hasCopyrights() 0 4 1
A getCopyrights() 0 4 1
A setCopyrights() 0 4 1
A hasLegs() 0 4 1
A getLegs() 0 4 1
A setLegs() 0 5 1
A addLegs() 0 6 2
A hasLeg() 0 4 1
A addLeg() 0 6 2
A removeLeg() 0 5 1
A hasOverviewPolyline() 0 4 1
A getOverviewPolyline() 0 4 1
A setOverviewPolyline() 0 4 1
A hasSummary() 0 4 1
A getSummary() 0 4 1
A setSummary() 0 4 1
A hasFare() 0 4 1
A getFare() 0 4 1
A setFare() 0 4 1
A hasWarnings() 0 4 1
A getWarnings() 0 4 1
A setWarnings() 0 5 1
A addWarnings() 0 6 2
A hasWarning() 0 4 1
A addWarning() 0 6 2
A removeWarning() 0 4 1
A hasWaypointOrders() 0 4 1
A getWaypointOrders() 0 4 1
A setWaypointOrders() 0 5 1
A addWaypointOrders() 0 8 2
A hasWaypointOrder() 0 4 1
A addWaypointOrder() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like DirectionRoute 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 DirectionRoute, 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\Direction\Response;
13
14
use Ivory\GoogleMap\Base\Bound;
15
use Ivory\GoogleMap\Overlay\EncodedPolyline;
16
use Ivory\GoogleMap\Service\Base\Fare;
17
18
/**
19
 * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionRoute
20
 *
21
 * @author GeLo <[email protected]>
22
 */
23
class DirectionRoute
24
{
25
    /**
26
     * @var Bound|null
27
     */
28
    private $bound;
29
30
    /**
31
     * @var string|null
32
     */
33
    private $copyrights;
34
35
    /**
36
     * @var DirectionLeg[]
37
     */
38
    private $legs = [];
39
40
    /**
41
     * @var EncodedPolyline|null
42
     */
43
    private $overviewPolyline;
44
45
    /**
46
     * @var string|null
47
     */
48
    private $summary;
49
50
    /**
51
     * @var Fare|null
52
     */
53
    private $fare;
54
55
    /**
56
     * @var string[]
57
     */
58
    private $warnings = [];
59
60
    /**
61
     * @var int[]
62
     */
63
    private $waypointOrders = [];
64
65
    /**
66
     * @return bool
67
     */
68
    public function hasBound()
69
    {
70
        return $this->bound !== null;
71
    }
72
73
    /**
74
     * @return Bound|null
75
     */
76
    public function getBound()
77
    {
78
        return $this->bound;
79
    }
80
81
    /**
82
     * @param Bound|null $bound
83
     */
84
    public function setBound(Bound $bound = null)
85
    {
86
        $this->bound = $bound;
87
    }
88
89
    /**
90
     * @return bool
91
     */
92
    public function hasCopyrights()
93
    {
94
        return $this->copyrights !== null;
95
    }
96
97
    /**
98
     * @return string|null
99
     */
100
    public function getCopyrights()
101
    {
102
        return $this->copyrights;
103
    }
104
105
    /**
106
     * @param string|null $copyrights
107
     */
108
    public function setCopyrights($copyrights = null)
109
    {
110
        $this->copyrights = $copyrights;
111
    }
112
113
    /**
114
     * @return bool
115
     */
116
    public function hasLegs()
117
    {
118
        return !empty($this->legs);
119
    }
120
121
    /**
122
     * @return DirectionLeg[]
123
     */
124
    public function getLegs()
125
    {
126
        return $this->legs;
127
    }
128
129
    /**
130
     * @param DirectionLeg[] $legs
131
     */
132
    public function setLegs(array $legs)
133
    {
134
        $this->legs = [];
135
        $this->addLegs($legs);
136
    }
137
138
    /**
139
     * @param DirectionLeg[] $legs
140
     */
141
    public function addLegs(array $legs)
142
    {
143
        foreach ($legs as $leg) {
144
            $this->addLeg($leg);
145
        }
146
    }
147
148
    /**
149
     * @param DirectionLeg $leg
150
     *
151
     * @return bool
152
     */
153
    public function hasLeg(DirectionLeg $leg)
154
    {
155
        return in_array($leg, $this->legs, true);
156
    }
157
158
    /**
159
     * @param DirectionLeg $leg
160
     */
161
    public function addLeg(DirectionLeg $leg)
162
    {
163
        if (!$this->hasLeg($leg)) {
164
            $this->legs[] = $leg;
165
        }
166
    }
167
168
    /**
169
     * @param DirectionLeg $leg
170
     */
171
    public function removeLeg(DirectionLeg $leg)
172
    {
173
        unset($this->legs[array_search($leg, $this->legs, true)]);
174
        $this->legs = array_values($this->legs);
175
    }
176
177
    /**
178
     * @return bool
179
     */
180
    public function hasOverviewPolyline()
181
    {
182
        return $this->overviewPolyline !== null;
183
    }
184
185
    /**
186
     * @return EncodedPolyline|null
187
     */
188
    public function getOverviewPolyline()
189
    {
190
        return $this->overviewPolyline;
191
    }
192
193
    /**
194
     * @param EncodedPolyline|null $overviewPolyline
195
     */
196
    public function setOverviewPolyline(EncodedPolyline $overviewPolyline = null)
197
    {
198
        $this->overviewPolyline = $overviewPolyline;
199
    }
200
201
    /**
202
     * @return bool
203
     */
204
    public function hasSummary()
205
    {
206
        return $this->summary !== null;
207
    }
208
209
    /**
210
     * @return string|null
211
     */
212
    public function getSummary()
213
    {
214
        return $this->summary;
215
    }
216
217
    /**
218
     * @param string|null $summary
219
     */
220
    public function setSummary($summary = null)
221
    {
222
        $this->summary = $summary;
223
    }
224
225
    /**
226
     * @return bool
227
     */
228
    public function hasFare()
229
    {
230
        return $this->fare !== null;
231
    }
232
233
    /**
234
     * @return Fare|null
235
     */
236
    public function getFare()
237
    {
238
        return $this->fare;
239
    }
240
241
    /**
242
     * @param Fare|null $fare
243
     */
244
    public function setFare(Fare $fare = null)
245
    {
246
        $this->fare = $fare;
247
    }
248
249
    /**
250
     * @return bool
251
     */
252
    public function hasWarnings()
253
    {
254
        return !empty($this->warnings);
255
    }
256
257
    /**
258
     * @return string[]
259
     */
260
    public function getWarnings()
261
    {
262
        return $this->warnings;
263
    }
264
265
    /**
266
     * @param string[] $warnings
267
     */
268
    public function setWarnings(array $warnings)
269
    {
270
        $this->warnings = [];
271
        $this->addWarnings($warnings);
272
    }
273
274
    /**
275
     * @param string[] $warnings
276
     */
277
    public function addWarnings(array $warnings)
278
    {
279
        foreach ($warnings as $warning) {
280
            $this->addWarning($warning);
281
        }
282
    }
283
284
    /**
285
     * @param $warning
286
     *
287
     * @return bool
288
     */
289
    public function hasWarning($warning)
290
    {
291
        return in_array($warning, $this->warnings, true);
292
    }
293
294
    /**
295
     * @param string $warning
296
     */
297
    public function addWarning($warning)
298
    {
299
        if (!$this->hasWarning($warning)) {
300
            $this->warnings[] = $warning;
301
        }
302
    }
303
304
    /**
305
     * @param string $warning
306
     */
307
    public function removeWarning($warning)
308
    {
309
        unset($this->warnings[array_search($warning, $this->warnings, true)]);
310
    }
311
312
    /**
313
     * @return bool
314
     */
315
    public function hasWaypointOrders()
316
    {
317
        return !empty($this->waypointOrders);
318
    }
319
320
    /**
321
     * @return int[]
322
     */
323
    public function getWaypointOrders()
324
    {
325
        return $this->waypointOrders;
326
    }
327
328
    /**
329
     * @param int[] $waypointOrders
330
     */
331
    public function setWaypointOrders(array $waypointOrders)
332
    {
333
        $this->waypointOrders = [];
334
        $this->addWaypointOrders($waypointOrders);
335
    }
336
337
    /**
338
     * @param int[] $waypointOrders
339
     */
340
    public function addWaypointOrders(array $waypointOrders)
341
    {
342
        $this->waypointOrders = [];
343
344
        foreach ($waypointOrders as $waypointOrder) {
345
            $this->addWaypointOrder($waypointOrder);
346
        }
347
    }
348
349
    /**
350
     * @param $waypointOrder
351
     *
352
     * @return bool
353
     */
354
    public function hasWaypointOrder($waypointOrder)
355
    {
356
        return in_array($waypointOrder, $this->waypointOrders, true);
357
    }
358
359
    /**
360
     * @param int $waypointOrder
361
     */
362
    public function addWaypointOrder($waypointOrder)
363
    {
364
        $this->waypointOrders[] = $waypointOrder;
365
    }
366
}
367