Completed
Push — master ( d821a1...69acc7 )
by Bradley
04:26
created

MapperBase::addItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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 ENABLED = true;
11
12
	const REGION = 'GB';
13
14
	const LANGUAGE = 'en-gb';
15
16
	const TYPE_ROADMAP = 'ROADMAP';
17
	const TYPE_SATELLITE = 'SATELLITE';
18
	const TYPE_HYBRID = 'HYBRID';
19
	const TYPE_TERRAIN = 'TERRAIN';
20
21
	const USER = false;
22
23
	const MARKER = true;
24
25
	const CENTER = true;
26
27
	const ZOOM = 8;
28
	const SCROLL_WHEEL_ZOOM = true;
29
30
	const TILT = 90;
31
32
	const UI = true;
33
34
	const ANIMATION_NONE = 'NONE';
35
	const ANIMATION_DROP = 'DROP';
36
	const ANIMATION_BOUNCE = 'BOUNCE';
37
38
	const OVERLAY_NONE = 'NONE';
39
	const OVERLAY_BIKE = 'BIKE';
40
	const OVERLAY_TRANSIT = 'TRANSIT';
41
	const OVERLAY_TRAFFIC = 'TRAFFIC';
42
43
	const SYMBOL_CIRCLE = 'CIRCLE';
44
	const SYMBOL_BACKWARD_CLOSED_ARROW = 'BACKWARD_CLOSED_ARROW';
45
	const SYMBOL_FORWARD_CLOSED_ARROW = 'FORWARD_CLOSED_ARROW';
46
	const SYMBOL_BACKWARD_OPEN_ARROW = 'BACKWARD_OPEN_ARROW';
47
	const SYMBOL_FORWARD_OPEN_ARROW = 'FORWARD_OPEN_ARROW';
48
49
	const ICON = '';
50
51
	const CLUSTER = true;
52
53
	const CLUSTERS_ICON = '//googlemaps.github.io/js-marker-clusterer/images/m';
54
	const CLUSTERS_GRID = 60;
55
	const CLUSTERS_ZOOM = null;
56
	const CLUSTERS_CENTER = false;
57
	const CLUSTERS_SIZE = 2;
58
59
	/**
60
	 * View.
61
	 *
62
	 * @var \Illuminate\View\Factory
63
	 */
64
	protected $view;
65
66
	/**
67
	 * Mapping enabled.
68
	 *
69
	 * @var boolean
70
	 */
71
	protected $enabled;
72
73
	/**
74
	 * API Key.
75
	 *
76
	 * @var string
77
	 */
78
	protected $key;
79
80
	/**
81
	 * API Version.
82
	 *
83
	 * @var integer
84
	 */
85
	protected $version = '3.exp';
86
87
	/**
88
	 * API region.
89
	 *
90
	 * @var string
91
	 */
92
	protected $region;
93
94
	/**
95
	 * API regions.
96
	 *
97
	 * @var array
98
	 */
