DirectionLeg   B
last analyzed

Complexity

Total Complexity 47

Size/Duplication

Total Lines 364
Duplicated Lines 0 %

Coupling/Cohesion

Components 11
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 47
lcom 11
cbo 0
dl 0
loc 364
ccs 107
cts 107
cp 1
rs 8.64
c 0
b 0
f 0

41 Methods

Rating   Name   Duplication   Size   Complexity  
A hasDistance() 0 4 1
A getDistance() 0 4 1
A setDistance() 0 4 1
A hasDuration() 0 4 1
A getDuration() 0 4 1
A setDuration() 0 4 1
A hasDurationInTraffic() 0 4 1
A getDurationInTraffic() 0 4 1
A setDurationInTraffic() 0 4 1
A hasArrivalTime() 0 4 1
A getArrivalTime() 0 4 1
A setArrivalTime() 0 4 1
A hasDepartureTime() 0 4 1
A getDepartureTime() 0 4 1
A setDepartureTime() 0 4 1
A hasEndAddress() 0 4 1
A getEndAddress() 0 4 1
A setEndAddress() 0 4 1
A hasEndLocation() 0 4 1
A getEndLocation() 0 4 1
A setEndLocation() 0 4 1
A hasStartAddress() 0 4 1
A getStartAddress() 0 4 1
A setStartAddress() 0 4 1
A hasStartLocation() 0 4 1
A getStartLocation() 0 4 1
A setStartLocation() 0 4 1
A hasSteps() 0 4 1
A getSteps() 0 4 1
A setSteps() 0 5 1
A addSteps() 0 6 2
A hasStep() 0 4 1
A addStep() 0 6 2
A removeStep() 0 5 2
A hasViaWaypoints() 0 4 1
A getViaWaypoints() 0 4 1
A setViaWaypoints() 0 5 1
A addViaWaypoints() 0 6 2
A hasViaWaypoint() 0 4 1
A addViaWaypoint() 0 6 2
A removeViaWaypoint() 0 5 2

How to fix   Complexity   

Complex Class

Complex classes like DirectionLeg 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 DirectionLeg, 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\Coordinate;
15
use Ivory\GoogleMap\Service\Base\Distance;
16
use Ivory\GoogleMap\Service\Base\Duration;
17
use Ivory\GoogleMap\Service\Base\Time;
18
19
/**
20
 * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionLeg
21
 *
22
 * @author GeLo <[email protected]>
23
 */
