Completed
Push — master ( 5d031b...aa4864 )
by Tobias
03:51
created

GoogleAddress::getSubLocalityLevels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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
     * @param null|string $id
116
     *
117
     * @return GoogleAddress
118
     */
119 16
    public function withId(string $id = null)
120
    {
121 16
        $new = clone $this;
122 16
        $new->id = $id;
123
124 16
        return $new;
125
    }
126
127
    /**
128
     * @see https://developers.google.com/places/place-id
129
     *
130
     * @return null|string
131
     */
132 3
    public function getId()
133
    {
134 3
        return $this->id;
135
    }
136
137
    /**
138
     * @param null|string $locationType
139
     *
140
     * @return GoogleAddress
141
     */
142 16
    public function withLocationType(string $locationType = null)
143
    {
144 16
        $new = clone $this;
145 16
        $new->locationType = $locationType;
146
147 16
        return $new;
148
    }
149
150
    /**
151
     * @return null|string
152
     */
153
    public function getLocationType()
154
    {
155
        return $this->locationType;
156
    }
157
158
    /**
159
     * @return array
160
     */
161
    public function getResultType(): array
162
    {
163
        return $this->resultType;
164
    }
165
166
    /**
167
     * @param array $resultType
168
     *
169
     * @return GoogleAddress
170
     */
171 16
    public function withResultType(array $resultType)
172
    {
173 16
        $new = clone $this;
174 16
        $new->resultType = $resultType;
175
176 16
        return $new;
177
    }
178
179
    /**
180
     * @return null|string
181
     */
182
    public function getFormattedAddress()
183
    {
184
        return $this->formattedAddress;
185
    }
186
187
    /**
188
     * @param string|null $formattedAddress
189
     *
190
     * @return GoogleAddress
191
     */
192 16
    public function withFormattedAddress(string $formattedAddress = null)
193
    {
194 16
        $new = clone $this;
195 16
        $new->formattedAddress = $formattedAddress;
196
197 16
        return $new;
198
    }
199
200
    /**
201
     * @return null|string
202
     */
203 1
    public function getAirport()
204
    {
205 1
        return $this->airport;
206
    }
207
208
    /**
209
     * @param string|null $airport
210
     *
211
     * @return GoogleAddress
212
     */
213 16
    public function withAirport(string $airport = null)
214
    {
215 16
        $new = clone $this;
216 16
        $new->airport = $airport;
217
218 16
        return $new;
219
    }
220
221
    /**
222
     * @return null|string
223
     */
224 1
    public function getColloquialArea()
225
    {
226 1
        return $this->colloquialArea;
227
    }
228
229
    /**
230
     * @param string|null $colloquialArea
231
     *
232
     * @return GoogleAddress
233
     */
234 16
    public function withColloquialArea(string $colloquialArea = null)
235
    {
236 16
        $new = clone $this;
237 16
        $new->colloquialArea = $colloquialArea;
238
239 16
        return $new;
240
    }
241
242
    /**
243
     * @return null|string
244
     */
245
    public function getIntersection()
246
    {
247
        return $this->intersection;
248
    }
249
250
    /**
251
     * @param string|null $intersection
252
     *
253
     * @return GoogleAddress
254
     */
255 16
    public function withIntersection(string $intersection = null)
256
    {
257 16
        $new = clone $this;
258 16
        $new->intersection = $intersection;
259
260 16
        return $new;
261
    }
262
263
    /**
264
     * @return null|string
265
     */
266 1
    public function getNaturalFeature()
267
    {
268 1
        return $this->naturalFeature;
269
    }
270
271
    /**
272
     * @param string|null $naturalFeature
273
     *
274
     * @return GoogleAddress
275
     */
276 16
    public function withNaturalFeature(string $naturalFeature = null)
277
    {
278 16
        $new = clone $this;
279 16
        $new->naturalFeature = $naturalFeature;
280
281 16
        return $new;
282
    }
283
284
    /**
285
     * @return null|string
286
     */
287 1
    public function getNeighborhood()
288
    {
289 1
        return $this->neighborhood;
290
    }
291
292
    /**
293
     * @param string|null $neighborhood
294
     *
295
     * @return GoogleAddress
296
     */
297 16
    public function withNeighborhood(string $neighborhood = null)
298
    {
299 16
        $new = clone $this;
300 16
        $new->neighborhood = $neighborhood;
301
302 16
        return $new;
303
    }
304
305
    /**
306
     * @return null|string
307
     */
308 1
    public function getPark()
309
    {
310 1
        return $this->park;
311
    }
