Completed
Push — master ( 0932c1...0a23f4 )
by Tobias
23:05
created

GoogleAddress::withPartialMatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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