Passed
Push — feature/v4 ( e5e380...dac4aa )
by Samuel
11:37
created

Place::hasId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Ivory Google Map package.
7
 *
8
 * (c) Eric GELOEN <[email protected]>
9
 *
10
 * For the full copyright and license information, please read the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ivory\GoogleMap\Service\Place\Base;
15
16
use Ivory\GoogleMap\Service\Base\AddressComponent;
17
use Ivory\GoogleMap\Service\Base\Geometry;
18
19
class Place
20
{
21
    /** @var string|null */
22
    private $id;
23
24
    /** @var string|null */
25
    private $placeId;
26
27
    /** @var string|null */
28
    private $name;
29
30
    /** @var string|null */
31
    private $formattedAddress;
32
33
    /** @var string|null */
34
    private $formattedPhoneNumber;
35
36
    /** @var string|null */
37
    private $internationalPhoneNumber;
38
39
    /** @var string|null */
40
    private $url;
41
42
    /** @var string|null */
43
    private $icon;
44
45
    /** @var string|null */
46
    private $scope;
47
48
    /** @var int|null */
49
    private $priceLevel;
50
51
    /** @var float|null */
52
    private $rating;
53
54
    /** @var int|null */
55
    private $utcOffset;
56
57
    /** @var string|null */
58
    private $vicinity;
59
60
    /** @var string|null */
61
    private $website;
62
63
    /** @var Geometry|null */
64
    private $geometry;
65
66
    /** @var OpeningHours|null */
67
    private $openingHours;
68
69
    /** @var AddressComponent[] */
70
    private $addressComponents = [];
71
72
    /** @var Photo[] */
73
    private $photos = [];
74
75
    /** @var AlternatePlaceId[] */
76
    private $alternatePlaceIds = [];
77
78
    /** @var Review[] */
79
    private $reviews = [];
80
81
    /** @var string[] */
82
    private $types = [];
83
84
    /** @var bool|null */
85
    private $permanentlyClose;
86
87 2
    public function hasId(): bool
88
    {
89 2
        return null !== $this->id;
90
    }
91
92 2
    public function getId(): ?string
93
    {
94 2
        return $this->id;
95
    }
96
97 1
    public function setId(?string $id): void
98
    {
99 1
        $this->id = $id;
100 1
    }
101
102 2
    public function hasPlaceId(): bool
103
    {
104 2
        return null !== $this->placeId;
105
    }
106
107 2
    public function getPlaceId(): ?string
108
    {
109 2
        return $this->placeId;
110
    }
111
112 1
    public function setPlaceId(?string $placeId): void
113
    {
114 1
        $this->placeId = $placeId;
115 1
    }
116
117 2
    public function hasName(): bool
118
    {
119 2
        return null !== $this->name;
120
    }
121
122 2
    public function getName(): ?string
123
    {
124 2
        return $this->name;
125
    }
126
127 1
    public function setName(?string $name): void
128
    {
129 1
        $this->name = $name;
130 1
    }
131
132 2
    public function hasFormattedAddress(): bool
133
    {
134 2
        return null !== $this->formattedAddress;
135
    }
136
137 2
    public function getFormattedAddress(): ?string
138
    {
139 2
        return $this->formattedAddress;
140
    }
141
142 1
    public function setFormattedAddress(?string $formattedAddress): void
143
    {
144 1
        $this->formattedAddress = $formattedAddress;
145 1
    }
146
147 2
    public function hasFormattedPhoneNumber(): bool
148
    {
149 2
        return null !== $this->formattedPhoneNumber;
150
    }
151
152 2
    public function getFormattedPhoneNumber(): ?string
153
    {
154 2
        return $this->formattedPhoneNumber;
155
    }
156
157 1
    public function setFormattedPhoneNumber(?string $formattedPhoneNumber): void
158
    {
159 1
        $this->formattedPhoneNumber = $formattedPhoneNumber;
160 1
    }
161
162 2
    public function hasInternationalPhoneNumber(): bool
163
    {
164 2
        return null !== $this->internationalPhoneNumber;
165
    }
166
167 2
    public function getInternationalPhoneNumber(): ?string
168
    {
169 2
        return $this->internationalPhoneNumber;
170
    }
171
172 1
    public function setInternationalPhoneNumber(?string $internationalPhoneNumber): void
173
    {
174 1
        $this->internationalPhoneNumber = $internationalPhoneNumber;
175 1
    }
176
177 2
    public function hasUrl(): bool
178
    {
179 2
        return null !== $this->url;
180
    }
181
182 2
    public function getUrl(): ?string
183
    {
184 2
        return $this->url;
185
    }
186
187 1
    public function setUrl(?string $url): void
188
    {
189 1
        $this->url = $url;
190 1
    }
191
192 2
    public function hasIcon(): bool
193
    {
194 2
        return null !== $this->icon;
195
    }
196
197 2
    public function getIcon(): ?string
198
    {
199 2
        return $this->icon;
200
    }
201
202 1
    public function setIcon(?string $icon): void
203
    {
204 1
        $this->icon = $icon;
205 1
    }
206
207 2
    public function hasScope(): bool
208
    {
209 2
        return null !== $this->scope;
210
    }
211
212 2
    public function getScope(): ?string
213
    {
214 2
        return $this->scope;
215
    }
216
217 1
    public function setScope(?string $scope): void
218
    {
219 1
        $this->scope = $scope;
220 1
    }
221
222 2
    public function hasPriceLevel(): bool
223
    {
224 2
        return null !== $this->priceLevel;
225
    }
226
227 2
    public function getPriceLevel(): ?int
228
    {
229 2
        return $this->priceLevel;
230
    }
231
232 1
    public function setPriceLevel(?int $priceLevel): void
233
    {
234 1
        $this->priceLevel = $priceLevel;
235 1
    }
236
237 2
    public function hasRating(): bool
238
    {
239 2
        return null !== $this->rating;
240
    }
241
242 2
    public function getRating(): ?float
243
    {
244 2
        return $this->rating;
245
    }
246
247 1
    public function setRating(?float $rating): void
248
    {
249 1
        $this->rating = $rating;
250 1
    }
251
252 2
    public function hasUtcOffset(): bool
253
    {
254 2
        return null !== $this->utcOffset;
255
    }
256
257 2
    public function getUtcOffset(): ?int
258
    {
259 2
        return $this->utcOffset;
260
    }
261
262 1
    public function setUtcOffset(?int $utcOffset): void
263
    {
264 1
        $this->utcOffset = $utcOffset;
265 1
    }
266
267 2
    public function hasVicinity(): bool
268
    {
269 2
        return null !== $this->vicinity;
270
    }
271
272 2
    public function getVicinity(): ?string
273
    {
274 2
        return $this->vicinity;
275
    }
276
277 1
    public function setVicinity(?string $vicinity): void
278
    {
279 1
        $this->vicinity = $vicinity;
280 1
    }
281
282 2
    public function hasWebsite(): bool
283
    {
284 2
        return null !== $this->website;
285
    }
286
287 2
    public function getWebsite(): ?string
288
    {
289 2
        return $this->website;
290
    }
291
292 1
    public function setWebsite(?string $website): void
293
    {
294 1
        $this->website = $website;
295 1
    }
296
297 2
    public function hasGeometry(): bool
298
    {
299 2
        return null !== $this->geometry;
300
    }
301
302 2
    public function getGeometry(): ?Geometry
303
    {
304 2
        return $this->geometry;
305
    }
306
307 1
    public function setGeometry(Geometry $geometry = null): void
308
    {
309 1
        $this->geometry = $geometry;
310 1
    }
311
312 2
    public function hasOpeningHours(): bool
313
    {
314 2
        return null !== $this->openingHours;
315
    }
316
317 2
    public function getOpeningHours(): ?OpeningHours
318
    {
319 2
        return $this->openingHours;
320
    }
321
322 1
    public function setOpeningHours(OpeningHours $openingHours = null): void
323
    {
324 1
        $this->openingHours = $openingHours;
325 1
    }
326
327 6
    public function hasAddressComponents(string $type = null): bool
328
    {
329 6
        $addresses = $this->getAddressComponents($type);
330
331 6
        return !empty($addresses);
332
    }
333
334
    /** @return AddressComponent[] */
335 6
    public function getAddressComponents(string $type = null): array
336
    {
337 6
        if (null === $type) {
338 5
            return $this->addressComponents;
339
        }
340
341 1
        $addressComponents = [];
342
343 1
        foreach ($this->addressComponents as $addressComponent) {
344 1
            if (in_array($type, $addressComponent->getTypes(), true)) {
345 1
                $addressComponents[] = $addressComponent;
346
            }
347
        }
348
349 1
        return $addressComponents;
350
    }
351
352
    /** @param AddressComponent[] $addressComponents */
353 3
    public function setAddressComponents(array $addressComponents): void
354
    {
355 3
        $this->addressComponents = [];
356 3
        $this->addAddressComponents($addressComponents);
357 3
    }
358
359
    /** @param AddressComponent[] $addressComponents */
360 3
    public function addAddressComponents(array $addressComponents): void
361
    {
362 3
        foreach ($addressComponents as $addressComponent) {
363 3
            $this->addAddressComponent($addressComponent);
364
        }
365 3
    }
366
367 5
    public function hasAddressComponent(AddressComponent $addressComponent): bool
368
    {
369 5
        return in_array($addressComponent, $this->addressComponents, true);
370
    }
371
372 5
    public function addAddressComponent(AddressComponent $addressComponent): void
373
    {
374 5
        if (!$this->hasAddressComponent($addressComponent)) {
375 5
            $this->addressComponents[] = $addressComponent;
376
        }
377 5
    }
378
379 1
    public function removeAddressComponent(AddressComponent $addressComponent): void
380
    {
381 1
        unset($this->addressComponents[array_search($addressComponent, $this->addressComponents, true)]);
382 1
        $this->addressComponents = empty($this->addressComponents) ? [] : array_values($this->addressComponents);
383 1
    }
384
385 5
    public function hasPhotos(): bool
386
    {
387 5
        return !empty($this->photos);
388
    }
389
390 5
    public function getPhotos(): array
391
    {
392 5
        return $this->photos;
393
    }
394
395
    /** @param Photo[] $photos */
396 2
    public function setPhotos(array $photos): void
397
    {
398 2
        $this->photos = [];
399 2
        $this->addPhotos($photos);
400 2
    }
401
402
    /** @param Photo[] $photos */
403 2
    public function addPhotos(array $photos): void
404
    {
405 2
        foreach ($photos as $photo) {
406 2
            $this->addPhoto($photo);
407
        }
408 2
    }
409
410 4
    public function hasPhoto(Photo $photo): bool
411
    {
412 4
        return in_array($photo, $this->photos, true);
413
    }
414
415 4
    public function addPhoto(Photo $photo): void
416
    {
417 4
        if (!$this->hasPhoto($photo)) {
418 4
            $this->photos[] = $photo;
419
        }
420 4
    }
421
422 1
    public function removePhoto(Photo $photo): void
423
    {
424 1
        unset($this->photos[array_search($photo, $this->photos, true)]);
425 1
        $this->photos = empty($this->photos) ? [] : array_values($this->photos);
426 1
    }
427
428 5
    public function hasAlternatePlaceIds(): bool
429
    {
430 5
        return !empty($this->alternatePlaceIds);
431
    }
432
433
    /** @return AlternatePlaceId[] */
434 5
    public function getAlternatePlaceIds(): array
435
    {
436 5
        return $this->alternatePlaceIds;
437
    }
438
439
    /** @param AlternatePlaceId[] $alternatePlaceIds */
440 2
    public function setAlternatePlaceIds(array $alternatePlaceIds): void
441
    {
442 2
        $this->alternatePlaceIds = [];
443 2
        $this->addAlternatePlaceIds($alternatePlaceIds);
444 2
    }
445
446
    /** @param AlternatePlaceId[] $alternatePlaceIds */
447 2
    public function addAlternatePlaceIds(array $alternatePlaceIds): void
448
    {
449 2
        foreach ($alternatePlaceIds as $alternatePlaceId) {
450 2
            $this->addAlternatePlaceId($alternatePlaceId);
451
        }
452 2
    }
453
454 4
    public function hasAlternatePlaceId(AlternatePlaceId $alternatePlaceId): bool
455
    {
456 4
        return in_array($alternatePlaceId, $this->alternatePlaceIds, true);
457
    }
458
459 4
    public function addAlternatePlaceId(AlternatePlaceId $alternatePlaceId): void
460
    {
461 4
        if (!$this->hasAlternatePlaceId($alternatePlaceId)) {
462 4
            $this->alternatePlaceIds[] = $alternatePlaceId;
463
        }
464 4
    }
465
466 1
    public function removeAlternatePlaceId(AlternatePlaceId $alternatePlaceId): void
467
    {
468 1
        unset($this->alternatePlaceIds[array_search($alternatePlaceId, $this->alternatePlaceIds, true)]);
469 1
        $this->alternatePlaceIds = empty($this->alternatePlaceIds) ? [] : array_values($this->alternatePlaceIds);
470 1
    }
471
472 5
    public function hasReviews(): bool
473
    {
474 5
        return !empty($this->reviews);
475
    }
476
477
    /** @return Review[] */
478 5
    public function getReviews(): array
479
    {
480 5
        return $this->reviews;
481
    }
482
483
    /** @param Review[] $reviews */
484 2
    public function setReviews(array $reviews): void
485
    {
486 2
        $this->reviews = [];
487 2
        $this->addReviews($reviews);
488 2
    }
489
490
    /** @param Review[] $reviews */
491 2
    public function addReviews(array $reviews): void
492
    {
493 2
        foreach ($reviews as $review) {
494 2
            $this->addReview($review);
495
        }
496 2
    }
497
498 4
    public function hasReview(Review $review): bool
499
    {
500 4
        return in_array($review, $this->reviews, true);
501
    }
502
503 4
    public function addReview(Review $review): void
504
    {
505 4
        if (!$this->hasReview($review)) {
506 4
            $this->reviews[] = $review;
507
        }
508 4
    }
509
510 1
    public function removeReview(Review $review): void
511
    {
512 1
        unset($this->reviews[array_search($review, $this->reviews, true)]);
513 1
        $this->reviews = empty($this->reviews) ? [] : array_values($this->reviews);
514 1
    }
515
516 5
    public function hasTypes(): bool
517
    {
518 5
        return !empty($this->types);
519
    }
520
521
    /** @return string[] */
522 5
    public function getTypes(): array
523
    {
524 5
        return $this->types;
525
    }
526
527
    /** @param string[] $types */
528 2
    public function setTypes(array $types): void
529
    {
530 2
        $this->types = [];
531 2
        $this->addTypes($types);
532 2
    }
533
534
    /** @param string[] $types */
535 2
    public function addTypes(array $types): void
536
    {
537 2
        foreach ($types as $type) {
538 2
            $this->addType($type);
539
        }
540 2
    }
541
542 4
    public function hasType(string $type): bool
543
    {
544 4
        return in_array($type, $this->types, true);
545
    }
546
547 4
    public function addType(string $type): void
548
    {
549 4
        if (!$this->hasType($type)) {
550 4
            $this->types[] = $type;
551
        }
552 4
    }
553
554 1
    public function removeType(string $type): void
555
    {
556 1
        unset($this->types[array_search($type, $this->types, true)]);
557 1
        $this->types = empty($this->types) ? [] : array_values($this->types);
558 1
    }
559
560 2
    public function hasPermanentlyClose(): bool
561
    {
562 2
        return null !== $this->permanentlyClose;
563
    }
564
565 2
    public function isPermanentlyClose(): ?bool
566
    {
567 2
        return $this->permanentlyClose;
568
    }
569
570 1
    public function setPermanentlyClose(?bool $permanentlyClose): void
571
    {
572 1
        $this->permanentlyClose = $permanentlyClose;
573 1
    }
574
}
575