99
	protected $regions = [
100
		'AF',
101
		'AX',
102
		'AL',
103
		'DZ',
104
		'AS',
105
		'AD',
106
		'AO',
107
		'AI',
108
		'AQ',
109
		'AG',
110
		'AR',
111
		'AM',
112
		'AW',
113
		'AU',
114
		'AT',
115
		'AZ',
116
		'BS',
117
		'BH',
118
		'BD',
119
		'BB',
120
		'BY',
121
		'BE',
122
		'BZ',
123
		'BJ',
124
		'BM',
125
		'BT',
126
		'BO',
127
		'BQ',
128
		'BA',
129
		'BW',
130
		'BV',
131
		'BR',
132
		'IO',
133
		'BN',
134
		'BG',
135
		'BF',
136
		'BI',
137
		'KH',
138
		'CM',
139
		'CA',
140
		'CV',
141
		'KY',
142
		'CF',
143
		'TD',
144
		'CL',
145
		'CN',
146
		'CX',
147
		'CC',
148
		'CO',
149
		'KM',
150
		'CG',
151
		'CD',
152
		'CK',
153
		'CR',
154
		'CI',
155
		'HR',
156
		'CU',
157
		'CW',
158
		'CY',
159
		'CZ',
160
		'DK',
161
		'DJ',
162
		'DM',
163
		'DO',
164
		'EC',
165
		'EG',
166
		'SV',
167
		'GQ',
168
		'ER',
169
		'EE',
170
		'ET',
171
		'FK',
172
		'FO',
173
		'FJ',
174
		'FI',
175
		'FR',
176
		'GF',
177
		'PF',
178
		'TF',
179
		'GA',
180
		'GM',
181
		'GE',
182
		'DE',
183
		'GH',
184
		'GI',
185
		'GR',
186
		'GL',
187
		'GD',
188
		'GP',
189
		'GU',
190
		'GT',
191
		'GG',
192
		'GN',
193
		'GW',
194
		'GY',
195
		'HT',
196
		'HM',
197
		'VA',
198
		'HN',
199
		'HK',
200
		'HU',
201
		'IS',
202
		'IN',
203
		'ID',
204
		'IR',
205
		'IQ',
206
		'IE',
207
		'IM',
208
		'IL',
209
		'IT',
210
		'JM',
211
		'JP',
212
		'JE',
213
		'JO',
214
		'KZ',
215
		'KE',
216
		'KI',
217
		'KP',
218
		'KR',
219
		'KW',
220
		'KG',
221
		'LA',
222
		'LV',
223
		'LB',
224
		'LS',
225
		'LR',
226
		'LY',
227
		'LI',
228
		'LT',
229
		'LU',
230
		'MO',
231
		'MK',
232
		'MG',
233
		'MW',
234
		'MY',
235
		'MV',
236
		'ML',
237
		'MT',
238
		'MH',
239
		'MQ',
240
		'MR',
241
		'MU',
242
		'YT',
243
		'MX',
244
		'FM',
245
		'MD',
246
		'MC',
247
		'MN',
248
		'ME',
249
		'MS',
250
		'MA',
251
		'MZ',
252
		'MM',
253
		'NA',
254
		'NR',
255
		'NP',
256
		'NL',
257
		'NC',
258
		'NZ',
259
		'NI',
260
		'NE',
261
		'NG',
262
		'NU',
263
		'NF',
264
		'MP',
265
		'NO',
266
		'OM',
267
		'PK',
268
		'PW',
269
		'PS',
270
		'PA',
271
		'PG',
272
		'PY',
273
		'PE',
274
		'PH',
275
		'PN',
276
		'PL',
277
		'PT',
278
		'PR',
279
		'QA',
280
		'RE',
281
		'RO',
282
		'RU',
283
		'RW',
284
		'BL',
285
		'SH',
286
		'KN',
287
		'LC',
288
		'MF',
289
		'PM',
290
		'VC',
291
		'WS',
292
		'SM',
293
		'ST',
294
		'SA',
295
		'SN',
296
		'RS',
297
		'SC',
298
		'SL',
299
		'SG',
300
		'SX',
301
		'SK',
302
		'SI',
303
		'SB',
304
		'SO',
305
		'ZA',
306
		'GS',
307
		'SS',
308
		'ES',
309
		'LK',
310
		'SD',
311
		'SR',
312
		'SJ',
313
		'SZ',
314
		'SE',
315
		'CH',
316
		'SY',
317
		'TW',
318
		'TJ',
319
		'TZ',
320
		'TH',
321
		'TL',
322
		'TG',
323
		'TK',
324
		'TO',
325
		'TT',
326
		'TN',
327
		'TR',
328
		'TM',
329
		'TC',
330
		'TV',
331
		'UG',
332
		'UA',
333
		'AE',
334
		'GB',
335
		'US',
336
		'UM',
337
		'UY',
338
		'UZ',
339
		'VU',
340
		'VE',
341
		'VN',
342
		'VG',
343
		'VI',
344
		'WF',
345
		'EH',
346
		'YE',
347
		'ZM',
348
		'ZW'
349
	];
350
351
	/**
352
	 * API Language.
353
	 *
354
	 * @var string
355
	 */
356
	protected $language;
357
358
	/**
359
	 * API Languages.
360
	 *
361
	 * @var array
362
	 */