24
class DirectionLeg
25
{
26
    /**
27
     * @var Distance|null
28
     */
29
    private $distance;
30
31
    /**
32
     * @var Duration|null
33
     */
34
    private $duration;
35
36
    /**
37
     * @var Duration|null
38
     */
39
    private $durationInTraffic;
40
41
    /**
42
     * @var Time|null
43
     */
44
    private $arrivalTime;
45
46
    /**
47
     * @var Time|null
48
     */
49
    private $departureTime;
50
51
    /**
52
     * @var string|null
53
     */
54
    private $endAddress;
55
56
    /**
57
     * @var Coordinate|null
58
     */
59
    private $endLocation;
60
61
    /**
62
     * @var string|null
63
     */
64
    private $startAddress;
65
66
    /**
67
     * @var Coordinate|null
68
     */
69
    private $startLocation;
70
71
    /**
72
     * @var DirectionStep[]
73
     */
74
    private $steps = [];
75
76
    /**
77
     * @var DirectionWaypoint[]
78
     */
79
    private $viaWaypoints = [];
80
81
    /**
82
     * @return bool
83
     */
84 12
    public function hasDistance()
85
    {
86 12
        return null !== $this->distance;
87
    }
88
89
    /**
90
     * @return Distance|null
91
     */
92 12
    public function getDistance()
93
    {
94 12
        return $this->distance;
95
    }
96
97 8
    public function setDistance(Distance $distance = null)
98
    {
99 8
        $this->distance = $distance;
100 8
    }
101
102
    /**
103
     * @return bool
104
     */
105 12
    public function hasDuration()
106
    {
107 12
        return null !== $this->duration;
108
    }
109
110
    /**
111
     * @return Duration|null
112
     */
113 12
    public function getDuration()
114
    {
115 12
        return $this->duration;
116
    }
117
118 8
    public function setDuration(Duration $duration = null)
119
    {
120 8
        $this->duration = $duration;
121 8
    }
122
123
    /**
124
     * @return bool
125
     */
126 12
    public function hasDurationInTraffic()
127
    {
128 12
        return null !== $this->durationInTraffic;
129
    }
130
131
    /**
132
     * @return Duration|null
133
     */
134 12
    public function getDurationInTraffic()
135
    {
136 12
        return $this->durationInTraffic;
137
    }
138
139 8
    public function setDurationInTraffic(Duration $durationInTraffic = null)
140
    {
141 8
        $this->durationInTraffic = $durationInTraffic;
142 8
    }
143
144
    /**
145
     * @return bool
146
     */
147 12
    public function hasArrivalTime()
148
    {
149 12
        return null !== $this->arrivalTime;
150
    }
151
152
    /**
153
     * @return Time|null
154
     */
155 12
    public function getArrivalTime()
156
    {
157 12
        return $this->arrivalTime;
158
    }
159
160 8
    public function setArrivalTime(Time $arrivalTime = null)
161
    {
162 8
        $this->arrivalTime = $arrivalTime;
163 8
    }
164
165
    /**
166
     * @return bool
167
     */
168 12
    public function hasDepartureTime()
169
    {
170 12
        return null !== $this->departureTime;
171
    }
172
173
    /**
174
     * @return Time|null
175
     */
176 12
    public function getDepartureTime()
177
    {
178 12
        return $this->departureTime;
179
    }
180
181 8
    public function setDepartureTime(Time $departureTime = null)
182
    {
183 8
        $this->departureTime = $departureTime;
184 8
    }
185
186
    /**
187
     * @return bool
188
     */
189 12
    public function hasEndAddress()
190
    {
191 12
        return null !== $this->endAddress;
192
    }
193
194
    /**
195
     * @return string|null
196
     */
197 12
    public function getEndAddress()
198
    {
199 12
        return $this->endAddress;
200
    }
201
202
    /**
203
     * @param string|null $endAddress
204
     */
205 8
    public function setEndAddress($endAddress = null)
206
    {
207 8
        $this->endAddress = $endAddress;
208 8
    }
209
210
    /**
211
     * @return bool
212
     */
213 12
    public function hasEndLocation()
214
    {
215 12
        return null !== $this->endLocation;
216
    }
217
218
    /**
219
     * @return Coordinate|null
220
     */
221 12
    public function getEndLocation()
222
    {
223 12
        return $this->endLocation;
224
    }
225
226 8
    public function setEndLocation(Coordinate $endLocation = null)
227
    {
228 8
        $this->endLocation = $endLocation;
229 8
    }
230
231
    /**
232
     * @return bool
233
     */
234 12
    public function hasStartAddress()
235
    {
236 12
        return null !== $this->startAddress;
237
    }
238
239
    /**
240
     * @return string|null
241
     */
242 12
    public function getStartAddress()
243
    {
244 12
        return $this->startAddress;
245
    }
246
247
    /**
248
     * @param string|null $startAddress
249
     */
250 8
    public function setStartAddress($startAddress = null)
251
    {
252 8
        $this->startAddress = $startAddress;
253 8
    }
254
255
    /**
256
     * @return bool
257
     */
258 12
    public function hasStartLocation()
259
    {
260 12
        return null !== $this->startLocation;
261
    }
262
263
    /**
264
     * @return Coordinate|null
265
     */
266 12
    public function getStartLocation()
267
    {
268 12
        return $this->startLocation;
269
    }
270
271 8
    public function setStartLocation(Coordinate $startLocation = null)
272
    {
273 8
        $this->startLocation = $startLocation;
274 8
    }
275
276
    /**
277
     * @return bool
278
     */
279 20
    public function hasSteps()
280
    {
281 20
        return !empty($this->steps);
282
    }
283
284
    /**
285
     * @return DirectionStep[]
286
     */
287 20
    public function getSteps()
288
    {
289 20
        return $this->steps;
290
    }
291
292
    /**
293
     * @param DirectionStep[] $steps
294
     */
295 8
    public function setSteps(array $steps)
296
    {
297 8
        $this->steps = [];
298 8
        $this->addSteps($steps);
299 8
    }
300
301
    /**
302
     * @param DirectionStep[] $steps
303
     */
304 8
    public function addSteps(array $steps)
305
    {
306 8
        foreach ($steps as $step) {
307 8
            $this->addStep($step);
308
        }
309 8
    }
310
311
    /**
312
     * @return bool
313
     */
314 16
    public function hasStep(DirectionStep $step)
315
    {
316 16
        return in_array($step, $this->steps, true);
317
    }
318
319 16
    public function addStep(DirectionStep $step)
320
    {
321 16
        if (!$this->hasStep($step)) {
322 16
            $this->steps[] = $step;
323
        }
324 16
    }
325
326 4
    public function removeStep(DirectionStep $step)
327
    {
328 4
        unset($this->steps[array_search($step, $this->steps, true)]);
329 4
        $this->steps = empty($this->steps) ? [] : array_values($this->steps);
330 4
    }
331
332
    /**
333
     * @return bool
334
     */
335 20
    public function hasViaWaypoints()
336
    {
337 20
        return !empty($this->viaWaypoints);
338
    }
339
340
    /**
341
     * @return DirectionWaypoint[]
342
     */
343 20
    public function getViaWaypoints()
344
    {
345 20
        return $this->viaWaypoints;
346
    }
347
348
    /**
349
     * @param DirectionWaypoint[] $viaWaypoints
350
     */
351 8
    public function setViaWaypoints(array $viaWaypoints)
352
    {
353 8
        $this->viaWaypoints = [];
354 8
        $this->addViaWaypoints($viaWaypoints);
355 8
    }
356
357
    /**
358
     * @param DirectionWaypoint[] $viaWaypoints
359
     */
360 8
    public function addViaWaypoints(array $viaWaypoints)
361
    {
362 8
        foreach ($viaWaypoints as $viaWaypoint) {
363 8
            $this->addViaWaypoint($viaWaypoint);
364
        }
365 8
    }
366
367
    /**
368
     * @return bool
369
     */
370 16
    public function hasViaWaypoint(DirectionWaypoint $viaWaypoint)
371
    {
372 16
        return in_array($viaWaypoint, $this->viaWaypoints, true);
373
    }
374
375 16
    public function addViaWaypoint(DirectionWaypoint $viaWaypoint)
376
    {
377 16
        if (!$this->hasViaWaypoint($viaWaypoint)) {
378 16
            $this->viaWaypoints[] = $viaWaypoint;
379
        }
380 16
    }
381
382 4
    public function removeViaWaypoint(DirectionWaypoint $viaWaypoint)
383
    {
384 4
        unset($this->viaWaypoints[array_search($viaWaypoint, $this->viaWaypoints, true)]);
385 4
        $this->viaWaypoints = empty($this->viaWaypoints) ? [] : array_values($this->viaWaypoints);
386 4
    }
387
}
388