DirectionRoute   A
last analyzed

Complexity

Total Complexity 42

Size/Duplication

Total Lines 328
Duplicated Lines 0 %

Coupling/Cohesion

Components 8
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 42
lcom 8
cbo 0
dl 0
loc 328
ccs 97
cts 97
cp 1
rs 9.0399
c 0
b 0
f 0

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 2
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 5 2
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 12
    public function hasBound()
69
    {
70 12
        return null !== $this->bound;
71
    }
72
73
    /**
74
     * @return Bound|null
75
     */
76 12
    public function getBound()
77
    {
78 12
        return $this->bound;
79
    }
80
81 8
    public function setBound(Bound $bound = null)
82
    {
83 8
        $this->bound = $bound;
84 8
    }
85
86
    /**
87
     * @return bool
88
     */
89 12
    public function hasCopyrights()
90
    {
91 12
        return null !== $this->copyrights;
92
    }
93
94
    /**
95
     * @return string|null
96
     */
97 12
    public function getCopyrights()
98
    {
99 12
        return $this->copyrights;
100
    }
101
102
    /**
103
     * @param string|null $copyrights
104
     */
105 8
    public function setCopyrights($copyrights = null)
106
    {
107 8
        $this->copyrights = $copyrights;
108 8
    }
109
110
    /**
111
     * @return bool
112
     */
113 20
    public function hasLegs()
114
    {
115 20
        return !empty($this->legs);
116
    }
117
118
    /**
119
     * @return DirectionLeg[]
120
     */
121 20
    public function getLegs()
122
    {
123 20
        return $this->legs;
124
    }
125
126
    /**
127
     * @param DirectionLeg[] $legs
128
     */
129 8
    public function setLegs(array $legs)
130
    {
131 8
        $this->legs = [];
132 8
        $this->addLegs($legs);
133 8
    }
134
135
    /**
136
     * @param DirectionLeg[] $legs
137
     */
138 8
    public function addLegs(array $legs)
139
    {
140 8
        foreach ($legs as $leg) {
141 8
            $this->addLeg($leg);
142
        }
143 8
    }
144
145
    /**
146
     * @return bool
147
     */
148 16
    public function hasLeg(DirectionLeg $leg)
149
    {
150 16
        return in_array($leg, $this->legs, true);
151
    }
152
153 16
    public function addLeg(DirectionLeg $leg)
154
    {
155 16
        if (!$this->hasLeg($leg)) {
156 16
            $this->legs[] = $leg;
157
        }
158 16
    }
159
160 4
    public function removeLeg(DirectionLeg $leg)
161
    {
162 4
        unset($this->legs[array_search($leg, $this->legs, true)]);
163 4
        $this->legs = empty($this->legs) ? [] : array_values($this->legs);
164 4
    }
165
166
    /**
167
     * @return bool
168
     */
169 12
    public function hasOverviewPolyline()
170
    {
171 12
        return null !== $this->overviewPolyline;
172
    }
173
174
    /**
175
     * @return EncodedPolyline|null
176
     */
177 12
    public function getOverviewPolyline()
178
    {
179 12
        return $this->overviewPolyline;
180
    }
181
182 8
    public function setOverviewPolyline(EncodedPolyline $overviewPolyline = null)
183
    {
184 8
        $this->overviewPolyline = $overviewPolyline;
185 8
    }
186
187
    /**
188
     * @return bool
189
     */
190 12
    public function hasSummary()
191
    {
192 12
        return null !== $this->summary;
193
    }
194
195
    /**
196
     * @return string|null
197
     */
198 12
    public function getSummary()
199
    {
200 12
        return $this->summary;
201
    }
202
203
    /**
204
     * @param string|null $summary
205
     */
206 8
    public function setSummary($summary = null)
207
    {
208 8
        $this->summary = $summary;
209 8
    }
210
211
    /**
212
     * @return bool
213
     */
214 12
    public function hasFare()
215
    {
216 12
        return null !== $this->fare;
217
    }
218
219
    /**
220
     * @return Fare|null
221
     */
222 12
    public function getFare()
223
    {
224 12
        return $this->fare;
225
    }
226
227 8
    public function setFare(Fare $fare = null)
228
    {
229 8
        $this->fare = $fare;
230 8
    }
231
232
    /**
233
     * @return bool
234
     */
235 20
    public function hasWarnings()
236
    {
237 20
        return !empty($this->warnings);
238
    }
239
240
    /**
241
     * @return string[]
242
     */
243 20
    public function getWarnings()
244
    {
245 20
        return $this->warnings;
246
    }
247
248
    /**
249
     * @param string[] $warnings
250
     */
251 8
    public function setWarnings(array $warnings)
252
    {
253 8
        $this->warnings = [];
254 8
        $this->addWarnings($warnings);
255 8
    }
256
257
    /**
258
     * @param string[] $warnings
259
     */
260 8
    public function addWarnings(array $warnings)
261
    {
262 8
        foreach ($warnings as $warning) {
263 8
            $this->addWarning($warning);
264
        }
265 8
    }
266
267
    /**
268
     * @param $warning
269
     *
270
     * @return bool
271
     */
272 16
    public function hasWarning($warning)
273
    {
274 16
        return in_array($warning, $this->warnings, true);
275
    }
276
277
    /**
278
     * @param string $warning
279
     */
280 16
    public function addWarning($warning)
281
    {
282 16
        if (!$this->hasWarning($warning)) {
283 16
            $this->warnings[] = $warning;
284
        }
285 16
    }
286
287
    /**
288
     * @param string $warning
289
     */
290 4
    public function removeWarning($warning)
291
    {
292 4
        unset($this->warnings[array_search($warning, $this->warnings, true)]);
293 4
        $this->warnings = empty($this->warnings) ? [] : array_values($this->warnings);
294 4
    }
295
296
    /**
297
     * @return bool
298
     */
299 12
    public function hasWaypointOrders()
300
    {
301 12
        return !empty($this->waypointOrders);
302
    }
303
304
    /**
305
     * @return int[]
306
     */
307 12
    public function getWaypointOrders()
308
    {
309 12
        return $this->waypointOrders;
310
    }
311
312
    /**
313
     * @param int[] $waypointOrders
314
     */
315 4
    public function setWaypointOrders(array $waypointOrders)
316
    {
317 4
        $this->waypointOrders = [];
318 4
        $this->addWaypointOrders($waypointOrders);
319 4
    }
320
321
    /**
322
     * @param int[] $waypointOrders
323
     */
324 4
    public function addWaypointOrders(array $waypointOrders)
325
    {
326 4
        $this->waypointOrders = [];
327
328 4
        foreach ($waypointOrders as $waypointOrder) {
329 4
            $this->addWaypointOrder($waypointOrder);
330
        }
331 4
    }
332
333
    /**
334
     * @param $waypointOrder
335
     *
336
     * @return bool
337
     */
338 8
    public function hasWaypointOrder($waypointOrder)
339
    {
340 8
        return in_array($waypointOrder, $this->waypointOrders, true);
341
    }
342
343
    /**
344
     * @param int $waypointOrder
345
     */
346 8
    public function addWaypointOrder($waypointOrder)
347
    {
348 8
        $this->waypointOrders[] = $waypointOrder;
349 8
    }
350
}
351