363
	protected $languages = [
364
		'af',
365
		'ar-ae',
366
		'ar-bh',
367
		'ar-dz',
368
		'ar-eg',
369
		'ar-iq',
370
		'ar-jo',
371
		'ar-kw',
372
		'ar-lb',
373
		'ar-ly',
374
		'ar-ma',
375
		'ar-om',
376
		'ar-qa',
377
		'ar-sa',
378
		'ar-sy',
379
		'ar-tn',
380
		'ar-ye',
381
		'be',
382
		'bg',
383
		'ca',
384
		'cs',
385
		'da',
386
		'de',
387
		'de-at',
388
		'de-ch',
389
		'de-li',
390
		'de-lu',
391
		'el',
392
		'en',
393
		'en-au',
394
		'en-bz',
395
		'en-ca',
396
		'en-gb',
397
		'en-ie',
398
		'en-jm',
399
		'en-nz',
400
		'en-tt',
401
		'en-us',
402
		'en-za',
403
		'es',
404
		'es-ar',
405
		'es-bo',
406
		'es-cl',
407
		'es-co',
408
		'es-cr',
409
		'es-do',
410
		'es-ec',
411
		'es-gt',
412
		'es-hn',
413
		'es-mx',
414
		'es-ni',
415
		'es-pa',
416
		'es-pe',
417
		'es-pr',
418
		'es-py',
419
		'es-sv',
420
		'es-uy',
421
		'es-ve',
422
		'et',
423
		'eu',
424
		'fa',
425
		'fi',
426
		'fo',
427
		'fr',
428
		'fr-be',
429
		'fr-ca',
430
		'fr-ch',
431
		'fr-lu',
432
		'ga',
433
		'gd',
434
		'he',
435
		'hi',
436
		'hr',
437
		'hu',
438
		'id',
439
		'is',
440
		'it',
441
		'it-ch',
442
		'ja',
443
		'ji',
444
		'ko',
445
		'ko',
446
		'ku',
447
		'lt',
448
		'lv',
449
		'mk',
450
		'ml',
451
		'ms',
452
		'mt',
453
		'nl',
454
		'nl-be',
455
		'nb',
456
		'nn',
457
		'no',
458
		'pa',
459
		'pl',
460
		'pt',
461
		'pt-br',
462
		'rm',
463
		'ro',
464
		'ro-md',
465
		'ru',
466
		'ru-md',
467
		'sb',
468
		'sk',
469
		'sl',
470
		'sq',
471
		'sr',
472
		'sv',
473
		'sv-fi',
474
		'th',
475
		'tn',
476
		'tr',
477
		'ts',
478
		'uk',
479
		'ur',
480
		've',
481
		'vi',
482
		'xh',
483
		'zh-cn',
484
		'zh-hk',
485
		'zh-sg',
486
		'zh-tw',
487
		'zu'
488
	];
489
490
	/**
491
	 * User custom maps.
492
	 *
493
	 * @var boolean
494
	 */
495
	protected $user;
496
497
	/**
498
	 * Automatic map marker.
499
	 *
500
	 * @var boolean
501
	 */
502
	protected $marker;
503
504
	/**
505
	 * Center map automatically.
506
	 *
507
	 * @var boolean
508
	 */
509
	protected $center;
510
511
	/**
512
	 * Show map UI.
513
	 *
514
	 * @var boolean
515
	 */
516
	protected $ui;
517
518
	/**
519
	 * Map zoom level.
520
	 *
521
	 * @var integer
522
	 */
523
	protected $zoom;
524
525
	/**
526
	 * Map scroll wheel zoom.
527
	 *
528
	 * @var boolean
529
	 */
530
	protected $scrollWheelZoom;
531
532
	/**
533
	 * Map type.
534
	 *
535
	 * @var string
536
	 */
537
	protected $type;
538
539
	/**
540
	 * Available map types.
541
	 *
542
	 * @var array
543
	 */
544
	protected $types = [
545
		'ROADMAP',
546
		'SATELLITE',
547
		'HYBRID',
548
		'TERRAIN'
549
	];
550
551
	/**
552
	 * Map tilt.
553
	 *
554
	 * @var integer
555
	 */
556
	protected $tilt;
557
558
	/**
559
	 * Map marker icon.
560
	 *
561
	 * @var string
562
	 */
563
	protected $icon;
564
565
	/**
566
	 * Map marker animation.
567
	 *
568
	 * @var string
569
	 */
570
	protected $animation;
571
572
	/**
573
	 * Available map marker animations.
574
	 *
575
	 * @var array
576
	 */
577
	protected $animations = [
578
		'NONE',
579
		'DROP',
580
		'BOUNCE',
581
	];
582
583
	/**
584
	 * Map marker cluster.
585
	 *
586
	 * @var boolean
587
	 */
588
	protected $cluster;
589
590
	/**
591
	 * Map marker clusters icon.
592
	 *
593
	 * @var array
594
	 */
595
	protected $clustersIcon;
596
597
	/**
598
	 * Map marker clusters grid.
599
	 *
600
	 * @var integer
601
	 */
602
	protected $clustersGrid;
603
604
	/**
605
	 * Map marker clusters zoom.
606
	 *
607
	 * @var integer|null
608
	 */
609
	protected $clustersZoom;
610
611
	/**
612
	 * Map marker clusters center.
613
	 *
614
	 * @var boolean
615
	 */
616
	protected $clustersCenter;