312
313
    /**
314
     * @param string|null $park
315
     *
316
     * @return GoogleAddress
317
     */
318 16
    public function withPark(string $park = null)
319
    {
320 16
        $new = clone $this;
321 16
        $new->park = $park;
322
323 16
        return $new;
324
    }
325
326
    /**
327
     * @return null|string
328
     */
329 2
    public function getPointOfInterest()
330
    {
331 2
        return $this->pointOfInterest;
332
    }
333
334
    /**
335
     * @param string|null $pointOfInterest
336
     *
337
     * @return GoogleAddress
338
     */
339 16
    public function withPointOfInterest(string $pointOfInterest = null)
340
    {
341 16
        $new = clone $this;
342 16
        $new->pointOfInterest = $pointOfInterest;
343
344 16
        return $new;
345
    }
346
347
    /**
348
     * @return null|string
349
     */
350 1
    public function getPolitical()
351
    {
352 1
        return $this->political;
353
    }
354
355
    /**
356
     * @param string|null $political
357
     *
358
     * @return GoogleAddress
359
     */
360 16
    public function withPolitical(string $political = null)
361
    {
362 16
        $new = clone $this;
363 16
        $new->political = $political;
364
365 16
        return $new;
366
    }
367
368
    /**
369
     * @return null|string
370
     */
371 1
    public function getPremise()
372
    {
373 1
        return $this->premise;
374
    }
375
376
    /**
377
     * @param null $premise
378
     *
379
     * @return GoogleAddress
380
     */
381 16
    public function withPremise(string $premise = null)
382
    {
383 16
        $new = clone $this;
384 16
        $new->premise = $premise;
385
386 16
        return $new;
387
    }
388
389
    /**
390
     * @return null|string
391
     */
392
    public function getStreetAddress()
393
    {
394
        return $this->streetAddress;
395
    }
396
397
    /**
398
     * @param string|null $streetAddress
399
     *
400
     * @return GoogleAddress
401
     */
402 16
    public function withStreetAddress(string $streetAddress = null)
403
    {
404 16
        $new = clone $this;
405 16
        $new->streetAddress = $streetAddress;
406
407 16
        return $new;
408
    }
409
410
    /**
411
     * @return null|string
412
     */
413 1
    public function getSubpremise()
414
    {
415 1
        return $this->subpremise;
416
    }
417
418
    /**
419
     * @param string|null $subpremise
420
     *
421
     * @return GoogleAddress
422
     */
423 16
    public function withSubpremise(string $subpremise = null)
424
    {
425 16
        $new = clone $this;
426 16
        $new->subpremise = $subpremise;
427
428 16
        return $new;
429
    }
430
431
    /**
432
     * @return null|string
433
     */
434 1
    public function getWard()
435
    {
436 1
        return $this->ward;
437
    }
438
439
    /**
440
     * @param string|null $ward
441
     *
442
     * @return GoogleAddress
443
     */
444 16
    public function withWard(string $ward = null)
445
    {
446 16
        $new = clone $this;
447 16
        $new->ward = $ward;
448
449 16
        return $new;
450
    }
451
452
    /**
453
     * @return null|string
454
     */
455 1
    public function getEstablishment()
456
    {
457 1
        return $this->establishment;
458
    }
459
460
    /**
461
     * @param string|null $establishment
462
     *
463
     * @return GoogleAddress
464
     */
465 16
    public function withEstablishment(string $establishment = null)
466
    {
467 16
        $new = clone $this;
468 16
        $new->establishment = $establishment;
469
470 16
        return $new;
471
    }
472
473
    /**
474
     * @return AdminLevelCollection
475
     */
476 1
    public function getSubLocalityLevels()
477
    {
478 1
        return $this->subLocalityLevels;
479
    }
480
481
    /**
482
     * @param array $subLocalityLevel
483
     *
484
     * @return $this
485
     */
486 16
    public function withSubLocalityLevels(array $subLocalityLevel)
487
    {
488 16
        $subLocalityLevels = [];
489 16
        foreach ($subLocalityLevel as $level) {
490 6
            if (empty($level['level'])) {
491
                continue;
492
            }
493
494 6
            $name = $level['name'] ?? $level['code'] ?? null;
495 6
            if (empty($name)) {
496
                continue;
497
            }
498
499 6
            $subLocalityLevels[] = new AdminLevel($level['level'], $name, $level['code'] ?? null);
500
        }
501
502 16
        $new = clone $this;
503 16
        $new->subLocalityLevels = new AdminLevelCollection($subLocalityLevels);
504
505 16
        return $new;
506
    }
507
}
508