Completed
Push — master ( 0de6e3...381d30 )
by Bradley
05:42 queued 04:30
created

MapperBase::setKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cornford\Googlmapper;
4
5
use Cornford\Googlmapper\Contracts\MappingBaseInterface;
6
use Cornford\Googlmapper\Exceptions\MapperArgumentException;
7
use Cornford\Googlmapper\Traits\Languages;
8
use Cornford\Googlmapper\Traits\Regions;
9
use Illuminate\View\Factory as View;
10
11
abstract class MapperBase implements MappingBaseInterface
12
{
13
    use Regions;
14
    use Languages;
15
16
    private const ENABLED = true;
17
18
    private const REGION = 'GB';
19
20
    private const LANGUAGE = 'en-gb';
21
22
    private const TYPE_ROADMAP = 'ROADMAP';
23
    private const TYPE_SATELLITE = 'SATELLITE';
24
    private const TYPE_HYBRID = 'HYBRID';
25
    private const TYPE_TERRAIN = 'TERRAIN';
26
27
    private const ASYNC = false;
28
29
    private const MARKER = true;
30
31
    private const CENTER = true;
32
33
    private const LOCATE = false;
34
35
    private const ZOOM = 8;
36
    private const SCROLL_WHEEL_ZOOM = true;
37
38
    private const CONTROL_ZOOM = true;
39
    private const CONTROL_MAP_TYPE = true;
40
    private const CONTROL_SCALE = false;
41
    private const CONTROL_STREET_VIEW = true;
42
    private const CONTROL_ROTATE = false;
43
    private const CONTROL_FULLSCREEN = true;
44
45
    private const HEADING = 0;
46
47
    private const TILT = 0;
48
49
    private const UI = true;
50
51
    private const ANIMATION_NONE = 'NONE';
52
    private const ANIMATION_DROP = 'DROP';
53
    private const ANIMATION_BOUNCE = 'BOUNCE';
54
55
    private const OVERLAY_NONE = 'NONE';
56
    private const OVERLAY_BIKE = 'BIKE';
57
    private const OVERLAY_TRANSIT = 'TRANSIT';
58
    private const OVERLAY_TRAFFIC = 'TRAFFIC';
59
60
    private const SYMBOL_CIRCLE = 'CIRCLE';
61
    private const SYMBOL_BACKWARD_CLOSED_ARROW = 'BACKWARD_CLOSED_ARROW';
62
    private const SYMBOL_FORWARD_CLOSED_ARROW = 'FORWARD_CLOSED_ARROW';
63
    private const SYMBOL_BACKWARD_OPEN_ARROW = 'BACKWARD_OPEN_ARROW';
64
    private const SYMBOL_FORWARD_OPEN_ARROW = 'FORWARD_OPEN_ARROW';
65
66
    private const ICON = '';
67
68
    private const CLUSTER = true;
69
70
    private const CLUSTERS_ICON = '//googlemaps.github.io/js-marker-clusterer/images/m';
71
    private const CLUSTERS_GRID = 60;
72
    private const CLUSTERS_ZOOM = null;
73
    private const CLUSTERS_CENTER = false;
74
    private const CLUSTERS_SIZE = 2;
75
76
    /**
77
     * View.
78
     *
79
     * @var \Illuminate\View\Factory
80
     */
81
    protected $view;
82
83
    /**
84
     * Mapping enabled.
85
     *
86
     * @var boolean
87
     */
88
    protected $enabled;
89
90
    /**
91
     * API Key.
92
     *
93
     * @var string
94
     */
95
    protected $key;
96
97
    /**
98
     * API Version.
99
     *
100
     * @var float|string
101
     */
102
    protected $version;
103
104
    /**
105
     * API region.
106
     *
107
     * @var string
108
     */
109
    protected $region;
110
111
    /**
112
     * API Language.
113
     *
114
     * @var string
115
     */
116
    protected $language;
117
118
    /**
119
     * Async maps.
120
     *
121
     * @var boolean
122
     */
123
    protected $async;
124
125
    /**
126
     * Automatic map marker.
127
     *
128
     * @var boolean
129
     */
130
    protected $marker;
131
132
    /**
133
     * Center map automatically.
134
     *
135
     * @var boolean
136
     */
137
    protected $center;
138
139
    /**
140
     * Locate users location.
141
     *
142
     * @var boolean
143
     */
144
    protected $locate;
145
146
    /**
147
     * Show map UI.
148
     *
149
     * @var boolean
150
     */
151
    protected $ui;
152
153
    /**
154
     * Map zoom level.
155
     *
156
     * @var int
157
     */
158
    protected $zoom;
159
160
    /**
161
     * Map scroll wheel zoom.
162
     *
163
     * @var boolean
164
     */
165
    protected $scrollWheelZoom;
166
167
    /**
168
     * Map zoom control.
169
     *
170
     * @var boolean
171
     */
172
    protected $zoomControl;
173
174
    /**
175
     * Map type control.
176
     *
177
     * @var boolean
178
     */
179
    protected $mapTypeControl;
180
181
    /**
182
     * Map scale control.
183
     *
184
     * @var boolean
185
     */
186
    protected $scaleControl;
187
188
    /**
189
     * Map street view control.
190
     *
191
     * @var boolean
192
     */
193
    protected $streetViewControl;
194
195
    /**
196
     * Map rotate control.
197
     *
198
     * @var boolean
199
     */
200
    protected $rotateControl;
201
202
    /**
203
     * Map fullscreen control.
204
     *
205
     * @var boolean
206
     */
207
    protected $fullscreenControl;
208
209
    /**
210
     * Map type.
211
     *
212
     * @var string
213
     */
214
    protected $type;
215
216
    /**
217
     * Available map types.
218
     *
219
     * @var array
220
     */
221
    protected $types = [
222
        'ROADMAP',
223
        'SATELLITE',
224
        'HYBRID',
225
        'TERRAIN'
226
    ];
227
228
    /**
229
     * Map heading.
230
     *
231
     * @var int
232
     */
233
    protected $heading;
234
235
    /**
236
     * Map tilt.
237
     *
238
     * @var int
239
     */
240
    protected $tilt;
241
242
    /**
243
     * Map marker icon.
244
     *
245
     * @var string
246
     */
247
    protected $icon;
248
249
    /**
250
     * Map marker animation.
251
     *
252
     * @var string
253
     */
254
    protected $animation;
255
256
    /**
257
     * Available map marker animations.
258
     *
259
     * @var array
260
     */
261
    protected $animations = [
262
        'NONE',
263
        'DROP',
264
        'BOUNCE',
265
    ];
266
267
    /**
268
     * Map marker cluster.
269
     *
270
     * @var boolean
271
     */
272
    protected $cluster;
273
274
    /**
275
     * Map marker clusters icon.
276
     *
277
     * @var string
278
     */
279
    protected $clustersIcon;
280
281
    /**
282
     * Map marker clusters grid.
283
     *
284
     * @var int
285
     */
286
    protected $clustersGrid;
287
288
    /**
289
     * Map marker clusters zoom.
290
     *
291
     * @var int|null
292
     */
293
    protected $clustersZoom;
294
295
    /**
296
     * Map marker clusters center.
297
     *
298
     * @var boolean
299
     */
300
    protected $clustersCenter;
301
302
    /**
303
     * Map marker clusters size.
304
     *
305
     * @var int
306
     */
307
    protected $clustersSize;
308
309
    /**
310
     * Mapping items.
311
     *
312
     * @var array
313
     */
314
    public $items = [];
315
316
    /**
317
     * Construct Googlmapper.
318
     *
319
     * @param View  $view
320
     * @param array $options
321
     *
322
     * @throws MapperArgumentException
323
     */
324
    public function __construct(View $view, array $options = [])
325
    {
326
        $this->view = $view;
327
328
        if (!isset($options['key'])) {
329
            throw new MapperArgumentException('Google maps API key is required.');
330
        }
331
332
        if (!isset($options['version'])) {
333
            throw new MapperArgumentException('Google maps API version is required.');
334
        }
335
336
        if (!isset($options['region'])) {
337
            throw new MapperArgumentException('Region is required.');
338
        }
339
340
        if (!in_array($options['region'], $this->regions)) {
341
            throw new MapperArgumentException('Region is required in ISO 3166-1 code format.');
342
        }
343
344
        if (!isset($options['language']) || !in_array($options['language'], $this->languages)) {
345
            throw new MapperArgumentException('Language is required.');
346
        }
347
348
        if (!in_array($options['language'], $this->languages)) {
349
            throw new MapperArgumentException('Language is required in ISO 639-1 code format.');
350
        }
351
352
        $this->setEnabled($options['enabled'] ?? self::ENABLED);
353
        $this->setKey($options['key']);
354
        $this->setVersion($options['version']);
355
        $this->setRegion($options['region'] ?? self::REGION);
356
        $this->setLanguage($options['language'] ?? self::LANGUAGE);
357
        $this->setAsync($options['async'] ?? self::ASYNC);
358
        $this->setMarker($options['marker'] ?? self::MARKER);
359
        $this->setCenter($options['center'] ?? self::CENTER);
360
        $this->setLocate($options['locate'] ?? self::LOCATE);
361
        $this->setZoom($options['zoom'] ?? self::ZOOM);
362
        $this->setScrollWheelZoom($options['scrollWheelZoom'] ?? self::SCROLL_WHEEL_ZOOM);
363
        $this->setZoomControl($options['zoomControl'] ?? self::CONTROL_ZOOM);
364
        $this->setMapTypeControl($options['mapTypeControl'] ?? self::CONTROL_MAP_TYPE);
365
        $this->setScaleControl($options['scaleControl'] ?? self::CONTROL_SCALE);
366
        $this->setStreetViewControl($options['streetViewControl'] ?? self::CONTROL_STREET_VIEW);
367
        $this->setRotateControl($options['rotateControl'] ?? self::CONTROL_ROTATE);
368
        $this->setFullscreenControl($options['fullscreenControl'] ?? self::CONTROL_FULLSCREEN);
369
        $this->setType($options['type'] ?? self::TYPE_ROADMAP);
370
        $this->setHeading($options['heading'] ?? self::HEADING);
371
        $this->setTilt($options['tilt'] ?? self::TILT);
372
        $this->setUi($options['ui'] ?? self::UI);
373
        $this->setIcon($options['markers']['icon'] ?? self::ICON);
374
        $this->setAnimation($options['markers']['animation'] ?? self::ANIMATION_NONE);
375
        $this->setCluster($options['cluster'] ?? self::CLUSTER);
376
        $this->setClustersIcon($options['clusters']['icon'] ?? self::CLUSTERS_ICON);
377
        $this->setClustersGrid($options['clusters']['grid'] ?? self::CLUSTERS_GRID);
378
        $this->setClustersZoom($options['clusters']['zoom'] ?? self::CLUSTERS_ZOOM);
379
        $this->setClustersCenter($options['clusters']['center'] ?? self::CLUSTERS_CENTER);
380
        $this->setClustersSize($options['clusters']['size'] ?? self::CLUSTERS_SIZE);
381
    }
382
383
    /**
384
     * Is mapping enabled?
385
     *
386
     * @return boolean
387
     */
388
    public function isEnabled()
389
    {
390
        return $this->getEnabled();
391
    }
392
393
    /**
394
     * Set enabled status.
395
     *
396
     * @param boolean $value
397
     *
398
     * @throws MapperArgumentException
399
     *
400
     * @return void
401
     */
402
    protected function setEnabled($value)
403
    {
404
        if (!is_bool($value)) {
405
            throw new MapperArgumentException('Invalid map enabled setting.');
406
        }
407
408
        $this->enabled = $value;
409
    }
410
411
    /**
412
     * Get the enabled status.
413
     *
414
     * @return boolean
415
     */
416
    protected function getEnabled()
417
    {
418
        return $this->enabled;
419
    }
420
421
    /**
422
     * Enable mapping.
423
     *
424
     * @throws MapperArgumentException
425
     *
426
     * @return void
427
     */
428
    public function enableMapping()
429
    {
430
        $this->setEnabled(true);
431
    }
432
433
    /**
434
     * Disable mapping.
435
     *
436
     * @throws MapperArgumentException
437
     *
438
     * @return void
439
     */
440
    public function disableMapping()
441
    {
442
        $this->setEnabled(false);
443
    }
444
445
    /**
446
     * Set the Google Maps key.
447
     *
448
     * @param string $value
449
     *
450
     * @throws MapperArgumentException
451
     *
452
     * @return void
453
     */
454
    public function setKey($value)
455
    {
456
        if (!is_string($value)) {
457
            throw new MapperArgumentException('Invalid Google Map\'s API key.');
458
        }
459
460
        $this->key = $value;
461
    }
462
463
    /**
464
     * Get the Google Maps key.
465
     *
466
     * @return string
467
     */
468
    public function getKey()
469
    {
470
        return $this->key;
471
    }
472
473
    /**
474
     * Set the Google Maps version.
475
     *
476
     * @param float|string $value
477
     *
478
     * @throws MapperArgumentException
479
     *
480
     * @return void
481
     */
482
    public function setVersion($value)
483
    {
484
        if (!is_float($value) && !is_string($value)) {
485
            throw new MapperArgumentException('Invalid Google Map\'s API version.');
486
        }
487
488
        $this->version = $value;
489
    }
490
491
    /**
492
     * Get the Google Maps version.
493
     *
494
     * @return float|string
495
     */
496
    public function getVersion()
497
    {
498
        return $this->version;
499
    }
500
501
    /**
502
     * Set the Google Maps region.
503
     *
504
     * @param string $value
505
     *
506
     * @throws MapperArgumentException
507
     *
508
     * @return void
509
     */
510
    public function setRegion($value)
511
    {
512
        if (!is_string($value)) {
513
            throw new MapperArgumentException('Invalid map region.');
514
        }
515
516
        if (!in_array($value, $this->regions)) {
517
            throw new MapperArgumentException('Region is required in ISO 3166-1 code format.');
518
        }
519
520
        $this->region = $value;
521
    }
522
523
    /**
524
     * Get the Google Maps region.
525
     *
526
     * @return string
527
     */
528
    public function getRegion()
529
    {
530
        return $this->region;
531
    }
532
533
    /**
534
     * Set the Google Maps language.
535
     *
536
     * @param string $value
537
     *
538
     * @throws MapperArgumentException
539
     *
540
     * @return void
541
     */
542
    public function setLanguage($value)
543
    {
544
        if (!is_string($value)) {
545
            throw new MapperArgumentException('Invalid map language.');
546
        }
547
548
        if (!in_array($value, $this->languages)) {
549
            throw new MapperArgumentException('Language is required in ISO 639-1 code format.');
550
        }
551
552
        $this->language = $value;
553
    }
554
555
    /**
556
     * Get the Google Maps language.
557
     *
558
     * @return string
559
     */
560
    public function getLanguage()
561
    {
562
        return $this->language;
563
    }
564
565
    /**
566
     * Set the map async status.
567
     *
568
     * @param boolean $value
569
     *
570
     * @throws MapperArgumentException
571
     *
572
     * @return void
573
     */
574
    protected function setAsync($value)
575
    {
576
        if (!is_bool($value)) {
577
            throw new MapperArgumentException('Invalid map async status.');
578
        }
579
580
        $this->async = $value;
581
    }
582
583
    /**
584
     * Get the map async status.
585
     *
586
     * @return boolean
587
     */
588
    public function getAsync()
589
    {
590
        return $this->async;
591
    }
592
593
    /**
594
     * Enable async for maps.
595
     *
596
     * @throws MapperArgumentException
597
     *
598
     * @return void
599
     */
600
    public function enableAsync()
601
    {
602
        $this->setAsync(true);
603
    }
604
605
    /**
606
     * Disable async for maps.
607
     *
608
     * @throws MapperArgumentException
609
     *
610
     * @return void
611
     */
612
    public function disableAsync()
613
    {
614
        $this->setAsync(false);
615
    }
616
617
    /**
618
     * Set the marker status.
619
     *
620
     * @param boolean $value
621
     *
622
     * @throws MapperArgumentException
623
     *
624
     * @return void
625
     */
626
    protected function setMarker($value)
627
    {
628
        if (!is_bool($value)) {
629
            throw new MapperArgumentException('Invalid map marker setting.');
630
        }
631
632
        $this->marker = $value;
633
    }
634
635
    /**
636
     * Get the marker status.
637
     *
638
     * @return boolean
639
     */
640
    public function getMarker()
641
    {
642
        return $this->marker;
643
    }
644
645
    /**
646
     * Enable markers for maps.
647
     *
648
     * @throws MapperArgumentException
649
     *
650
     * @return void
651
     */
652
    public function enableMarkers()
653
    {
654
        $this->setMarker(true);
655
    }
656
657
    /**
658
     * Disable markers for maps.
659
     *
660
     * @throws MapperArgumentException
661
     *
662
     * @return void
663
     */
664
    public function disableMarkers()
665
    {
666
        $this->setMarker(false);
667
    }
668
669
    /**
670
     * Set the map center status.
671
     *
672
     * @param boolean $value
673
     *
674
     * @throws MapperArgumentException
675
     *
676
     * @return void
677
     */
678
    protected function setCenter($value)
679
    {
680
        if (!is_bool($value)) {
681
            throw new MapperArgumentException('Invalid map center setting.');
682
        }
683
684
        $this->center = $value;
685
    }
686
687
    /**
688
     * Get the map center status.
689
     *
690
     * @return boolean
691
     */
692
    public function getCenter()
693
    {
694
        return $this->center;
695
    }
696
697
    /**
698
     * Enable center of maps.
699
     *
700
     * @throws MapperArgumentException
701
     *
702
     * @return void
703
     */
704
    public function enableCenter()
705
    {
706
        $this->setCenter(true);
707
    }
708
709
    /**
710
     * Disable center of maps.
711
     *
712
     * @throws MapperArgumentException
713
     *
714
     * @return void
715
     */
716
    public function disableCenter()
717
    {
718
        $this->setCenter(false);
719
    }
720
721
    /**
722
     * Set the map locate user status.
723
     *
724
     * @param boolean $value
725
     *
726
     * @throws MapperArgumentException
727
     *
728
     * @return void
729
     */
730
    protected function setLocate($value)
731
    {
732
        if (!is_bool($value)) {
733
            throw new MapperArgumentException('Invalid map locate setting.');
734
        }
735
736
        $this->locate = $value;
737
    }
738
739
    /**
740
     * Get the map locate user status.
741
     *
742
     * @return boolean
743
     */
744
    public function getLocate()
745
    {
746
        return $this->locate;
747
    }
748
749
    /**
750
     * Enable locate user position on maps.
751
     *
752
     * @throws MapperArgumentException
753
     *
754
     * @return void
755
     */
756
    public function enableLocate()
757
    {
758
        $this->setLocate(true);
759
    }
760
761
    /**
762
     * Disable locate user position on maps.
763
     *
764
     * @throws MapperArgumentException
765
     *
766
     * @return void
767
     */
768
    public function disableLocate()
769
    {
770
        $this->setLocate(false);
771
    }
772
773
    /**
774
     * Set the map UI status.
775
     *
776
     * @param boolean $value
777
     *
778
     * @throws MapperArgumentException
779
     *
780
     * @return void
781
     */
782
    protected function setUi($value)
783
    {
784
        if (!is_bool($value)) {
785
            throw new MapperArgumentException('Invalid map ui setting.');
786
        }
787
788
        $this->ui = $value;
789
    }
790
791
    /**
792
     * Get the map UI status.
793
     *
794
     * @return boolean
795
     */
796
    public function getUi()
797
    {
798
        return $this->ui;
799
    }
800
801
    /**
802
     * Enable maps ui.
803
     *
804
     * @throws MapperArgumentException
805
     *
806
     * @return void
807
     */
808
    public function enableUi()
809
    {
810
        $this->setUi(false);
811
    }
812
813
    /**
814
     * Disable maps ui.
815
     *
816
     * @throws MapperArgumentException
817
     *
818
     * @return void
819
     */
820
    public function disableUi()
821
    {
822
        $this->setUi(true);
823
    }
824
825
    /**
826
     * Set map zoom level.
827
     *
828
     * @param int $value
829
     *
830
     * @throws MapperArgumentException
831
     *
832
     * @return void
833
     */
834
    public function setZoom($value)
835
    {
836
        if (!is_numeric($value)) {
837
            throw new MapperArgumentException('Zoom level must be an integer.');
838
        }
839
840
        if ($value < 1 || $value > 20) {
841
            throw new MapperArgumentException('A zoom level must be between 1 and 20.');
842
        }
843
844
        $this->zoom = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value can also be of type double or string. However, the property $zoom is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
845
    }
846
847
    /**
848
     * Get map zoom level.
849
     *
850
     * @return int
851
     */
852
    public function getZoom()
853
    {
854
        return $this->zoom;
855
    }
856
857
    /**
858
     * Set map scroll wheel zoom.
859
     *
860
     * @param boolean $value
861
     *
862
     * @throws MapperArgumentException
863
     *
864
     * @return void
865
     */
866
    public function setScrollWheelZoom($value)
867
    {
868
        if (!is_bool($value)) {
869
            throw new MapperArgumentException('Mouse Wheel Zoom must be a boolean.');
870
        }
871
872
        $this->scrollWheelZoom = $value;
873
    }
874
875
    /**
876
     * Get map scroll wheel zoom.
877
     *
878
     * @return boolean
879
     */
880
    public function getScrollWheelZoom()
881
    {
882
        return $this->scrollWheelZoom;
883
    }
884
885
    /**
886
     * Set map zoom control.
887
     *
888
     * @param boolean $value
889
     *
890
     * @throws MapperArgumentException
891
     *
892
     * @return void
893
     */
894
    public function setZoomControl($value)
895
    {
896
        if (!is_bool($value)) {
897
            throw new MapperArgumentException('Zoom control must be a boolean.');
898
        }
899
900
        $this->zoomControl = $value;
901
    }
902
903
    /**
904
     * Get map zoom control.
905
     *
906
     * @return boolean
907
     */
908
    public function getZoomControl()
909
    {
910
        return $this->zoomControl;
911
    }
912
913
    /**
914
     * Set map type control.
915
     *
916
     * @param boolean $value
917
     *
918
     * @throws MapperArgumentException
919
     *
920
     * @return void
921
     */
922
    public function setMapTypeControl($value)
923
    {
924
        if (!is_bool($value)) {
925
            throw new MapperArgumentException('Map type control must be a boolean.');
926
        }
927
928
        $this->mapTypeControl = $value;
929
    }
930
931
    /**
932
     * Get map type control.
933
     *
934
     * @return boolean
935
     */
936
    public function getMapTypeControl()
937
    {
938
        return $this->mapTypeControl;
939
    }
940
941
    /**
942
     * Set map scale control.
943
     *
944
     * @param boolean $value
945
     *
946
     * @throws MapperArgumentException
947
     *
948
     * @return void
949
     */
950
    public function setScaleControl($value)
951
    {
952
        if (!is_bool($value)) {
953
            throw new MapperArgumentException('Scale control must be a boolean.');
954
        }
955
956
        $this->scaleControl = $value;
957
    }
958
959
    /**
960
     * Get map scale control.
961
     *
962
     * @return boolean
963
     */
964
    public function getScaleControl()
965
    {
966
        return $this->scaleControl;
967
    }
968
969
    /**
970
     * Set map street view control.
971
     *
972
     * @param boolean $value
973
     *
974
     * @throws MapperArgumentException
975
     *
976
     * @return void
977
     */
978
    public function setStreetViewControl($value)
979
    {
980
        if (!is_bool($value)) {
981
            throw new MapperArgumentException('Street view control must be a boolean.');
982
        }
983
984
        $this->streetViewControl = $value;
985
    }
986
987
    /**
988
     * Get map street view control.
989
     *
990
     * @return boolean
991
     */
992
    public function getStreetViewControl()
993
    {
994
        return $this->streetViewControl;
995
    }
996
997
    /**
998
     * Set map rotate control.
999
     *
1000
     * @param boolean $value
1001
     *
1002
     * @throws MapperArgumentException
1003
     *
1004
     * @return void
1005
     */
1006
    public function setRotateControl($value)
1007
    {
1008
        if (!is_bool($value)) {
1009
            throw new MapperArgumentException('Rotate control must be a boolean.');
1010
        }
1011
1012
        $this->rotateControl = $value;
1013
    }
1014
1015
    /**
1016
     * Get map rotate control.
1017
     *
1018
     * @return boolean
1019
     */
1020
    public function getRotateControl()
1021
    {
1022
        return $this->rotateControl;
1023
    }
1024
1025
    /**
1026
     * Set map fullscreen control.
1027
     *
1028
     * @param boolean $value
1029
     *
1030
     * @throws MapperArgumentException
1031
     *
1032
     * @return void
1033
     */
1034
    public function setFullscreenControl($value)
1035
    {
1036
        if (!is_bool($value)) {
1037
            throw new MapperArgumentException('Fullscreen control must be a boolean.');
1038
        }
1039
1040
        $this->fullscreenControl = $value;
1041
    }
1042
1043
    /**
1044
     * Get map fullscreen control.
1045
     *
1046
     * @return boolean
1047
     */
1048
    public function getFullscreenControl()
1049
    {
1050
        return $this->fullscreenControl;
1051
    }
1052
1053
    /**
1054
     * Set map type.
1055
     *
1056
     * @param string $value
1057
     *
1058
     * @throws MapperArgumentException
1059
     *
1060
     * @return void
1061
     */
1062
    public function setType($value)
1063
    {
1064
        if (!in_array($value, $this->types)) {
1065
            throw new MapperArgumentException('Invalid map type.');
1066
        }
1067
1068
        $this->type = $value;
1069
    }
1070
1071
    /**
1072
     * Get map type.
1073
     *
1074
     * @return string
1075
     */
1076
    public function getType()
1077
    {
1078
        return $this->type;
1079
    }
1080
1081
    /**
1082
     * Set map heading.
1083
     *
1084
     * @param int|double $value
1085
     *
1086
     * @throws MapperArgumentException
1087
     *
1088
     * @return void
1089
     */
1090
    public function setHeading($value)
1091
    {
1092
        if (!is_numeric($value)) {
1093
            throw new MapperArgumentException('Invalid map heading.');
1094
        }
1095
1096
        $this->heading = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value can also be of type double or string. However, the property $heading is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1097
    }
1098
1099
    /**
1100
     * Get map heading.
1101
     *
1102
     * @return int|double
1103
     */
1104
    public function getHeading()
1105
    {
1106
        return $this->heading;
1107
    }
1108
1109
    /**
1110
     * Set map tilt.
1111
     *
1112
     * @param int|double $value
1113
     *
1114
     * @throws MapperArgumentException
1115
     *
1116
     * @return void
1117
     */
1118
    public function setTilt($value)
1119
    {
1120
        if (!is_numeric($value)) {
1121
            throw new MapperArgumentException('Invalid map tilt.');
1122
        }
1123
1124
        $this->tilt = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value can also be of type double or string. However, the property $tilt is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1125
    }
1126
1127
    /**
1128
     * Get map tilt.
1129
     *
1130
     * @return int
1131
     */
1132
    public function getTilt()
1133
    {
1134
        return $this->tilt;
1135
    }
1136
1137
    /**
1138
     * Set map marker icon.
1139
     *
1140
     * @param string $value
1141
     *
1142
     * @throws MapperArgumentException
1143
     *
1144
     * @return void
1145
     */
1146
    public function setIcon($value)
1147
    {
1148
        if (!is_string($value)) {
1149
            throw new MapperArgumentException('Invalid map marker icon.');
1150
        }
1151
1152
        $this->icon = $value;
1153
    }
1154
1155
    /**
1156
     * Get map marker icon.
1157
     *
1158
     * @return string
1159
     */
1160
    public function getIcon()
1161
    {
1162
        return $this->icon;
1163
    }
1164
1165
    /**
1166
     * Set map marker animation.
1167
     *
1168
     * @param string $value
1169
     *
1170
     * @throws MapperArgumentException
1171
     *
1172
     * @return void
1173
     */
1174
    public function setAnimation($value)
1175
    {
1176
        if (!in_array($value, $this->animations)) {
1177
            throw new MapperArgumentException('Invalid map marker animation.');
1178
        }
1179
1180
        $this->animation = $value;
1181
    }
1182
1183
    /**
1184
     * Get map marker animation.
1185
     *
1186
     * @return string
1187
     */
1188
    public function getAnimation()
1189
    {
1190
        return $this->animation;
1191
    }
1192
1193
    /**
1194
     * Set cluster status.
1195
     *
1196
     * @param bool $value
1197
     *
1198
     * @throws MapperArgumentException
1199
     *
1200
     * @return void
1201
     */
1202
    protected function setCluster($value)
1203
    {
1204
        if (!is_bool($value)) {
1205
            throw new MapperArgumentException('Invalid map cluster setting.');
1206
        }
1207
1208
        $this->cluster = $value;
1209
    }
1210
1211
    /**
1212
     * Get the cluster status.
1213
     *
1214
     * @return bool
1215
     */
1216
    public function getCluster()
1217
    {
1218
        return $this->cluster;
1219
    }
1220
1221
    /**
1222
     * Enable cluster.
1223
     *
1224
     * @throws MapperArgumentException
1225
     *
1226
     * @return void
1227
     */
1228
    public function enableCluster()
1229
    {
1230
        $this->setCluster(true);
1231
    }
1232
1233
    /**
1234
     * Disable cluster.
1235
     *
1236
     * @throws MapperArgumentException
1237
     *
1238
     * @return void
1239
     */
1240
    public function disableCluster()
1241
    {
1242
        $this->setCluster(false);
1243
    }
1244
1245
    /**
1246
     * Set map cluster icon.
1247
     *
1248
     * @param string $value
1249
     *
1250
     * @throws MapperArgumentException
1251
     *
1252
     * @return void
1253
     */
1254
    public function setClustersIcon($value)
1255
    {
1256
        if (!is_string($value)) {
1257
            throw new MapperArgumentException('Invalid map clusters icon setting.');
1258
        }
1259
1260
        $this->clustersIcon = $value;
1261
    }
1262
1263
    /**
1264
     * Get map clusters icon.
1265
     *
1266
     * @return string
1267
     */
1268
    public function getClustersIcon()
1269
    {
1270
        return $this->clustersIcon;
1271
    }
1272
1273
    /**
1274
     * Set map cluster grid.
1275
     *
1276
     * @param int $value
1277
     *
1278
     * @throws MapperArgumentException
1279
     *
1280
     * @return void
1281
     */
1282
    public function setClustersGrid($value)
1283
    {
1284
        if (!is_int($value)) {
1285
            throw new MapperArgumentException('Invalid map clusters grid setting.');
1286
        }
1287
1288
        $this->clustersGrid = $value;
1289
    }
1290
1291
    /**
1292
     * Get map cluster grid.
1293
     *
1294
     * @return int
1295
     */
1296
    public function getClustersGrid()
1297
    {
1298
        return $this->clustersGrid;
1299
    }
1300
1301
    /**
1302
     * Set map cluster zoom.
1303
     *
1304
     * @param int|null $value
1305
     *
1306
     * @throws MapperArgumentException
1307
     *
1308
     * @return void
1309
     */
1310
    public function setClustersZoom($value)
1311
    {
1312
        if (!is_integer($value) && !is_null($value)) {
1313
            throw new MapperArgumentException('Invalid map clusters zoom setting.');
1314
        }
1315
1316
        $this->clustersZoom = $value;
1317
    }
1318
1319
    /**
1320
     * Get map cluster grid.
1321
     *
1322
     * @return integer|null
1323
     */
1324
    public function getClustersZoom()
1325
    {
1326
        return $this->clustersZoom;
1327
    }
1328
1329
    /**
1330
     * Set map cluster center.
1331
     *
1332
     * @param bool $value
1333
     *
1334
     * @throws MapperArgumentException
1335
     *
1336
     * @return void
1337
     */
1338
    public function setClustersCenter($value)
1339
    {
1340
        if (!is_bool($value)) {
1341
            throw new MapperArgumentException('Invalid map clusters center setting.');
1342
        }
1343
1344
        $this->clustersCenter = $value;
1345
    }
1346
1347
    /**
1348
     * Get map cluster center.
1349
     *
1350
     * @return bool
1351
     */
1352
    public function getClustersCenter()
1353
    {
1354
        return $this->clustersCenter;
1355
    }
1356
1357
    /**
1358
     * Set map cluster size.
1359
     *
1360
     * @param int $value
1361
     *
1362
     * @throws MapperArgumentException
1363
     *
1364
     * @return void
1365
     */
1366
    public function setClustersSize($value)
1367
    {
1368
        if (!is_integer($value)) {
1369
            throw new MapperArgumentException('Invalid map clusters size setting.');
1370
        }
1371
1372
        $this->clustersSize = $value;
1373
    }
1374
1375
    /**
1376
     * Get map cluster size.
1377
     *
1378
     * @return int
1379
     */
1380
    public function getClustersSize()
1381
    {
1382
        return $this->clustersSize;
1383
    }
1384
1385
    /**
1386
     * Get mapper options.
1387
     *
1388
     * @return array
1389
     */
1390
    protected function getOptions()
1391
    {
1392
        return [
1393
            'key' => $this->getKey(),
1394
            'version' => $this->getVersion(),
1395
            'region' => $this->getRegion(),
1396
            'language' => $this->getLanguage(),
1397
            'async' => $this->getAsync(),
1398
            'marker' => $this->getMarker(),
1399
            'center' => $this->getCenter(),
1400
            'locate' => $this->getLocate(),
1401
            'zoom' => $this->getZoom(),
1402
            'scrollWheelZoom' => $this->getScrollWheelZoom(),
1403
            'fullscreenControl' => $this->getFullscreenControl(),
1404
            'zoomControl' => $this->getZoomControl(),
1405
            'scaleControl' => $this->getScaleControl(),
1406
            'streetViewControl' => $this->getStreetViewControl(),
1407
            'rotateControl' => $this->getRotateControl(),
1408
            'mapTypeControl' => $this->getMapTypeControl(),
1409
            'type' => $this->getType(),
1410
            'heading' => $this->getHeading(),
1411
            'tilt' => $this->getTilt(),
1412
            'ui' => $this->getUi(),
1413
            'overlay' => '',
1414
            'markers' => [
1415
                'title' => '',
1416
                'label' => '',
1417
                'content' => '',
1418
                'icon' => $this->getIcon(),
1419
                'place' => '',
1420
                'animation' => $this->getAnimation(),
1421
                'symbol' => '',
1422
            ],
1423
            'cluster' => $this->getCluster(),
1424
            'clusters' => [
1425
                'icon' => $this->getClustersIcon(),
1426
                'grid' => $this->getClustersGrid(),
1427
                'zoom' => $this->getClustersZoom(),
1428
                'center' => $this->getClustersCenter(),
1429
                'size' => $this->getClustersSize()
1430
            ],
1431
        ];
1432
    }
1433
1434
    /**
1435
     * Add mapping item.
1436
     *
1437
     * @param object $value
1438
     *
1439
     * @return void
1440
     */
1441
    protected function addItem($value)
1442
    {
1443
        $this->items[] = $value;
1444
    }
1445
1446
    /**
1447
     * Set mapping items.
1448
     *
1449
     * @param array $array
1450
     *
1451
     * @return void
1452
     */
1453
    protected function setItems(array $array)
1454
    {
1455
        $this->items = $array;
1456
    }
1457
1458
    /**
1459
     * Get the mapping items.
1460
     *
1461
     * @return array
1462
     */
1463
    public function getItems()
1464
    {
1465
        return $this->items;
1466
    }
1467
1468
    /**
1469
     * Get a mapping item by reference.
1470
     *
1471
     * @param int $item
1472
     *
1473
     * @return array|bool
1474
     */
1475
    public function getItem($item)
1476
    {
1477
        return isset($this->items[$item]) ? $this->items[$item] : false;
1478
    }
1479
}
1480