Completed
Push — master ( 328a9b...226cb1 )
by Bradley
04:33
created

MapperBase::setTilt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

class Id
{
    public $id;

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

}

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

$account_id = false;

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

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1296
	}
1297
1298
	/**
1299
	 * Get map heading.
1300
	 *
1301
	 * @return integer
1302
	 */
1303
	public function getHeading()
1304
	{
1305
		return $this->heading;
1306
	}
1307
1308
	/**
1309
	 * Set map tilt.
1310
	 *
1311
	 * @param integer|double $value
1312
	 *
1313
	 * @throws MapperArgumentException
1314
	 *
1315
	 * @return void
1316
	 */
1317
	public function setTilt($value)
1318
	{
1319
		if (!is_numeric($value)) {
1320
			throw new MapperArgumentException('Invalid map tilt.');
1321
		}
1322
1323
		$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...
1324
	}
1325
1326
	/**
1327
	 * Get map tilt.
1328
	 *
1329
	 * @return integer
1330
	 */
1331
	public function getTilt()
1332
	{
1333
		return $this->tilt;
1334
	}
1335
1336
	/**
1337
	 * Set map marker icon.
1338
	 *
1339
	 * @param string $value
1340
	 *
1341
	 * @throws MapperArgumentException
1342
	 *
1343
	 * @return void
1344
	 */
1345
	public function setIcon($value)
1346
	{
1347
		if (!is_string($value)) {
1348
			throw new MapperArgumentException('Invalid map marker icon.');
1349
		}
1350
1351
		$this->icon = $value;
1352
	}
1353
1354
	/**
1355
	 * Get map marker icon.
1356
	 *
1357
	 * @return string
1358
	 */
1359
	public function getIcon()
1360
	{
1361
		return $this->icon;
1362
	}
1363
1364
	/**
1365
	 * Set map marker animation.
1366
	 *
1367
	 * @param string $value
1368
	 *
1369
	 * @throws MapperArgumentException
1370
	 *
1371
	 * @return void
1372
	 */
1373
	public function setAnimation($value)
1374
	{
1375
		if (!in_array($value, $this->animations)) {
1376
			throw new MapperArgumentException('Invalid map marker animation.');
1377
		}
1378
1379
		$this->animation = $value;
1380
	}
1381
1382
	/**
1383
	 * Get map marker animation.
1384
	 *
1385
	 * @return string
1386
	 */
1387
	public function getAnimation()
1388
	{
1389
		return $this->animation;
1390
	}
1391
1392
	/**
1393
	 * Set cluster status.
1394
	 *
1395
	 * @param boolean $value
1396
	 *
1397
	 * @throws MapperArgumentException
1398
	 *
1399
	 * @return void
1400
	 */
1401
	protected function setCluster($value)
1402
	{
1403
		if (!is_bool($value)) {
1404
			throw new MapperArgumentException('Invalid map cluster setting.');
1405
		}
1406
1407
		$this->cluster = $value;
1408
	}
1409
1410
	/**
1411
	 * Get the cluster status.
1412
	 *
1413
	 * @return boolean
1414
	 */
1415
	public function getCluster()
1416
	{
1417
		return $this->cluster;
1418
	}
1419
1420
	/**
1421
	 * Enable cluster.
1422
	 *
1423
	 * @return void
1424
	 */
1425
	public function enableCluster()
1426
	{
1427
		$this->setCluster(true);
1428
	}
1429
1430
	/**
1431
	 * Disable cluster.
1432
	 *
1433
	 * @return void
1434
	 */
1435
	public function disableCluster()
1436
	{
1437
		$this->setCluster(false);
1438
	}
1439
1440
	/**
1441
	 * Set map cluster icon.
1442
	 *
1443
	 * @param string $value
1444
	 *
1445
	 * @throws MapperArgumentException
1446
	 *
1447
	 * @return void
1448
	 */
1449
	public function setClustersIcon($value)
1450
	{
1451
		if (!is_string($value)) {
1452
			throw new MapperArgumentException('Invalid map clusters icon setting.');
1453
		}
1454
1455
		$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...
1456
	}
1457
1458
	/**
1459
	 * Get map clusters icon.
1460
	 *
1461
	 * @return string
1462
	 */
1463
	public function getClustersIcon()
1464
	{
1465
		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...
1466
	}
1467
1468
	/**
1469
	 * Set map cluster grid.
1470
	 *
1471
	 * @param integer $value
1472
	 *
1473
	 * @throws MapperArgumentException
1474
	 *
1475
	 * @return void
1476
	 */
1477
	public function setClustersGrid($value)
1478
	{
1479
		if (!is_integer($value)) {
1480
			throw new MapperArgumentException('Invalid map clusters grid setting.');
1481
		}
1482
1483
		$this->clustersGrid = $value;
1484
	}
1485
1486
	/**
1487
	 * Get map cluster grid.
1488
	 *
1489
	 * @return integer
1490
	 */
1491
	public function getClustersGrid()
1492
	{
1493
		return $this->clustersGrid;
1494
	}
