Completed
Push — master ( fa09b4...cd114b )
by Bradley
02:58
created

src/Cornford/Googlmapper/MapperBase.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace Cornford\Googlmapper;
2
3
use Cornford\Googlmapper\Contracts\MappingBaseInterface;
4
use Cornford\Googlmapper\Exceptions\MapperArgumentException;
5
use Illuminate\View\Factory as View;
6
7
abstract class MapperBase implements MappingBaseInterface
8
{
9
10
	const REGION = 'GB';
11
12
	const LANGUAGE = 'en-gb';
13
14
	const TYPE_ROADMAP = 'ROADMAP';
15
	const TYPE_SATELLITE = 'SATELLITE';
16
	const TYPE_HYBRID = 'HYBRID';
17
	const TYPE_TERRAIN = 'TERRAIN';
18
19
	const ZOOM = 8;
20
	const SCROLL_WHEEL_ZOOM = true;
21
22
	const TILT = 90;
23
24
	const ANIMATION_NONE = 'NONE';
25
	const ANIMATION_DROP = 'DROP';
26
	const ANIMATION_BOUNCE = 'BOUNCE';
27
28
	const OVERLAY_NONE = 'NONE';
29
	const OVERLAY_BIKE = 'BIKE';
30
	const OVERLAY_TRANSIT = 'TRANSIT';
31
	const OVERLAY_TRAFFIC = 'TRAFFIC';
32
33
	const SYMBOL_CIRCLE = 'CIRCLE';
34
	const SYMBOL_BACKWARD_CLOSED_ARROW = 'BACKWARD_CLOSED_ARROW';
35
	const SYMBOL_FORWARD_CLOSED_ARROW = 'FORWARD_CLOSED_ARROW';
36
	const SYMBOL_BACKWARD_OPEN_ARROW = 'BACKWARD_OPEN_ARROW';
37
	const SYMBOL_FORWARD_OPEN_ARROW = 'FORWARD_OPEN_ARROW';
38
39
	/**
40
	 * View.
41
	 *
42
	 * @var \Illuminate\View\Factory
43
	 */
44
	protected $view;
45
46
	/**
47
	 * Mapping enabled.
48
	 *
49
	 * @var boolean
50
	 */
51
	protected $enabled;
52
53
	/**
54
	 * API Key.
55
	 *
56
	 * @var string
57
	 */
58
	protected $key;
59
60
	/**
61
	 * API Version.
62
	 *
63
	 * @var integer
64
	 */
65
	protected $version = '3.exp';
66
67
	/**
68
	 * API region.
69
	 *
70
	 * @var string
71
	 */
72
	protected $region;
73
74
	/**
75
	 * API regions.
76
	 *
77
	 * @var array
78
	 */
79
	protected $regions = [
80
		'AF',
81
		'AX',
82
		'AL',
83
		'DZ',
84
		'AS',
85
		'AD',
86
		'AO',
87
		'AI',
88
		'AQ',
89
		'AG',
90
		'AR',
91
		'AM',
92
		'AW',
93
		'AU',
94
		'AT',
95
		'AZ',
96
		'BS',
97
		'BH',
98
		'BD',
99
		'BB',
100
		'BY',
101
		'BE',
102
		'BZ',
103
		'BJ',
104
		'BM',
105
		'BT',
106
		'BO',
107
		'BQ',
108
		'BA',
109
		'BW',
110
		'BV',
111
		'BR',
112
		'IO',
113
		'BN',
114
		'BG',
115
		'BF',
116
		'BI',
117
		'KH',
118
		'CM',
119
		'CA',
120
		'CV',
121
		'KY',
122
		'CF',
123
		'TD',
124
		'CL',
125
		'CN',
126
		'CX',
127
		'CC',
128
		'CO',
129
		'KM',
130
		'CG',
131
		'CD',
132
		'CK',
133
		'CR',
134
		'CI',
135
		'HR',
136
		'CU',
137
		'CW',
138
		'CY',
139
		'CZ',
140
		'DK',
141
		'DJ',
142
		'DM',
143
		'DO',
144
		'EC',
145
		'EG',
146
		'SV',
147
		'GQ',
148
		'ER',
149
		'EE',
150
		'ET',
151
		'FK',
152
		'FO',
153
		'FJ',
154
		'FI',
155
		'FR',
156
		'GF',
157
		'PF',
158
		'TF',
159
		'GA',
160
		'GM',
161
		'GE',
162
		'DE',
163
		'GH',
164
		'GI',
165
		'GR',
166
		'GL',
167
		'GD',
168
		'GP',
169
		'GU',
170
		'GT',
171
		'GG',
172
		'GN',
173
		'GW',
174
		'GY',
175
		'HT',
176
		'HM',
177
		'VA',
178
		'HN',
179
		'HK',
180
		'HU',
181
		'IS',
182
		'IN',
183
		'ID',
184
		'IR',
185
		'IQ',
186
		'IE',
187
		'IM',
188
		'IL',
189
		'IT',
190
		'JM',
191
		'JP',
192
		'JE',
193
		'JO',
194
		'KZ',
195
		'KE',
196
		'KI',
197
		'KP',
198
		'KR',
199
		'KW',
200
		'KG',
201
		'LA',
202
		'LV',
203
		'LB',
204
		'LS',
205
		'LR',
206
		'LY',
207
		'LI',
208
		'LT',
209
		'LU',
210
		'MO',
211
		'MK',
212
		'MG',
213
		'MW',
214
		'MY',
215
		'MV',
216
		'ML',
217
		'MT',
218
		'MH',
219
		'MQ',
220
		'MR',
221
		'MU',
222
		'YT',
223
		'MX',
224
		'FM',
225
		'MD',
226
		'MC',
227
		'MN',
228
		'ME',
229
		'MS',
230
		'MA',
231
		'MZ',
232
		'MM',
233
		'NA',
234
		'NR',
235
		'NP',
236
		'NL',
237
		'NC',
238
		'NZ',
239
		'NI',
240
		'NE',
241
		'NG',
242
		'NU',
243
		'NF',
244
		'MP',
245
		'NO',
246
		'OM',
247
		'PK',
248
		'PW',
249
		'PS',
250
		'PA',
251
		'PG',
252
		'PY',
253
		'PE',
254
		'PH',
255
		'PN',
256
		'PL',
257
		'PT',
258
		'PR',
259
		'QA',
260
		'RE',
261
		'RO',
262
		'RU',
263
		'RW',
264
		'BL',
265
		'SH',
266
		'KN',
267
		'LC',
268
		'MF',
269
		'PM',
270
		'VC',
271
		'WS',
272
		'SM',
273
		'ST',
274
		'SA',
275
		'SN',
276
		'RS',
277
		'SC',
278
		'SL',
279
		'SG',
280
		'SX',
281
		'SK',
282
		'SI',
283
		'SB',
284
		'SO',
285
		'ZA',
286
		'GS',
287
		'SS',
288
		'ES',
289
		'LK',
290
		'SD',
291
		'SR',
292
		'SJ',
293
		'SZ',
294
		'SE',
295
		'CH',
296
		'SY',
297
		'TW',
298
		'TJ',
299
		'TZ',
300
		'TH',
301
		'TL',
302
		'TG',
303
		'TK',
304
		'TO',
305
		'TT',
306
		'TN',
307
		'TR',
308
		'TM',
309
		'TC',
310
		'TV',
311
		'UG',
312
		'UA',
313
		'AE',
314
		'GB',
315
		'US',
316
		'UM',
317
		'UY',
318
		'UZ',
319
		'VU',
320
		'VE',
321
		'VN',
322
		'VG',
323
		'VI',
324
		'WF',
325
		'EH',
326
		'YE',
327
		'ZM',
328
		'ZW'
329
	];
330
331
	/**
332
	 * API Language.
333
	 *
334
	 * @var string
335
	 */
336
	protected $language;
337
338
	/**
339
	 * API Languages.
340
	 *
341
	 * @var array
342
	 */
343
	protected $languages = [
344
		'af',
345
		'ar-ae',
346
		'ar-bh',
347
		'ar-dz',
348
		'ar-eg',
349
		'ar-iq',
350
		'ar-jo',
351
		'ar-kw',
352
		'ar-lb',
353
		'ar-ly',
354
		'ar-ma',
355
		'ar-om',
356
		'ar-qa',
357
		'ar-sa',
358
		'ar-sy',
359
		'ar-tn',
360
		'ar-ye',
361
		'be',
362
		'bg',
363
		'ca',
364
		'cs',
365
		'da',
366
		'de',
367
		'de-at',
368
		'de-ch',
369
		'de-li',
370
		'de-lu',
371
		'el',
372
		'en',
373
		'en-au',
374
		'en-bz',
375
		'en-ca',
376
		'en-gb',
377
		'en-ie',
378
		'en-jm',
379
		'en-nz',
380
		'en-tt',
381
		'en-us',
382
		'en-za',
383
		'es',
384
		'es-ar',
385
		'es-bo',
386
		'es-cl',
387
		'es-co',
388
		'es-cr',
389
		'es-do',
390
		'es-ec',
391
		'es-gt',
392
		'es-hn',
393
		'es-mx',
394
		'es-ni',
395
		'es-pa',
396
		'es-pe',
397
		'es-pr',
398
		'es-py',
399
		'es-sv',
400
		'es-uy',
401
		'es-ve',
402
		'et',
403
		'eu',
404
		'fa',
405
		'fi',
406
		'fo',
407
		'fr',
408
		'fr-be',
409
		'fr-ca',
410
		'fr-ch',
411
		'fr-lu',
412
		'ga',
413
		'gd',
414
		'he',
415
		'hi',
416
		'hr',
417
		'hu',
418
		'id',
419
		'is',
420
		'it',
421
		'it-ch',
422
		'ja',
423
		'ji',
424
		'ko',
425
		'ko',
426
		'ku',
427
		'lt',
428
		'lv',
429
		'mk',
430
		'ml',
431
		'ms',
432
		'mt',
433
		'nl',
434
		'nl-be',
435
		'nb',
436
		'nn',
437
		'no',
438
		'pa',
439
		'pl',
440
		'pt',
441
		'pt-br',
442
		'rm',
443
		'ro',
444
		'ro-md',
445
		'ru',
446
		'ru-md',
447
		'sb',
448
		'sk',
449
		'sl',
450
		'sq',
451
		'sr',
452
		'sv',
453
		'sv-fi',
454
		'th',
455
		'tn',
456
		'tr',
457
		'ts',
458
		'uk',
459
		'ur',
460
		've',
461
		'vi',
462
		'xh',
463
		'zh-cn',
464
		'zh-hk',
465
		'zh-sg',
466
		'zh-tw',
467
		'zu'
468
	];
469
470
	/**
471
	 * User custom maps.
472
	 *
473
	 * @var boolean
474
	 */
475
	protected $user;
476
477
	/**
478
	 * Automatic map marker.
479
	 *
480
	 * @var boolean
481
	 */
482
	protected $marker;
483
484
	/**
485
	 * Center map automatically.
486
	 *
487
	 * @var boolean
488
	 */
489
	protected $center;
490
491
	/**
492
	 * Show map UI.
493
	 *
494
	 * @var boolean
495
	 */
496
	protected $ui;
497
498
	/**
499
	 * Map zoom level.
500
	 *
501
	 * @var integer
502
	 */
503
	protected $zoom;
504
505
	/**
506
	 * Map scroll wheel zoom.
507
	 *
508
	 * @var boolean
509
	 */
510
	protected $scrollWheelZoom;
511
512
	/**
513
	 * Map type.
514
	 *
515
	 * @var string
516
	 */
517
	protected $type;
518
519
	/**
520
	 * Available map types.
521
	 *
522
	 * @var array
523
	 */
524
	protected $types = [
525
		'ROADMAP',
526
		'SATELLITE',
527
		'HYBRID',
528
		'TERRAIN'
529
	];
530
531
	/**
532
	 * Map tilt.
533
	 *
534
	 * @var integer
535
	 */
536
	protected $tilt;
537
538
	/**
539
	 * Map marker icon.
540
	 *
541
	 * @var string
542
	 */
543
	protected $icon;
544
545
	/**
546
	 * Map marker animation.
547
	 *
548
	 * @var string
549
	 */
550
	protected $animation;
551
552
	/**
553
	 * Available map marker animations.
554
	 *
555
	 * @var array
556
	 */
557
	protected $animations = [
558
		'NONE',
559
		'DROP',
560
		'BOUNCE',
561
	];
562
563
	/**
564
	 * Map marker cluster.
565
	 *
566
	 * @var boolean
567
	 */
568
	protected $cluster;
569
570
	/**
571
	 * Mapping items.
572
	 *
573
	 * @var array
574
	 */
575
	public $items = [];
576
577
	/**
578
	 * Construct Googlmapper.
579
	 *
580
	 * @param View  $view
581
	 * @param array $options
582
	 *
583
	 * @throws MapperArgumentException
584
	 */
585
	public function __construct(View $view, array $options = [])
586
	{
587
		$this->view = $view;
588
589
		if (!isset($options['key'])) {
590
			throw new MapperArgumentException('Google maps API key is required.');
591
		}
592
593
		if (!isset($options['region'])) {
594
			throw new MapperArgumentException('Region is required.');
595
		}
596
597
		if (!in_array($options['region'], $this->regions)) {
598
			throw new MapperArgumentException('Region is required in ISO 3166-1 code format.');
599
		}
600
601
		if (!isset($options['language']) || !in_array($options['language'], $this->languages)) {
602
			throw new MapperArgumentException('Language is required.');
603
		}
604
605
		if (!in_array($options['language'], $this->languages)) {
606
			throw new MapperArgumentException('Language is required in ISO 639-1 code format.');
607
		}
608
609
		$this->setEnabled(isset($options['enabled']) ? $options['enabled'] : true);
610
		$this->setKey($options['key']);
611
		$this->setRegion(isset($options['region']) ? $options['region'] : self::REGION);
612
		$this->setLanguage(isset($options['language']) ? $options['language'] : self::LANGUAGE);
613
		$this->setUser(isset($options['user']) ? $options['user'] : false);
614
		$this->setMarker(isset($options['marker']) ? $options['marker'] : true);
615
		$this->setCenter(isset($options['centre']) ? $options['centre'] : true);
616
		$this->setZoom(isset($options['zoom']) ? $options['zoom'] : self::ZOOM);
617
		$this->setScrollWheelZoom(isset($options['scrollWheelZoom']) ? $options['scrollWheelZoom'] : self::SCROLL_WHEEL_ZOOM);
618
		$this->setType(isset($options['type']) ? $options['type'] : self::TYPE_ROADMAP);
619
		$this->setTilt(isset($options['tilt']) ? $options['tilt'] : self::TILT);
620
		$this->setUi(isset($options['ui']) ? $options['ui'] : true);
621
		$this->setIcon(isset($options['markers']['icon']) ? $options['markers']['icon'] : '');
622
		$this->setAnimation(isset($options['markers']['animation']) ? $options['markers']['animation'] : self::ANIMATION_NONE);
623
		$this->setCluster(isset($options['cluster']) ? $options['cluster'] : true);
624
	}
625
626
	/**
627
	 * Is mapping enabled?
628
	 *
629
	 * @return boolean
630
	 */
631
	public function isEnabled()
632
	{
633
		return $this->getEnabled();
634
	}
635
636
	/**
637
	 * Set enabled status.
638
	 *
639
	 * @param boolean $value
640
	 *
641
	 * @throws MapperArgumentException
642
	 *
643
	 * @return void
644
	 */
645
	protected function setEnabled($value)
646
	{
647
		if (!is_bool($value)) {
648
			throw new MapperArgumentException('Invalid map enabled setting.');
649
		}
650
651
		$this->enabled = $value;
652
	}
653
654
	/**
655
	 * Get the enabled status.
656
	 *
657
	 * @return boolean
658
	 */
659
	protected function getEnabled()
660
	{
661
		return $this->enabled;
662
	}
663
664
	/**
665
	 * Enable mapping.
666
	 *
667
	 * @return void
668
	 */
669
	public function enableMapping()
670
	{
671
		$this->setEnabled(true);
672
	}
673
674
	/**
675
	 * Disable mapping.
676
	 *
677
	 * @return void
678
	 */
679
	public function disableMapping()
680
	{
681
		$this->setEnabled(false);
682
	}
683
684
	/**
685
	 * Set the Google Maps key.
686
	 *
687
	 * @param string $value
688
	 *
689
	 * @throws MapperArgumentException
690
	 *
691
	 * @return void
692
	 */
693
	public function setKey($value)
694
	{
695
		if (!is_string($value)) {
696
			throw new MapperArgumentException('Invalid Google Map\'s API key.');
697
		}
698
699
		$this->key = $value;
700
	}
701
702
	/**
703
	 * Get the Google Maps key.
704
	 *
705
	 * @return string
706
	 */
707
	public function getKey()
708
	{
709
		return $this->key;
710
	}
711
712
	/**
713
	 * Set the Google Maps region.
714
	 *
715
	 * @param string $value
716
	 *
717
	 * @throws MapperArgumentException
718
	 *
719
	 * @return void
720
	 */
721 View Code Duplication
	public function setRegion($value)
722
	{
723
		if (!is_string($value)) {
724
			throw new MapperArgumentException('Invalid map region.');
725
		}
726
727
		if (!in_array($value, $this->regions)) {
728
			throw new MapperArgumentException('Region is required in ISO 3166-1 code format.');
729
		}
730
731
		$this->region = $value;
732
	}
733
734
	/**
735
	 * Get the Google Maps region.
736
	 *
737
	 * @return string
738
	 */
739
	public function getRegion()
740
	{
741
		return $this->region;
742
	}
743
744
	/**
745
	 * Set the Google Maps language.
746
	 *
747
	 * @param string $value
748
	 *
749
	 * @throws MapperArgumentException
750
	 *
751
	 * @return void
752
	 */
753 View Code Duplication
	public function setLanguage($value)
754
	{
755
		if (!is_string($value)) {
756
			throw new MapperArgumentException('Invalid map language.');
757
		}
758
759
		if (!in_array($value, $this->languages)) {
760
			throw new MapperArgumentException('Language is required in ISO 639-1 code format.');
761
		}
762
763
		$this->language = $value;
764
	}
765
766
	/**
767
	 * Get the Google Maps language.
768
	 *
769
	 * @return string
770
	 */
771
	public function getLanguage()
772
	{
773
		return $this->language;
774
	}
775
776
	/**
777
	 * Set the map user status.
778
	 *
779
	 * @param boolean $value
780
	 *
781
	 * @throws MapperArgumentException
782
	 *
783
	 * @return void
784
	 */
785
	protected function setUser($value)
786
	{
787
		if (!is_bool($value)) {
788
			throw new MapperArgumentException('Invalid map user status.');
789
		}
790
791
		$this->user = $value;
792
	}
793
794
	/**
795
	 * Get the map user status.
796
	 *
797
	 * @return boolean
798
	 */
799
	public function getUser()
800
	{
801
		return $this->user;
802
	}
803
804
	/**
805
	 * Enable users for maps.
806
	 *
807
	 * @return void
808
	 */
809
	public function enableUsers()
810
	{
811
		$this->setUser(true);
812
	}
813
814
	/**
815
	 * Disable users for maps.
816
	 *
817
	 * @return void
818
	 */
819
	public function disableUsers()
820
	{
821
		$this->setUser(false);
822
	}
823
824
	/**
825
	 * Set the marker status.
826
	 *
827
	 * @param boolean $value
828
	 *
829
	 * @throws MapperArgumentException
830
	 *
831
	 * @return void
832
	 */
833
	protected function setMarker($value)
834
	{
835
		if (!is_bool($value)) {
836
			throw new MapperArgumentException('Invalid map marker setting.');
837
		}
838
839
		$this->marker = $value;
840
	}
841
842
	/**
843
	 * Get the marker status.
844
	 *
845
	 * @return boolean
846
	 */
847
	public function getMarker()
848
	{
849
		return $this->marker;
850
	}
851
852
	/**
853
	 * Enable markers for maps.
854
	 *
855
	 * @return void
856
	 */
857
	public function enableMarkers()
858
	{
859
		$this->setMarker(true);
860
	}
861
862
	/**
863
	 * Disable markers for maps.
864
	 *
865
	 * @return void
866
	 */
867
	public function disableMarkers()
868
	{
869
		$this->setMarker(false);
870
	}
871
872
	/**
873
	 * Set the map center status.
874
	 *
875
	 * @param boolean $value
876
	 *
877
	 * @throws MapperArgumentException
878
	 *
879
	 * @return void
880
	 */
881
	protected function setCenter($value)
882
	{
883
		if (!is_bool($value)) {
884
			throw new MapperArgumentException('Invalid map center setting.');
885
		}
886
887
		$this->center = $value;
888
	}
889
890
	/**
891
	 * Get the map center status.
892
	 *
893
	 * @return boolean
894
	 */
895
	public function getCenter()
896
	{
897
		return $this->center;
898
	}
899
900
	/**
901
	 * Enable center of maps.
902
	 *
903
	 * @return void
904
	 */
905
	public function enableCenter()
906
	{
907
		$this->setCenter(true);
908
	}
909
910
	/**
911
	 * Disable center of maps.
912
	 *
913
	 * @return void
914
	 */
915
	public function disableCenter()
916
	{
917
		$this->setCenter(false);
918
	}
919
920
	/**
921
	 * Set the map UI status.
922
	 *
923
	 * @param boolean $value
924
	 *
925
	 * @throws MapperArgumentException
926
	 *
927
	 * @return void
928
	 */
929
	protected function setUi($value)
930
	{
931
		if (!is_bool($value)) {
932
			throw new MapperArgumentException('Invalid map ui setting.');
933
		}
934
935
		$this->ui = $value;
936
	}
937
938
	/**
939
	 * Get the map UI status.
940
	 *
941
	 * @return boolean
942
	 */
943
	public function getUi()
944
	{
945
		return $this->ui;
946
	}
947
948
	/**
949
	 * Enable maps ui.
950
	 *
951
	 * @return void
952
	 */
953
	public function enableUi()
954
	{
955
		$this->setUi(false);
956
	}
957
958
	/**
959
	 * Disable maps ui.
960
	 *
961
	 * @return void
962
	 */
963
	public function disableUi()
964
	{
965
		$this->setUi(true);
966
	}
967
968
	/**
969
	 * Set map zoom level.
970
	 *
971
	 * @param integer $value
972
	 *
973
	 * @throws MapperArgumentException
974
	 *
975
	 * @return void
976
	 */
977
	public function setZoom($value)
978
	{
979
		if (!is_numeric($value)) {
980
			throw new MapperArgumentException('Zoom level must be an integer.');
981
		}
982
983
		if ($value < 1 || $value > 20) {
984
			throw new MapperArgumentException('A zoom level must be between 1 and 20.');
985
		}
986
987
		$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...
988
	}
989
990
	/**
991
	 * Get map zoom level.
992
	 *
993
	 * @return integer
994
	 */
995
	public function getZoom()
996
	{
997
		return $this->zoom;
998
	}
999
1000
	/**
1001
	 * Set map scroll wheel zoom.
1002
	 *
1003
	 * @param boolean $value
1004
	 *
1005
	 * @throws MapperArgumentException
1006
	 *
1007
	 * @return void
1008
	 */
1009
	public function setScrollWheelZoom($value)
1010
	{
1011
		if (!is_bool($value)) {
1012
			throw new MapperArgumentException('Mouse Wheel Zoom must be a boolean.');
1013
		}
1014
1015
		$this->scrollWheelZoom = $value;
1016
	}
1017
1018
	/**
1019
	 * Get map scroll wheel zoom.
1020
	 *
1021
	 * @return boolean
1022
	 */
1023
	public function getScrollWheelZoom()
1024
	{
1025
		return $this->scrollWheelZoom;
1026
	}
1027
1028
	/**
1029
	 * Set map type.
1030
	 *
1031
	 * @param string $value
1032
	 *
1033
	 * @throws MapperArgumentException
1034
	 *
1035
	 * @return void
1036
	 */
1037
	public function setType($value)
1038
	{
1039
		if (!in_array($value, $this->types)) {
1040
			throw new MapperArgumentException('Invalid map type.');
1041
		}
1042
1043
		$this->type = $value;
1044
	}
1045
1046
	/**
1047
	 * Get map type.
1048
	 *
1049
	 * @return string
1050
	 */
1051
	public function getType()
1052
	{
1053
		return $this->type;
1054
	}
1055
1056
	/**
1057
	 * Set map tilt.
1058
	 *
1059
	 * @param integer|double $value
1060
	 *
1061
	 * @throws MapperArgumentException
1062
	 *
1063
	 * @return void
1064
	 */
1065
	public function setTilt($value)
1066
	{
1067
		if (!is_numeric($value)) {
1068
			throw new MapperArgumentException('Invalid map tilt.');
1069
		}
1070
1071
		$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...
1072
	}
1073
1074
	/**
1075
	 * Get map $tilt.
1076
	 *
1077
	 * @return integer
1078
	 */
1079
	public function getTilt()
1080
	{
1081
		return $this->tilt;
1082
	}
1083
1084
	/**
1085
	 * Set map marker icon.
1086
	 *
1087
	 * @param string $value
1088
	 *
1089
	 * @throws MapperArgumentException
1090
	 *
1091
	 * @return void
1092
	 */
1093
	public function setIcon($value)
1094
	{
1095
		if (!is_string($value)) {
1096
			throw new MapperArgumentException('Invalid map marker icon.');
1097
		}
1098
1099
		$this->icon = $value;
1100
	}
1101
1102
	/**
1103
	 * Get map marker icon.
1104
	 *
1105
	 * @return string
1106
	 */
1107
	public function getIcon()
1108
	{
1109
		return $this->icon;
1110
	}
1111
1112
	/**
1113
	 * Set map marker animation.
1114
	 *
1115
	 * @param string $value
1116
	 *
1117
	 * @throws MapperArgumentException
1118
	 *
1119
	 * @return void
1120
	 */
1121
	public function setAnimation($value)
1122
	{
1123
		if (!in_array($value, $this->animations)) {
1124
			throw new MapperArgumentException('Invalid map marker animation.');
1125
		}
1126
1127
		$this->animation = $value;
1128
	}
1129
1130
	/**
1131
	 * Get map marker animation.
1132
	 *
1133
	 * @return string
1134
	 */
1135
	public function getAnimation()
1136
	{
1137
		return $this->animation;
1138
	}
1139
1140
	/**
1141
	 * Get mapper options.
1142
	 *
1143
	 * @return array
1144
	 */
1145
	protected function getOptions()
1146
	{
1147
		return [
1148
			'key' => $this->getKey(),
1149
			'version' => $this->version,
1150
			'region' => $this->getRegion(),
1151
			'language' => $this->getLanguage(),
1152
			'user' => $this->getUser(),
1153
			'marker' => $this->getMarker(),
1154
			'center' => $this->getCenter(),
1155
			'zoom' => $this->getZoom(),
1156
			'scrollWheelZoom' => $this->getScrollWheelZoom(),
1157
			'type' => $this->getType(),
1158
			'tilt' => $this->getTilt(),
1159
			'ui' => $this->getUi(),
1160
			'overlay' => '',
1161
			'markers' => [
1162
				'title' => '',
1163
				'content' => '',
1164
				'icon' => $this->getIcon(),
1165
				'place' => '',
1166
				'animation' => $this->getAnimation(),
1167
				'symbol' => '',
1168
			],
1169
			'cluster' => $this->getCluster()
1170
		];
1171
	}
1172
1173
	/**
1174
	 * Add mapping item.
1175
	 *
1176
	 * @param object $value
1177
	 *
1178
	 * @return void
1179
	 */
1180
	protected function addItem($value)
1181
	{
1182
		$this->items[] = $value;
1183
	}
1184
1185
	/**
1186
	 * Set mapping items.
1187
	 *
1188
	 * @param array $array
1189
	 *
1190
	 * @return void
1191
	 */
1192
	protected function setItems(array $array)
1193
	{
1194
		$this->items = $array;
1195
	}
1196
1197
	/**
1198
	 * Get the mapping items.
1199
	 *
1200
	 * @return array
1201
	 */
1202
	public function getItems()
1203
	{
1204
		return $this->items;
1205
	}
1206
1207
	/**
1208
	 * Get a mapping item by reference.
1209
	 *
1210
	 * @param integer $item
1211
	 *
1212
	 * @return array|boolean
1213
	 */
1214
	public function getItem($item)
1215
	{
1216
		return isset($this->items[$item]) ? $this->items[$item] : false;
1217
	}
1218
1219
	/**
1220
	 * Set cluster status.
1221
	 *
1222
	 * @param boolean $value
1223
	 *
1224
	 * @throws MapperArgumentException
1225
	 *
1226
	 * @return void
1227
	 */
1228
	protected function setCluster($value)
1229
	{
1230
		if (!is_bool($value)) {
1231
			throw new MapperArgumentException('Invalid map cluster setting.');
1232
		}
1233
1234
		$this->cluster = $value;
1235
	}
1236
1237
	/**
1238
	 * Get the cluster status.
1239
	 *
1240
	 * @return boolean
1241
	 */
1242
	protected function getCluster()
1243
	{
1244
		return $this->cluster;
1245
	}
1246
1247
	/**
1248
	 * Enable cluster.
1249
	 *
1250
	 * @return void
1251
	 */
1252
	public function enableCluster()
1253
	{
1254
		$this->setCluster(true);
1255
	}
1256
1257
	/**
1258
	 * Disable cluster.
1259
	 *
1260
	 * @return void
1261
	 */
1262
	public function disableCluster()
1263
	{
1264
		$this->setCluster(false);
1265
	}
1266
1267
}