617
618
	/**
619
	 * Map marker clusters size.
620
	 *
621
	 * @var integer
622
	 */
623
	protected $clustersSize;
624
625
	/**
626
	 * Mapping items.
627
	 *
628
	 * @var array
629
	 */
630
	public $items = [];
631
632
	/**
633
	 * Construct Googlmapper.
634
	 *
635
	 * @param View  $view
636
	 * @param array $options
637
	 *
638
	 * @throws MapperArgumentException
639
	 */
640
	public function __construct(View $view, array $options = [])
641
	{
642
		$this->view = $view;
643
644
		if (!isset($options['key'])) {
645
			throw new MapperArgumentException('Google maps API key is required.');
646
		}
647
648
		if (!isset($options['region'])) {
649
			throw new MapperArgumentException('Region is required.');
650
		}
651
652
		if (!in_array($options['region'], $this->regions)) {
653
			throw new MapperArgumentException('Region is required in ISO 3166-1 code format.');
654
		}
655
656
		if (!isset($options['language']) || !in_array($options['language'], $this->languages)) {
657
			throw new MapperArgumentException('Language is required.');
658
		}
659
660
		if (!in_array($options['language'], $this->languages)) {
661
			throw new MapperArgumentException('Language is required in ISO 639-1 code format.');
662
		}
663
664
		$this->setEnabled(isset($options['enabled']) ? $options['enabled'] : self::ENABLED);
665
		$this->setKey($options['key']);
666
		$this->setRegion(isset($options['region']) ? $options['region'] : self::REGION);
667
		$this->setLanguage(isset($options['language']) ? $options['language'] : self::LANGUAGE);
668
		$this->setUser(isset($options['user']) ? $options['user'] : self::USER);
669
		$this->setMarker(isset($options['marker']) ? $options['marker'] : self::MARKER);
670
		$this->setCenter(isset($options['center']) ? $options['center'] : self::CENTER);
671
		$this->setZoom(isset($options['zoom']) ? $options['zoom'] : self::ZOOM);
672
		$this->setScrollWheelZoom(isset($options['scrollWheelZoom']) ? $options['scrollWheelZoom'] : self::SCROLL_WHEEL_ZOOM);
673
		$this->setType(isset($options['type']) ? $options['type'] : self::TYPE_ROADMAP);
674
		$this->setTilt(isset($options['tilt']) ? $options['tilt'] : self::TILT);
675
		$this->setUi(isset($options['ui']) ? $options['ui'] : self::UI);
676
		$this->setIcon(isset($options['markers']['icon']) ? $options['markers']['icon'] : self::ICON);
677
		$this->setAnimation(isset($options['markers']['animation']) ? $options['markers']['animation'] : self::ANIMATION_NONE);
678
		$this->setCluster(isset($options['cluster']) ? $options['cluster'] : self::CLUSTER);
679
		$this->setClustersIcon(isset($options['clusters']['icon']) ? $options['clusters']['icon'] : self::CLUSTERS_ICON);
680
		$this->setClustersGrid(isset($options['clusters']['grid']) ? $options['clusters']['grid'] : self::CLUSTERS_GRID);
681
		$this->setClustersZoom(isset($options['clusters']['zoom']) ? $options['clusters']['zoom'] : self::CLUSTERS_ZOOM);
682
		$this->setClustersCenter(isset($options['clusters']['center']) ? $options['clusters']['center'] : self::CLUSTERS_CENTER);
683
		$this->setClustersSize(isset($options['clusters']['size']) ? $options['clusters']['size'] : self::CLUSTERS_SIZE);
684
	}
685
686
	/**
687
	 * Is mapping enabled?
688
	 *
689
	 * @return boolean
690
	 */
691
	public function isEnabled()
692
	{
693
		return $this->getEnabled();
694
	}
695
696
	/**
697
	 * Set enabled status.
698
	 *
699
	 * @param boolean $value
700
	 *
701
	 * @throws MapperArgumentException
702
	 *
703
	 * @return void
704
	 */
705
	protected function setEnabled($value)
706
	{
707
		if (!is_bool($value)) {
708
			throw new MapperArgumentException('Invalid map enabled setting.');
709
		}
710
711
		$this->enabled = $value;
712
	}
713
714
	/**
715
	 * Get the enabled status.
716
	 *
717
	 * @return boolean
718
	 */
719
	protected function getEnabled()
720
	{
721
		return $this->enabled;
722
	}
723
724
	/**
725
	 * Enable mapping.
726
	 *
727
	 * @return void
728
	 */
729
	public function enableMapping()
730
	{
731
		$this->setEnabled(true);
732
	}