1495
1496
	/**
1497
	 * Set map cluster zoom.
1498
	 *
1499
	 * @param integer|null $value
1500
	 *
1501
	 * @throws MapperArgumentException
1502
	 *
1503
	 * @return void
1504
	 */
1505
	public function setClustersZoom($value)
1506
	{
1507
		if (!is_integer($value) && !is_null($value)) {
1508
			throw new MapperArgumentException('Invalid map clusters zoom setting.');
1509
		}
1510
1511
		$this->clustersZoom = $value;
1512
	}
1513
1514
	/**
1515
	 * Get map cluster grid.
1516
	 *
1517
	 * @return integer|null
1518
	 */
1519
	public function getClustersZoom()
1520
	{
1521
		return $this->clustersZoom;
1522
	}
1523
1524
	/**
1525
	 * Set map cluster center.
1526
	 *
1527
	 * @param boolean $value
1528
	 *
1529
	 * @throws MapperArgumentException
1530
	 *
1531
	 * @return void
1532
	 */
1533
	public function setClustersCenter($value)
1534
	{
1535
		if (!is_bool($value)) {
1536
			throw new MapperArgumentException('Invalid map clusters center setting.');
1537
		}
1538
1539
		$this->clustersCenter = $value;
1540
	}
1541
1542
	/**
1543
	 * Get map cluster center.
1544
	 *
1545
	 * @return boolean
1546
	 */
1547
	public function getClustersCenter()
1548
	{
1549
		return $this->clustersCenter;
1550
	}
1551
1552
	/**
1553
	 * Set map cluster size.
1554
	 *
1555
	 * @param integer $value
1556
	 *
1557
	 * @throws MapperArgumentException
1558
	 *
1559
	 * @return void
1560
	 */
1561
	public function setClustersSize($value)
1562
	{
1563
		if (!is_integer($value)) {
1564
			throw new MapperArgumentException('Invalid map clusters size setting.');
1565
		}
1566
1567
		$this->clustersSize = $value;
1568
	}
1569
1570
	/**
1571
	 * Get map cluster size.
1572
	 *
1573
	 * @return integer
1574
	 */
1575
	public function getClustersSize()
1576
	{
1577
		return $this->clustersSize;
1578
	}
1579
1580
	/**
1581
	 * Get mapper options.
1582
	 *
1583
	 * @return array
1584
	 */
1585
	protected function getOptions()
1586
	{
1587
		return [
1588
			'key' => $this->getKey(),
1589
			'version' => $this->version,
1590
			'region' => $this->getRegion(),
1591
			'language' => $this->getLanguage(),
1592
			'async' => $this->getAsync(),
1593
			'user' => $this->getUser(),
1594
			'marker' => $this->getMarker(),
1595
			'center' => $this->getCenter(),
1596
			'locate' => $this->getLocate(),
1597
			'zoom' => $this->getZoom(),
1598
			'scrollWheelZoom' => $this->getScrollWheelZoom(),
1599
			'fullscreenControl' => $this->getFullscreenControl(),
1600
			'type' => $this->getType(),
1601
			'heading' => $this->getHeading(),
1602
			'tilt' => $this->getTilt(),
1603
			'ui' => $this->getUi(),
1604
			'overlay' => '',
1605
			'markers' => [
1606
				'title' => '',
1607
				'content' => '',
1608
				'icon' => $this->getIcon(),
1609
				'place' => '',
1610
				'animation' => $this->getAnimation(),
1611
				'symbol' => '',
1612
			],
1613
			'cluster' => $this->getCluster(),
1614
			'clusters' => [
1615
				'icon' => $this->getClustersIcon(),
1616
				'grid' => $this->getClustersGrid(),
1617
				'zoom' => $this->getClustersZoom(),
1618
				'center' => $this->getClustersCenter(),
1619
				'size' => $this->getClustersSize()
1620
			],
1621
		];
1622
	}
1623
1624
	/**
1625
	 * Add mapping item.
1626
	 *
1627
	 * @param object $value
1628
	 *
1629
	 * @return void
1630
	 */
1631
	protected function addItem($value)
1632
	{
1633
		$this->items[] = $value;
1634
	}
1635
1636
	/**
1637
	 * Set mapping items.
1638
	 *
1639
	 * @param array $array
1640
	 *
1641
	 * @return void
1642
	 */
1643
	protected function setItems(array $array)
1644
	{
1645
		$this->items = $array;
1646
	}
1647
1648
	/**
1649
	 * Get the mapping items.
1650
	 *
1651
	 * @return array
1652
	 */
1653
	public function getItems()
1654
	{
1655
		return $this->items;
1656
	}
1657
1658
	/**
1659
	 * Get a mapping item by reference.
1660
	 *
1661
	 * @param integer $item
1662
	 *
1663
	 * @return array|boolean
1664
	 */
1665
	public function getItem($item)
1666
	{
1667
		return isset($this->items[$item]) ? $this->items[$item] : false;
1668
	}
1669
1670
}