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
Pull Request — master (#243)
by Eric
66:10
created

DistanceMatrixRequest::getArrivalTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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\DistanceMatrix\Request;
13
14
use Ivory\GoogleMap\Service\Base\Location\EncodedPolylineLocation;
15
use Ivory\GoogleMap\Service\Base\Location\LocationInterface;
16
17
/**
18
 * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixRequest
19
 *
20
 * @author GeLo <[email protected]>
21
 */
22
class DistanceMatrixRequest implements DistanceMatrixRequestInterface
23
{
24
    /**
25
     * @var LocationInterface[]
26
     */
27
    private $origins = [];
28
29
    /**
30
     * @var LocationInterface[]
31
     */
32
    private $destinations = [];
33
34
    /**
35
     * @var \DateTime|null
36
     */
37
    private $departureTime;
38
39
    /**
40
     * @var \DateTime|null
41
     */
42
    private $arrivalTime;
43
44
    /**
45
     * @var string|null
46
     */
47
    private $travelMode;
48
49
    /**
50
     * @var string|null
51
     */
52
    private $avoid;
53
54
    /**
55
     * @var string|null
56
     */
57
    private $trafficModel;
58
59
    /**
60
     * @var string[]
61
     */
62
    private $transitModes = [];
63
64
    /**
65
     * @var string|null
66
     */
67
    private $transitRoutingPreference;
68
69
    /**
70
     * @var string|null
71
     */
72
    private $region;
73
74
    /**
75
     * @var string|null
76
     */
77
    private $unitSystem;
78
79
    /**
80
     * @var string|null
81
     */
82
    private $language;
83
84
    /**
85
     * @param LocationInterface[] $origins
86
     * @param LocationInterface[] $destinations
87 340
     */
88
    public function __construct(array $origins, array $destinations)
89 340
    {
90 340
        $this->setOrigins($origins);
91 340
        $this->setDestinations($destinations);
92
    }
93
94
    /**
95
     * @return bool
96 20
     */
97
    public function hasOrigins()
98 20
    {
99
        return !empty($this->origins);
100
    }
101
102
    /**
103
     * @return LocationInterface[]
104 20
     */
105
    public function getOrigins()
106 20
    {
107
        return $this->origins;
108
    }
109
110
    /**
111
     * @param LocationInterface[] $origins
112 340
     */
113
    public function setOrigins(array $origins)
114 340
    {
115 340
        $this->origins = [];
116 340
        $this->addOrigins($origins);
117
    }
118
119
    /**
120
     * @param LocationInterface[] $origins
121 340
     */
122
    public function addOrigins(array $origins)
123 340
    {
124 340
        foreach ($origins as $origin) {
125 170
            $this->addOrigin($origin);
126 340
        }
127
    }
128
129
    /**
130
     * @param LocationInterface $origin
131
     *
132
     * @return bool
133 340
     */
134
    public function hasOrigin(LocationInterface $origin)
135 340
    {
136
        return in_array($origin, $this->origins, true);
137
    }
138
139
    /**
140
     * @param LocationInterface $origin
141 340
     */
142
    public function addOrigin(LocationInterface $origin)
143 340
    {
144 340
        if (!$this->hasOrigin($origin)) {
145 170
            $this->origins[] = $origin;
146 340
        }
147
    }
148
149
    /**
150
     * @param LocationInterface $origin
151 4
     */
152
    public function removeOrigin(LocationInterface $origin)
153 4
    {
154 4
        unset($this->origins[array_search($origin, $this->origins, true)]);
155 4
        $this->origins = empty($this->origins) ? [] : array_values($this->origins);
156
    }
157
158
    /**
159
     * @return bool
160 20
     */
161
    public function hasDestinations()
162 20
    {
163
        return !empty($this->destinations);
164
    }
165
166
    /**
167
     * @return LocationInterface[]
168 20
     */
169
    public function getDestinations()
170 20
    {
171
        return $this->destinations;
172
    }
173
174
    /**
175
     * @param LocationInterface[] $destinations
176 340
     */
177
    public function setDestinations(array $destinations)
178 340
    {
179 340
        $this->destinations = [];
180 340
        $this->addDestinations($destinations);
181
    }
182
183
    /**
184
     * @param LocationInterface[] $destinations
185 340
     */
186
    public function addDestinations(array $destinations)
187 340
    {
188 340
        foreach ($destinations as $destination) {
189 170
            $this->addDestination($destination);
190 340
        }
191
    }
192
193
    /**
194
     * @param LocationInterface $destination
195
     *
196
     * @return bool
197 340
     */
198
    public function hasDestination(LocationInterface $destination)
199 340
    {
200
        return in_array($destination, $this->destinations, true);
201
    }
202
203
    /**
204
     * @param LocationInterface $destination
205 340
     */
206
    public function addDestination(LocationInterface $destination)
207 340
    {
208 340
        if (!$this->hasDestination($destination)) {
209 170
            $this->destinations[] = $destination;
210 340
        }
211
    }
212
213
    /**
214
     * @param LocationInterface $destination
215 4
     */
216
    public function removeDestination(LocationInterface $destination)
217 4
    {
218 4
        unset($this->destinations[array_search($destination, $this->destinations, true)]);
219 4
        $this->destinations = empty($this->destinations) ? [] : array_values($this->destinations);
220
    }
221
222
    /**
223
     * @return bool
224 224
     */
225
    public function hasDepartureTime()
226 224
    {
227
        return $this->departureTime !== null;
228
    }
229
230
    /**
231
     * @return \DateTime|null
232 12
     */
233
    public function getDepartureTime()
234 12
    {
235
        return $this->departureTime;
236
    }
237
238
    /**
239
     * @param \DateTime|null $departureTime
240 28
     */
241
    public function setDepartureTime(\DateTime $departureTime = null)
242 28
    {
243 28
        $this->departureTime = $departureTime;
244
    }
245
246
    /**
247
     * @return bool
248 224
     */
249
    public function hasArrivalTime()
250 224
    {
251
        return $this->arrivalTime !== null;
252
    }
253
254
    /**
255
     * @return \DateTime|null
256 12
     */
257
    public function getArrivalTime()
258 12
    {
259
        return $this->arrivalTime;
260
    }
261
262
    /**
263
     * @param \DateTime|null $arrivalTime
264 28
     */
265
    public function setArrivalTime(\DateTime $arrivalTime = null)
266 28
    {
267 28
        $this->arrivalTime = $arrivalTime;
268
    }
269
270
    /**
271
     * @return bool
272 224
     */
273
    public function hasTravelMode()
274 224
    {
275
        return $this->travelMode !== null;
276
    }
277
278
    /**
279
     * @return string|null
280 12
     */
281
    public function getTravelMode()
282 12
    {
283
        return $this->travelMode;
284
    }
285
286
    /**
287
     * @param string|null $travelMode
288 28
     */
289
    public function setTravelMode($travelMode = null)
290 28
    {
291 28
        $this->travelMode = $travelMode;
292
    }
293
294
    /**
295
     * @return bool
296 224
     */
297
    public function hasAvoid()
298 224
    {
299
        return $this->avoid !== null;
300
    }
301
302
    /**
303
     * @return string|null
304 12
     */
305
    public function getAvoid()
306 12
    {
307
        return $this->avoid;
308
    }
309
310
    /**
311
     * @param string|null $avoid
312 28
     */
313
    public function setAvoid($avoid = null)
314 28
    {
315 28
        $this->avoid = $avoid;
316
    }
317
318
    /**
319
     * @return bool
320 224
     */
321
    public function hasTrafficModel()
322 224
    {
323
        return $this->trafficModel !== null;
324
    }
325
326
    /**
327
     * @return string|null
328 12
     */
329
    public function getTrafficModel()
330 12
    {
331
        return $this->trafficModel;
332
    }
333
334
    /**
335
     * @param string|null $trafficModel
336 12
     */
337
    public function setTrafficModel($trafficModel)
338 12
    {
339 12
        $this->trafficModel = $trafficModel;
340
    }
341
342
    /**
343
     * @return bool
344 232
     */
345
    public function hasTransitModes()
346 232
    {
347
        return !empty($this->transitModes);
348
    }
349
350
    /**
351
     * @return string[]
352 20
     */
353
    public function getTransitModes()
354 20
    {
355
        return $this->transitModes;
356
    }
357
358
    /**
359
     * @param string[] $transitModes
360 12
     */
361
    public function setTransitModes(array $transitModes)
362 12
    {
363 12
        $this->transitModes = [];
364 12
        $this->addTransitModes($transitModes);
365
    }
366
367
    /**
368
     * @param string[] $transitModes
369 12
     */
370
    public function addTransitModes(array $transitModes)
371 12
    {
372 12
        foreach ($transitModes as $transitMode) {
373 6
            $this->addTransitMode($transitMode);
374 12
        }
375
    }
376
377
    /**
378
     * @param string $transitMode
379
     *
380
     * @return bool
381 20
     */
382
    public function hasTransitMode($transitMode)
383 20
    {
384
        return in_array($transitMode, $this->transitModes, true);
385
    }
386
387
    /**
388
     * @param string $transitMode
389 20
     */
390
    public function addTransitMode($transitMode)
391 20
    {
392 20
        if (!$this->hasTransitMode($transitMode)) {
393 10
            $this->transitModes[] = $transitMode;
394 20
        }
395
    }
396
397
    /**
398
     * @param string $transitMode
399 4
     */
400
    public function removeTransitMode($transitMode)
401 4
    {
402 4
        unset($this->transitModes[array_search($transitMode, $this->transitModes, true)]);
403 4
        $this->transitModes = empty($this->transitModes) ? [] : array_values($this->transitModes);
404
    }
405
406
    /**
407
     * @return bool
408 224
     */
409
    public function hasTransitRoutingPreference()
410 224
    {
411
        return $this->transitRoutingPreference !== null;
412
    }
413
414
    /**
415
     * @return string|null
416 12
     */
417
    public function getTransitRoutingPreference()
418 12
    {
419
        return $this->transitRoutingPreference;
420
    }
421
422
    /**
423
     * @param string|null $transitRoutingPreference
424 12
     */
425
    public function setTransitRoutingPreference($transitRoutingPreference)
426 12
    {
427 12
        $this->transitRoutingPreference = $transitRoutingPreference;
428
    }
429
430
    /**
431
     * @return bool
432 224
     */
433
    public function hasRegion()
434 224
    {
435
        return $this->region !== null;
436
    }
437
438
    /**
439
     * @return string|null
440 12
     */
441
    public function getRegion()
442 12
    {
443
        return $this->region;
444
    }
445
446
    /**
447
     * @param string|null $region
448 28
     */
449
    public function setRegion($region = null)
450 28
    {
451 28
        $this->region = $region;
452
    }
453
454
    /**
455
     * @return bool
456 224
     */
457
    public function hasUnitSystem()
458 224
    {
459
        return $this->unitSystem !== null;
460
    }
461
462
    /**
463
     * @return string|null
464 12
     */
465
    public function getUnitSystem()
466 12
    {
467
        return $this->unitSystem;
468
    }
469
470
    /**
471
     * @param string|null $unitSystem
472 28
     */
473
    public function setUnitSystem($unitSystem = null)
474 28
    {
475 28
        $this->unitSystem = $unitSystem;
476
    }
477
478
    /**
479
     * @return bool
480 224
     */
481
    public function hasLanguage()
482 224
    {
483
        return $this->language !== null;
484
    }
485
486
    /**
487
     * @return string|null
488 12
     */
489
    public function getLanguage()
490 12
    {
491
        return $this->language;
492
    }
493
494
    /**
495
     * @param string|null $language
496 28
     */
497
    public function setLanguage($language = null)
498 28
    {
499 28
        $this->language = $language;
500
    }
501
502
    /**
503
     * {@inheritdoc}
504
     */
505
    public function buildQuery()
506 212
    {
507 212
        $locationBuilder = function (LocationInterface $location) {
508 159
            $result = $location->buildQuery();
509
510
            if ($location instanceof EncodedPolylineLocation) {
511 212
                $result .= ':';
512 212
            }
513 106
514
            return $result;
515 212
        };
516 20
517 10
        $query = [
518
            'origins'      => implode('|', array_map($locationBuilder, $this->origins)),
519 212
            'destinations' => implode('|', array_map($locationBuilder, $this->destinations)),
520 20
        ];
521 10
522
        if ($this->hasDepartureTime()) {
523 212
            $query['departure_time'] = $this->departureTime->getTimestamp();
524 20
        }
525 10
526
        if ($this->hasArrivalTime()) {
527 212
            $query['arrival_time'] = $this->arrivalTime->getTimestamp();
528 20
        }
529 10
530
        if ($this->hasTravelMode()) {
531 212
            $query['mode'] = strtolower($this->travelMode);
532 4
        }
533 2
534
        if ($this->hasAvoid()) {
535 212
            $query['avoid'] = $this->avoid;
536 4
        }
537 2
538
        if ($this->hasTrafficModel()) {
539 212
            $query['traffic_model'] = $this->trafficModel;
540 4
        }
541 2
542
        if ($this->hasTransitModes()) {
543 212
            $query['transit_mode'] = implode('|', $this->transitModes);
544 20
        }
545 10
546
        if ($this->hasTransitRoutingPreference()) {
547 212
            $query['transit_routing_preference'] = $this->transitRoutingPreference;
548 20
        }
549 10
550
        if ($this->hasUnitSystem()) {
551 212
            $query['units'] = strtolower($this->unitSystem);
552 20
        }
553 10
554
        if ($this->hasRegion()) {
555 212
            $query['region'] = $this->region;
556
        }
557
558
        if ($this->hasLanguage()) {
559
            $query['language'] = $this->language;
560
        }
561
562
        return $query;
563
    }
564
}
565