Completed
Push — master ( 307ca3...eb8c69 )
by Tobias
07:22
created

GoogleAddress::getWard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Provider\GoogleMaps\Model;
14
15
use Geocoder\Model\Address;
16
use Geocoder\Model\AdminLevel;
17
use Geocoder\Model\AdminLevelCollection;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
final class GoogleAddress extends Address
23
{
24
    /**
25
     * @var string|null
26
     */
27
    private $id;
28
29
    /**
30
     * @var string|null
31
     */
32
    private $locationType;
33
34
    /**
35
     * @var array
36
     */
37
    private $resultType = [];
38
39
    /**
40
     * @var string|null
41
     */
42
    private $formattedAddress;
43
44
    /**
45
     * @var string|null
46
     */
47
    private $streetAddress;
48
49
    /**
50
     * @var string|null
51
     */
52
    private $intersection;
53
54
    /**
55
     * @var string|null
56
     */
57
    private $political;
58
59
    /**
60
     * @var string|null
61
     */
62
    private $colloquialArea;
63
64
    /**
65
     * @var string|null
66
     */
67
    private $ward;
68
69
    /**
70
     * @var string|null
71
     */
72
    private $neighborhood;
73
74
    /**
75
     * @var string|null
76
     */
77
    private $premise;
78
79
    /**
80
     * @var string|null
81
     */
82
    private $subpremise;
83
84
    /**
85
     * @var string|null
86
     */
87
    private $naturalFeature;
88
89
    /**
90
     * @var string|null
91
     */
92
    private $airport;
93
94
    /**
95
     * @var string|null
96
     */
97
    private $park;
98
99
    /**
100
     * @var string|null
101
     */
102
    private $pointOfInterest;
103
104
    /**
105
     * @var string|null
106
     */
107
    private $establishment;
108
109
    /**
110
     * @var AdminLevelCollection
111
     */
112
    private $subLocalityLevels;
113
114
    /**
115
     * @var bool
116
     */
117
    private $partialMatch;
118
119
    /**
120
     * @param null|string $id
121
     *
122
     * @return GoogleAddress
123
     */
124 17
    public function withId(string $id = null)
125
    {
126 17
        $new = clone $this;
127 17
        $new->id = $id;
128
129 17
        return $new;
130
    }
131
132
    /**
133
     * @see https://developers.google.com/places/place-id
134
     *
135
     * @return null|string
136
     */
137 4
    public function getId()
138
    {
139 4
        return $this->id;
140
    }
141
142
    /**
143
     * @param null|string $locationType
144
     *
145
     * @return GoogleAddress
146
     */
147 17
    public function withLocationType(string $locationType = null)
148
    {
149 17
        $new = clone $this;
150 17
        $new->locationType = $locationType;
151
152 17
        return $new;
153
    }
154
155
    /**
156
     * @return null|string
157
     */
158
    public function getLocationType()
159
    {
160
        return $this->locationType;
161
    }
162
163
    /**
164
     * @return array
165
     */
166
    public function getResultType(): array
167
    {
168
        return $this->resultType;
169
    }
170
171
    /**
172
     * @param array $resultType
173
     *
174
     * @return GoogleAddress
175
     */
176 17
    public function withResultType(array $resultType)
177
    {
178 17
        $new = clone $this;
179 17
        $new->resultType = $resultType;
180
181 17
        return $new;
182
    }
183
184
    /**
185
     * @return null|string
186
     */
187
    public function getFormattedAddress()
188
    {
189
        return $this->formattedAddress;
190
    }
191
192
    /**
193
     * @param string|null $formattedAddress
194
     *
195
     * @return GoogleAddress
196
     */
197 17
    public function withFormattedAddress(string $formattedAddress = null)
198
    {
199 17
        $new = clone $this;
200 17
        $new->formattedAddress = $formattedAddress;
201
202 17
        return $new;
203
    }
204
205
    /**
206
     * @return null|string
207
     */
208 1
    public function getAirport()
209
    {
210 1
        return $this->airport;
211
    }
212
213
    /**
214
     * @param string|null $airport
215
     *
216
     * @return GoogleAddress
217
     */
218 17
    public function withAirport(string $airport = null)
219
    {
220 17
        $new = clone $this;
221 17
        $new->airport = $airport;
222
223 17
        return $new;
224
    }
225
226
    /**
227
     * @return null|string
228
     */
229 1
    public function getColloquialArea()
230
    {
231 1
        return $this->colloquialArea;
232
    }
233
234
    /**
235
     * @param string|null $colloquialArea
236
     *
237
     * @return GoogleAddress
238
     */
239 17
    public function withColloquialArea(string $colloquialArea = null)
240
    {
241 17
        $new = clone $this;
242 17
        $new->colloquialArea = $colloquialArea;
243
244 17
        return $new;
245
    }
246
247
    /**
248
     * @return null|string
249
     */
250
    public function getIntersection()
251
    {
252
        return $this->intersection;
253
    }
254
255
    /**
256
     * @param string|null $intersection
257
     *
258
     * @return GoogleAddress
259
     */
260 17
    public function withIntersection(string $intersection = null)
261
    {
262 17
        $new = clone $this;
263 17
        $new->intersection = $intersection;
264
265 17
        return $new;
266
    }
267
268
    /**
269
     * @return null|string
270
     */
271 1
    public function getNaturalFeature()
272
    {
273 1
        return $this->naturalFeature;
274
    }
275
276
    /**
277
     * @param string|null $naturalFeature
278
     *
279
     * @return GoogleAddress
280
     */
281 17
    public function withNaturalFeature(string $naturalFeature = null)
282
    {
283 17
        $new = clone $this;
284 17
        $new->naturalFeature = $naturalFeature;
285
286 17
        return $new;
287
    }
288
289
    /**
290
     * @return null|string
291
     */
292 1
    public function getNeighborhood()
293
    {
294 1
        return $this->neighborhood;
295
    }
296
297
    /**
298
     * @param string|null $neighborhood
299
     *
300
     * @return GoogleAddress
301
     */
302 17
    public function withNeighborhood(string $neighborhood = null)
303
    {
304 17
        $new = clone $this;
305 17
        $new->neighborhood = $neighborhood;
306
307 17
        return $new;
308
    }
309
310
    /**
311
     * @return null|string
312
     */
313 1
    public function getPark()
314
    {
315 1
        return $this->park;
316
    }
317
318
    /**
319
     * @param string|null $park
320
     *
321
     * @return GoogleAddress
322
     */
323 17
    public function withPark(string $park = null)
324
    {
325 17
        $new = clone $this;
326 17
        $new->park = $park;
327
328 17
        return $new;
329
    }
330
331
    /**
332
     * @return null|string
333
     */
334 2
    public function getPointOfInterest()
335
    {
336 2
        return $this->pointOfInterest;
337
    }
338
339
    /**
340
     * @param string|null $pointOfInterest
341
     *
342
     * @return GoogleAddress
343
     */
344 17
    public function withPointOfInterest(string $pointOfInterest = null)
345
    {
346 17
        $new = clone $this;
347 17
        $new->pointOfInterest = $pointOfInterest;
348
349 17
        return $new;
350
    }
351
352
    /**
353
     * @return null|string
354
     */
355 1
    public function getPolitical()
356
    {
357 1
        return $this->political;
358
    }
359
360
    /**
361
     * @param string|null $political
362
     *
363
     * @return GoogleAddress
364
     */
365 17
    public function withPolitical(string $political = null)
366
    {
367 17
        $new = clone $this;
368 17
        $new->political = $political;
369
370 17
        return $new;
371
    }
372
373
    /**
374
     * @return null|string
375
     */
376 1
    public function getPremise()
377
    {
378 1
        return $this->premise;
379
    }
380
381
    /**
382
     * @param string $premise
383
     *
384
     * @return GoogleAddress
385
     */
386 17
    public function withPremise(string $premise = null)
387
    {
388 17
        $new = clone $this;
389 17
        $new->premise = $premise;
390
391 17
        return $new;
392
    }
393
394
    /**
395
     * @return null|string
396
     */
397
    public function getStreetAddress()
398
    {
399
        return $this->streetAddress;
400
    }
401
402
    /**
403
     * @param string|null $streetAddress
404
     *
405
     * @return GoogleAddress
406
     */
407 17
    public function withStreetAddress(string $streetAddress = null)
408
    {
409 17
        $new = clone $this;
410 17
        $new->streetAddress = $streetAddress;
411
412 17
        return $new;
413
    }
414
415
    /**
416
     * @return null|string
417
     */
418 1
    public function getSubpremise()
419
    {
420 1
        return $this->subpremise;
421
    }
422
423
    /**
424
     * @param string|null $subpremise
425
     *
426
     * @return GoogleAddress
427
     */
428 17
    public function withSubpremise(string $subpremise = null)
429
    {
430 17
        $new = clone $this;
431 17
        $new->subpremise = $subpremise;
432
433 17
        return $new;
434
    }
435
436
    /**
437
     * @return null|string
438
     */
439
    public function getWard()
440
    {
441
        return $this->ward;
442
    }
443
444
    /**
445
     * @param string|null $ward
446
     *
447
     * @return GoogleAddress
448
     */
449 17
    public function withWard(string $ward = null)
450
    {
451 17
        $new = clone $this;
452 17
        $new->ward = $ward;
453
454 17
        return $new;
455
    }
456
457
    /**
458
     * @return null|string
459
     */
460 1
    public function getEstablishment()
461
    {
462 1
        return $this->establishment;
463
    }
464
465
    /**
466
     * @param string|null $establishment
467
     *
468
     * @return GoogleAddress
469
     */
470 17
    public function withEstablishment(string $establishment = null)
471
    {
472 17
        $new = clone $this;
473 17
        $new->establishment = $establishment;
474
475 17
        return $new;
476
    }
477
478
    /**
479
     * @return AdminLevelCollection
480
     */
481 1
    public function getSubLocalityLevels()
482
    {
483 1
        return $this->subLocalityLevels;
484
    }
485
486
    /**
487
     * @param array $subLocalityLevel
488
     *
489
     * @return $this
490
     */
491 17
    public function withSubLocalityLevels(array $subLocalityLevel)
492
    {
493 17
        $subLocalityLevels = [];
494 17
        foreach ($subLocalityLevel as $level) {
495 3
            if (empty($level['level'])) {
496
                continue;
497
            }
498
499 3
            $name = $level['name'] ?? $level['code'] ?? '';
500 3
            if (empty($name)) {
501
                continue;
502
            }
503
504 3
            $subLocalityLevels[] = new AdminLevel($level['level'], $name, $level['code'] ?? null);
505
        }
506
507 17
        $subLocalityLevels = array_unique($subLocalityLevels);
508
509 17
        $new = clone $this;
510 17
        $new->subLocalityLevels = new AdminLevelCollection($subLocalityLevels);
511
512 17
        return $new;
513
    }
514
515
    /**
516
     * @return bool
517
     */
518 15
    public function isPartialMatch()
519
    {
520 15
        return $this->partialMatch;
521
    }
522
523
    /**
524
     * @param bool $partialMatch
525
     *
526
     * @return $this
527
     */
528 17
    public function withPartialMatch(bool $partialMatch)
529
    {
530 17
        $new = clone $this;
531 17
        $new->partialMatch = $partialMatch;
532
533 17
        return $new;
534
    }
535
}
536