733
734
	/**
735
	 * Disable mapping.
736
	 *
737
	 * @return void
738
	 */
739
	public function disableMapping()
740
	{
741
		$this->setEnabled(false);
742
	}
743
744
	/**
745
	 * Set the Google Maps key.
746
	 *
747
	 * @param string $value
748
	 *
749
	 * @throws MapperArgumentException
750
	 *
751
	 * @return void
752
	 */
753
	public function setKey($value)
754
	{
755
		if (!is_string($value)) {
756
			throw new MapperArgumentException('Invalid Google Map\'s API key.');
757
		}
758
759
		$this->key = $value;
760
	}
761
762
	/**
763
	 * Get the Google Maps key.
764
	 *
765
	 * @return string
766
	 */
767
	public function getKey()
768
	{
769
		return $this->key;
770
	}
771
772
	/**
773
	 * Set the Google Maps region.
774
	 *
775
	 * @param string $value
776
	 *
777
	 * @throws MapperArgumentException
778
	 *
779
	 * @return void
780
	 */
781 View Code Duplication
	public function setRegion($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
782
	{
783
		if (!is_string($value)) {
784
			throw new MapperArgumentException('Invalid map region.');
785
		}
786
787
		if (!in_array($value, $this->regions)) {
788
			throw new MapperArgumentException('Region is required in ISO 3166-1 code format.');
789
		}
790
791
		$this->region = $value;
792
	}
793
794
	/**
795
	 * Get the Google Maps region.
796
	 *
797
	 * @return string
798
	 */
799
	public function getRegion()
800
	{
801
		return $this->region;
802
	}
803
804
	/**
805
	 * Set the Google Maps language.
806
	 *
807
	 * @param string $value
808
	 *
809
	 * @throws MapperArgumentException
810
	 *
811
	 * @return void
812
	 */
813 View Code Duplication
	public function setLanguage($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
814
	{
815
		if (!is_string($value)) {
816
			throw new MapperArgumentException('Invalid map language.');
817
		}
818
819
		if (!in_array($value, $this->languages)) {
820
			throw new MapperArgumentException('Language is required in ISO 639-1 code format.');
821
		}
822
823
		$this->language = $value;
824
	}
825
826
	/**
827
	 * Get the Google Maps language.
828
	 *
829
	 * @return string
830
	 */
831
	public function getLanguage()
832
	{
833
		return $this->language;
834
	}
835
836
	/**
837
	 * Set the map user status.
838
	 *
839
	 * @param boolean $value
840
	 *
841
	 * @throws MapperArgumentException
842
	 *
843
	 * @return void
844
	 */
845
	protected function setUser($value)
846
	{
847
		if (!is_bool($value)) {
848
			throw new MapperArgumentException('Invalid map user status.');
849
		}
850
851
		$this->user = $value;
852
	}
853
854
	/**
855
	 * Get the map user status.
856
	 *
857
	 * @return boolean
858
	 */
859
	public function getUser()
860
	{
861
		return $this->user;
862
	}
863
864
	/**
865
	 * Enable users for maps.
866
	 *
867
	 * @return void
868
	 */
869
	public function enableUsers()
870
	{
871
		$this->setUser(true);
872
	}
873
874
	/**
875
	 * Disable users for maps.
876
	 *
877
	 * @return void
878
	 */
879
	public function disableUsers()
880
	{
881
		$this->setUser(false);
882
	}
883
884
	/**
885
	 * Set the marker status.
886
	 *
887
	 * @param boolean $value
888
	 *
889
	 * @throws MapperArgumentException
890
	 *
891
	 * @return void
892
	 */
893
	protected function setMarker($value)
894
	{
895
		if (!is_bool($value)) {
896
			throw new MapperArgumentException('Invalid map marker setting.');
897
		}
898
899
		$this->marker = $value;
900
	}
901
902
	/**
903
	 * Get the marker status.
904
	 *
905
	 * @return boolean
906
	 */
907
	public function getMarker()
908
	{
909
		return $this->marker;
910
	}
911
912
	/**
913
	 * Enable markers for maps.
914
	 *
915
	 * @return void
916
	 */
917
	public function enableMarkers()
918
	{
919
		$this->setMarker(true);
920
	}
921
922
	/**
923
	 * Disable markers for maps.
924
	 *
925
	 * @return void
926
	 */
927
	public function disableMarkers()
928
	{
929
		$this->setMarker(false);
930
	}
931
932
	/**
933
	 * Set the map center status.
934
	 *
935
	 * @param boolean $value
936
	 *
937
	 * @throws MapperArgumentException
938
	 *
939
	 * @return void
940
	 */
941
	protected function setCenter($value)
942
	{
943
		if (!is_bool($value)) {
944
			throw new MapperArgumentException('Invalid map center setting.');
945
		}
946
947
		$this->center = $value;
948
	}
949
950
	/**
951
	 * Get the map center status.
952
	 *
953
	 * @return boolean
954
	 */
955
	public function getCenter()
956
	{
957
		return $this->center;
958
	}
959
960
	/**
961
	 * Enable center of maps.
962
	 *
963
	 * @return void
964
	 */
965
	public function enableCenter()
966
	{
967
		$this->setCenter(true);
968
	}
969
970
	/**
971
	 * Disable center of maps.
972
	 *
973
	 * @return void
974
	 */
975
	public function disableCenter()
976
	{
977
		$this->setCenter(false);
978
	}
979
980
	/**
981
	 * Set the map UI status.
982
	 *
983
	 * @param boolean $value
984
	 *
985
	 * @throws MapperArgumentException
986
	 *
987
	 * @return void
988
	 */
989
	protected function setUi($value)
990
	{
991
		if (!is_bool($value)) {
992
			throw new MapperArgumentException('Invalid map ui setting.');
993
		}
994
995
		$this->ui = $value;
996
	}
997
998
	/**
999
	 * Get the map UI status.
1000
	 *
1001
	 * @return boolean
1002
	 */
1003
	public function getUi()
1004
	{
1005
		return $this->ui;
1006
	}
1007
1008
	/**
1009
	 * Enable maps ui.
1010
	 *
1011
	 * @return void
1012
	 */
1013
	public function enableUi()
1014
	{
1015
		$this->setUi(false);
1016
	}
1017
1018
	/**
1019
	 * Disable maps ui.
1020
	 *
1021
	 * @return void
1022
	 */
1023
	public function disableUi()
1024
	{
1025
		$this->setUi(true);
1026
	}
1027
1028
	/**
1029
	 * Set map zoom level.
1030
	 *
1031
	 * @param integer $value
1032
	 *
1033
	 * @throws MapperArgumentException
1034
	 *
1035
	 * @return void
1036
	 */
1037
	public function setZoom($value)
1038
	{
1039
		if (!is_numeric($value)) {
1040
			throw new MapperArgumentException('Zoom level must be an integer.');
1041
		}
1042
1043
		if ($value < 1 || $value > 20) {
1044
			throw new MapperArgumentException('A zoom level must be between 1 and 20.');
1045
		}
1046
1047
		$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...
1048
	}
1049
1050
	/**
1051
	 * Get map zoom level.
1052
	 *
1053
	 * @return integer
1054
	 */
1055
	public function getZoom()
1056
	{
1057
		return $this->zoom;
1058
	}
1059
1060
	/**
1061
	 * Set map scroll wheel zoom.
1062
	 *
1063
	 * @param boolean $value
1064
	 *
1065
	 * @throws MapperArgumentException
1066
	 *
1067
	 * @return void
1068
	 */
1069
	public function setScrollWheelZoom($value)
1070
	{
1071
		if (!is_bool($value)) {
1072
			throw new MapperArgumentException('Mouse Wheel Zoom must be a boolean.');
1073
		}
1074
1075
		$this->scrollWheelZoom = $value;
1076
	}
1077
1078
	/**
1079
	 * Get map scroll wheel zoom.
1080
	 *
1081
	 * @return boolean
1082
	 */
1083
	public function getScrollWheelZoom()
1084
	{
1085
		return $this->scrollWheelZoom;
1086
	}
1087
1088
	/**
1089
	 * Set map type.
1090
	 *
1091
	 * @param string $value
1092
	 *
1093
	 * @throws MapperArgumentException
1094
	 *
1095
	 * @return void
1096
	 */
1097
	public function setType($value)
1098
	{
1099
		if (!in_array($value, $this->types)) {
1100
			throw new MapperArgumentException('Invalid map type.');
1101
		}
1102
1103
		$this->type = $value;
1104
	}
1105
1106
	/**
1107
	 * Get map type.
1108
	 *
1109
	 * @return string
1110
	 */
1111
	public function getType()
1112
	{
1113
		return $this->type;
1114
	}
1115
1116
	/**
1117
	 * Set map tilt.
1118
	 *
1119
	 * @param integer|double $value
1120
	 *
1121
	 * @throws MapperArgumentException
1122
	 *
1123
	 * @return void
1124
	 */
1125
	public function setTilt($value)
1126
	{
1127
		if (!is_numeric($value)) {
1128
			throw new MapperArgumentException('Invalid map tilt.');
1129
		}
1130
1131
		$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...
1132
	}
1133
1134
	/**
1135
	 * Get map $tilt.
1136
	 *
1137
	 * @return integer
1138
	 */
1139
	public function getTilt()
1140
	{
1141
		return $this->tilt;
1142
	}
1143
1144
	/**
1145
	 * Set map marker icon.
1146
	 *
1147
	 * @param string $value
1148
	 *
1149
	 * @throws MapperArgumentException
1150
	 *
1151
	 * @return void
1152
	 */
1153
	public function setIcon($value)
1154
	{
1155
		if (!is_string($value)) {
1156
			throw new MapperArgumentException('Invalid map marker icon.');
1157
		}
1158
1159
		$this->icon = $value;
1160
	}
1161
1162
	/**
1163
	 * Get map marker icon.
1164
	 *
1165
	 * @return string
1166
	 */
1167
	public function getIcon()
1168
	{
1169
		return $this->icon;
1170
	}
1171
1172
	/**
1173
	 * Set map marker animation.
1174
	 *
1175
	 * @param string $value
1176
	 *
1177
	 * @throws MapperArgumentException
1178
	 *
1179
	 * @return void
1180
	 */
1181
	public function setAnimation($value)
1182
	{
1183
		if (!in_array($value, $this->animations)) {
1184
			throw new MapperArgumentException('Invalid map marker animation.');
1185
		}
1186
1187
		$this->animation = $value;
1188
	}
1189
1190
	/**
1191
	 * Get map marker animation.
1192
	 *
1193
	 * @return string
1194
	 */
1195
	public function getAnimation()
1196
	{
1197
		return $this->animation;
1198
	}
1199
	/**
1200
	 * Set cluster status.
1201
	 *
1202
	 * @param boolean $value
1203
	 *
1204
	 * @throws MapperArgumentException
1205
	 *
1206
	 * @return void
1207
	 */
1208
	protected function setCluster($value)
1209
	{
1210
		if (!is_bool($value)) {
1211
			throw new MapperArgumentException('Invalid map cluster setting.');
1212
		}
1213
1214
		$this->cluster = $value;
1215
	}
1216
1217
	/**
1218
	 * Get the cluster status.
1219
	 *
1220
	 * @return boolean
1221
	 */
1222
	public function getCluster()
1223
	{
1224
		return $this->cluster;
1225
	}
1226
1227
	/**
1228
	 * Enable cluster.
1229
	 *
1230
	 * @return void
1231
	 */
1232
	public function enableCluster()
1233
	{
1234
		$this->setCluster(true);
1235
	}
1236
1237
	/**
1238
	 * Disable cluster.
1239
	 *
1240
	 * @return void
1241
	 */
1242
	public function disableCluster()
1243
	{
1244
		$this->setCluster(false);
1245
	}
1246
1247
	/**
1248
	 * Set map cluster icon.
1249
	 *
1250
	 * @param string $value
1251
	 *
1252
	 * @throws MapperArgumentException
1253
	 *
1254
	 * @return void
1255
	 */
1256
	public function setClustersIcon($value)
1257
	{
1258
		if (!is_string($value)) {
1259
			throw new MapperArgumentException('Invalid map clusters icon setting.');
1260
		}
1261
1262
		$this->clustersIcon = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value of type string is incompatible with the declared type array of property $clustersIcon.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1263
	}
1264
1265
	/**
1266
	 * Get map clusters icon.
1267
	 *
1268
	 * @return string
1269
	 */
1270
	public function getClustersIcon()
1271
	{
1272
		return $this->clustersIcon;
1273
	}
1274
1275
	/**
1276
	 * Set map cluster grid.
1277
	 *
1278
	 * @param integer $value
1279
	 *
1280
	 * @throws MapperArgumentException
1281
	 *
1282
	 * @return void
1283
	 */
1284
	public function setClustersGrid($value)
1285
	{
1286
		if (!is_integer($value)) {
1287
			throw new MapperArgumentException('Invalid map clusters grid setting.');
1288
		}
1289
1290
		$this->clustersGrid = $value;
1291
	}
1292
1293
	/**
1294
	 * Get map cluster grid.
1295
	 *
1296
	 * @return integer
1297
	 */
1298
	public function getClustersGrid()
1299
	{
1300
		return $this->clustersGrid;
1301
	}
1302
1303
	/**
1304
	 * Set map cluster zoom.
1305
	 *
1306
	 * @param integer|null $value
1307
	 *
1308
	 * @throws MapperArgumentException
1309
	 *
1310
	 * @return void
1311
	 */
1312
	public function setClustersZoom($value)
1313
	{
1314
		if (!is_integer($value) && !is_null($value)) {
1315
			throw new MapperArgumentException('Invalid map clusters zoom setting.');
1316
		}
1317
1318
		$this->clustersZoom = $value;
1319
	}
1320
1321
	/**
1322
	 * Get map cluster grid.
1323
	 *
1324
	 * @return integer|null
1325
	 */
1326
	public function getClustersZoom()
1327
	{
1328
		return $this->clustersZoom;
1329
	}
1330
1331
	/**
1332
	 * Set map cluster center.
1333
	 *
1334
	 * @param boolean $value
1335
	 *
1336
	 * @throws MapperArgumentException
1337
	 *
1338
	 * @return void
1339
	 */
1340
	public function setClustersCenter($value)
1341
	{
1342
		if (!is_bool($value)) {
1343
			throw new MapperArgumentException('Invalid map clusters center setting.');
1344
		}
1345
1346
		$this->clustersCenter = $value;
1347
	}
1348
1349
	/**
1350
	 * Get map cluster center.
1351
	 *
1352
	 * @return boolean
1353
	 */
1354
	public function getClustersCenter()
1355
	{
1356
		return $this->clustersCenter;
1357
	}
1358
1359
	/**
1360
	 * Set map cluster size.
1361
	 *
1362
	 * @param integer $value
1363
	 *
1364
	 * @throws MapperArgumentException
1365
	 *
1366
	 * @return void
1367
	 */
1368
	public function setClustersSize($value)
1369
	{
1370
		if (!is_integer($value)) {
1371
			throw new MapperArgumentException('Invalid map clusters size setting.');
1372
		}
1373
1374
		$this->clustersSize = $value;
1375
	}
1376
1377
	/**
1378
	 * Get map cluster size.
1379
	 *
1380
	 * @return integer
1381
	 */
1382
	public function getClustersSize()
1383
	{
1384
		return $this->clustersSize;
1385
	}
1386
1387
	/**
1388
	 * Get mapper options.
1389
	 *
1390
	 * @return array
1391
	 */
1392
	protected function getOptions()
1393
	{
1394
		return [
1395
			'key' => $this->getKey(),
1396
			'version' => $this->version,
1397
			'region' => $this->getRegion(),
1398
			'language' => $this->getLanguage(),
1399
			'user' => $this->getUser(),
1400
			'marker' => $this->getMarker(),
1401
			'center' => $this->getCenter(),
1402
			'zoom' => $this->getZoom(),
1403
			'scrollWheelZoom' => $this->getScrollWheelZoom(),
1404
			'type' => $this->getType(),
1405
			'tilt' => $this->getTilt(),
1406
			'ui' => $this->getUi(),
1407
			'overlay' => '',
1408
			'markers' => [
1409
				'title' => '',
1410
				'content' => '',
1411
				'icon' => $this->getIcon(),
1412
				'place' => '',
1413
				'animation' => $this->getAnimation(),
1414
				'symbol' => '',
1415
			],
1416
			'cluster' => $this->getCluster(),
1417
			'clusters' => [
1418
				'icon' => $this->getClustersIcon(),
1419
				'grid' => $this->getClustersGrid(),
1420
				'zoom' => $this->getClustersZoom(),
1421
				'center' => $this->getClustersCenter(),
1422
				'size' => $this->getClustersSize()
1423
			],
1424
		];
1425
	}
1426
1427
	/**
1428
	 * Add mapping item.
1429
	 *
1430
	 * @param object $value
1431
	 *
1432
	 * @return void
1433
	 */
1434
	protected function addItem($value)
1435
	{
1436
		$this->items[] = $value;
1437
	}
1438
1439
	/**
1440
	 * Set mapping items.
1441
	 *
1442
	 * @param array $array
1443
	 *
1444
	 * @return void
1445
	 */
1446
	protected function setItems(array $array)
1447
	{
1448
		$this->items = $array;
1449
	}
1450
1451
	/**
1452
	 * Get the mapping items.
1453
	 *
1454
	 * @return array
1455
	 */
1456
	public function getItems()
1457
	{
1458
		return $this->items;
1459
	}
1460
1461
	/**
1462
	 * Get a mapping item by reference.
1463
	 *
1464
	 * @param integer $item
1465
	 *
1466
	 * @return array|boolean
1467
	 */
1468
	public function getItem($item)
1469
	{
1470
		return isset($this->items[$item]) ? $this->items[$item] : false;
1471
	}
1472
1473
}