Completed
Push — master ( 4f5a17...ce4d16 )
by Bradley
06:43
created

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

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
1370
	}
1371
1372
	/**
1373
	 * Set map cluster grid.
1374
	 *
1375
	 * @param integer $value
1376
	 *
1377
	 * @throws MapperArgumentException
1378
	 *
1379
	 * @return void
1380
	 */
1381
	public function setClustersGrid($value)
1382
	{
1383
		if (!is_integer($value)) {
1384
			throw new MapperArgumentException('Invalid map clusters grid setting.');
1385
		}
1386
1387
		$this->clustersGrid = $value;
1388
	}
1389
1390
	/**
1391
	 * Get map cluster grid.
1392
	 *
1393
	 * @return integer
1394
	 */
1395
	public function getClustersGrid()
1396
	{
1397
		return $this->clustersGrid;
1398
	}
1399
1400
	/**
1401
	 * Set map cluster zoom.
1402
	 *
1403
	 * @param integer|null $value
1404
	 *
1405
	 * @throws MapperArgumentException
1406
	 *
1407
	 * @return void
1408
	 */
1409
	public function setClustersZoom($value)
1410
	{
1411
		if (!is_integer($value) && !is_null($value)) {
1412
			throw new MapperArgumentException('Invalid map clusters zoom setting.');
1413
		}
1414
1415
		$this->clustersZoom = $value;
1416
	}
1417
1418
	/**
1419
	 * Get map cluster grid.
1420
	 *
1421
	 * @return integer|null
1422
	 */
1423
	public function getClustersZoom()
1424
	{
1425
		return $this->clustersZoom;
1426
	}
1427
1428
	/**
1429
	 * Set map cluster center.
1430
	 *
1431
	 * @param boolean $value
1432
	 *
1433
	 * @throws MapperArgumentException
1434
	 *
1435
	 * @return void
1436
	 */
1437
	public function setClustersCenter($value)
1438
	{
1439
		if (!is_bool($value)) {
1440
			throw new MapperArgumentException('Invalid map clusters center setting.');
1441
		}
1442
1443
		$this->clustersCenter = $value;
1444
	}
1445
1446
	/**
1447
	 * Get map cluster center.
1448
	 *
1449
	 * @return boolean
1450
	 */
1451
	public function getClustersCenter()
1452
	{
1453
		return $this->clustersCenter;
1454
	}
1455
1456
	/**
1457
	 * Set map cluster size.
1458
	 *
1459
	 * @param integer $value
1460
	 *
1461
	 * @throws MapperArgumentException
1462
	 *
1463
	 * @return void
1464
	 */
1465
	public function setClustersSize($value)
1466
	{
1467
		if (!is_integer($value)) {
1468
			throw new MapperArgumentException('Invalid map clusters size setting.');
1469
		}
1470
1471
		$this->clustersSize = $value;
1472
	}
1473
1474
	/**
1475
	 * Get map cluster size.
1476
	 *
1477
	 * @return integer
1478
	 */
1479
	public function getClustersSize()
1480
	{
1481
		return $this->clustersSize;
1482
	}
1483
1484
	/**
1485
	 * Get mapper options.
1486
	 *
1487
	 * @return array
1488
	 */
1489
	protected function getOptions()
1490
	{
1491
		return [
1492
			'key' => $this->getKey(),
1493
			'version' => $this->version,
1494
			'region' => $this->getRegion(),
1495
			'language' => $this->getLanguage(),
1496
			'user' => $this->getUser(),
1497
			'marker' => $this->getMarker(),
1498
			'center' => $this->getCenter(),
1499
			'locate' => $this->getLocate(),
1500
			'zoom' => $this->getZoom(),
1501
			'scrollWheelZoom' => $this->getScrollWheelZoom(),
1502
			'fullscreenControl' => $this->getFullscreenControl(),
1503
			'type' => $this->getType(),
1504
			'tilt' => $this->getTilt(),
1505
			'ui' => $this->getUi(),
1506
			'overlay' => '',
1507
			'markers' => [
1508
				'title' => '',
1509
				'content' => '',
1510
				'icon' => $this->getIcon(),
1511
				'place' => '',
1512
				'animation' => $this->getAnimation(),
1513
				'symbol' => '',
1514
			],
1515
			'cluster' => $this->getCluster(),
1516
			'clusters' => [
1517
				'icon' => $this->getClustersIcon(),
1518
				'grid' => $this->getClustersGrid(),
1519
				'zoom' => $this->getClustersZoom(),
1520
				'center' => $this->getClustersCenter(),
1521
				'size' => $this->getClustersSize()
1522
			],
1523
		];
1524
	}
1525
1526
	/**
1527
	 * Add mapping item.
1528
	 *
1529
	 * @param object $value
1530
	 *
1531
	 * @return void
1532
	 */
1533
	protected function addItem($value)
1534
	{
1535
		$this->items[] = $value;
1536
	}
1537
1538
	/**
1539
	 * Set mapping items.
1540
	 *
1541
	 * @param array $array
1542
	 *
1543
	 * @return void
1544
	 */
1545
	protected function setItems(array $array)
1546
	{
1547
		$this->items = $array;
1548
	}
1549
1550
	/**
1551
	 * Get the mapping items.
1552
	 *
1553
	 * @return array
1554
	 */
1555
	public function getItems()
1556
	{
1557
		return $this->items;
1558
	}
1559
1560
	/**
1561
	 * Get a mapping item by reference.
1562
	 *
1563
	 * @param integer $item
1564
	 *
1565
	 * @return array|boolean
1566
	 */
1567
	public function getItem($item)
1568
	{
1569
		return isset($this->items[$item]) ? $this->items[$item] : false;
1570
	}
1571
1572
}