DynamicGoogleMapSmarter::createMap()   B
last analyzed

Complexity

Conditions 5
Paths 1

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 8.439
c 0
b 0
f 0
cc 5
eloc 24
nc 1
nop 2
1
<?php
2
3
4
class DynamicGoogleMapSmarter extends Object
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
7
    /**
8
     * points are formatted like this:
9
     *  - points:[
10
     *      - id: ...
11
     *      - title: ....
12
     *      - address: ...
13
     *      - lat: ...
14
     *      - lng: ....
15
     *    ]
16
     * address OR lat / lng are optional (set lat / lng to zero to )
17
     *
18
     * @param  array $points
19
     * @param  string $markerCallback (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $markerCallback not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
20
     * @return this
0 ignored issues
show
Documentation introduced by
Should the return type not be DynamicGoogleMapSmarter?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
21
     */
22
    public function createMap($points, $markerCallback = null)
0 ignored issues
show
Unused Code introduced by
The parameter $markerCallback is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24
        $googleJS =
25
            "//maps.googleapis.com/maps/api/js"
26
            ."?v=".Config::inst()->get('GoogleMapSmarter', "api_version")
27
            ."&libraries=places"
28
            ."&key=".Config::inst()->get('GoogleMapSmarter', "api_key");
29
        Requirements::javascript($googleJS);
30
        Requirements::javascript('google_map_smarter/javascript/GoogleMapSmarter.js');
31
        $fx = $this->getMapVariable('markerCallbackFX', 'marker_callback_fx');
32
        $dLat = $this->getMapVariable('defaultLocationLat', 'default_location_lat');
33
        $dLng = $this->getMapVariable('defaultLocationLng', 'default_location_lng');
34
        Requirements::customScript('
35
                if(typeof GoogleMapSmarterOptions === "undefined") {
36
                    var GoogleMapSmarterOptions = [];
37
                }
38
                GoogleMapSmarterOptions.push({
39
                    id: "'.$this->getMapVariable('mapID', 'map_id').'",
40
                    iconIsRetinaSize:  '.($this->getMapVariable('iconIsRetinaSize', 'icon_is_retina_size') ? 1 : 0).',
41
                    iconURL:  "'.$this->getMapVariable('iconURL', 'icon_url').'",
42
                    iconWidth:  '.$this->getMapVariable('iconWidth', 'icon_width').',
43
                    iconHeight: '.$this->getMapVariable('iconHeight', 'icon_height').',
44
                    defaultZoom: '.$this->getMapVariable('defaultZoom', 'default_zoom').',
45
                    defaultLocation: {
46
                        lat: '.($dLat ? $dLat : 0).',
47
                        lng: '.($dLng ? $dLng : 0).'
48
                    },
49
                    points: '.json_encode($points).',
50
                    markerCallbackFX: '.($fx ? $fx : 'null').'
51
                });
52
            ',
53
            'CustomScript'.$this->getMapVariable('mapID', 'map_id')
54
        );
55
56
        return $this;
57
    }
58
59
    private static $map_id = 'google-map';
0 ignored issues
show
Unused Code introduced by
The property $map_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
60
61
    private static $icon_is_retina_size = true;
0 ignored issues
show
Unused Code introduced by
The property $icon_is_retina_size is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
62
63
    private static $icon_url = 'http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/map-marker-icon.png';
0 ignored issues
show
Unused Code introduced by
The property $icon_url is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
64
65
    private static $icon_width = 90;
0 ignored issues
show
Unused Code introduced by
The property $icon_width is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
66
67
    private static $icon_height = 90;
0 ignored issues
show
Unused Code introduced by
The property $icon_height is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
68
69
    private static $default_zoom = 7;
0 ignored issues
show
Unused Code introduced by
The property $default_zoom is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
70
71
    private static $default_location_lat = -45;
0 ignored issues
show
Unused Code introduced by
The property $default_location_lat is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
72
73
    private static $default_location_lng = 174;
0 ignored issues
show
Unused Code introduced by
The property $default_location_lng is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
74
75
    private static $marker_callback_fx = null;
0 ignored issues
show
Unused Code introduced by
The property $marker_callback_fx is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
76
77
    protected $mapID = null;
78
79
    protected $iconIsRetinaSize = null;
80
81
    protected $iconURL = null;
82
83
    protected $iconWidth = null;
84
85
    protected $iconHeight = null;
86
87
    protected $defaultZoom = null;
88
89
    protected $defaultLocationLat = null;
90
91
    protected $defaultLocationLng = null;
92
93
    protected $markerCallbackFx = null;
94
95
    public function setMapID($s)
96
    {
97
        return $this->setMapVariable('mapID', $s);
98
    }
99
100
    public function getMapID($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
    {
102
        return $this->getMapVariable('mapID', 'map_id');
103
    }
104
105
    public function setIconIsRetinaSize($s)
106
    {
107
        return $this->setMapVariable('iconIsRetinaSize',  $s);
108
    }
109
110
    public function getIconIsRetinaSize($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
    {
112
        return $this->getMapVariable('iconIsRetinaSize', 'icon_is_retina_size');
113
    }
114
115
116
    public function setIconURL($s)
117
    {
118
        return $this->setMapVariable('iconURL',  $s);
119
    }
120
121
    public function getIconURL($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
122
    {
123
        return $this->getMapVariable('iconURL', 'icon_url');
124
    }
125
126
    public function setIconWidth($s)
127
    {
128
        return $this->setMapVariable('iconWidth',  $s);
129
    }
130
131
    public function getIconWidth($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
132
    {
133
        return $this->getMapVariable('iconWidth', 'icon_width');
134
    }
135
136
    public function setIconHeight($s)
137
    {
138
        return $this->setMapVariable('iconHeight', $s);
139
    }
140
141
    public function getIconHeight($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
142
    {
143
        return $this->getMapVariable('iconHeight', 'icon_height');
144
    }
145
146
    public function setDefaultZOom($s)
147
    {
148
        return $this->setMapVariable('defaultZoom', $s);
149
    }
150
151
    public function getDefaultZoom($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
152
    {
153
        return $this->getMapVariable('defaultZoom', 'defaultZoom');
154
    }
155
156
    public function setDefaultLocationLat($s)
157
    {
158
        return $this->setMapVariable('defaultLocationLat', $s);
159
    }
160
161
    public function getDefaultLocationLat($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
162
    {
163
        return $this->getMapVariable('defaultLocationLat', 'defaultLocation_lat');
164
    }
165
166
    public function setDefaultLocationLng($s)
167
    {
168
        return $this->setMapVariable('defaultLocationLng', $s);
169
    }
170
171
    public function getDefaultLocationLng($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
172
    {
173
        return $this->getMapVariable('defaultLocationLng', 'defaultLocation_lng');
174
    }
175
176
    public function setMarkerCallbackFX($s)
177
    {
178
        return $this->setMapVariable('markerCallbackFX', $s);
179
    }
180
181
    public function getMarkerCallbackFX($s)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $s is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
182
    {
183
        return $this->getMapVariable('markerCallbackFX', 'marker_callback_fx');
184
    }
185
186
    /**
187
     *
188
     *
189
     * @param string $internalVariableName the variable name
190
     * @param string $staticVariableName   the static variable name
191
     *
192
     * @param return this
193
     */
194
    protected function getMapVariable($internalVariableName, $staticVariableName)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
195
    {
196
        if ($this->$internalVariableName !== null) {
197
            return $this->$internalVariableName;
198
        } else {
199
            return $this->Config()->$staticVariableName;
200
        }
201
    }
202
203
    /**
204
     *
205
     *
206
     * @param string $internalVariableName the variable name
207
     * @param mixed $s                     the variable to set
208
     *
209
     * @param return this
210
     */
211
    protected function setMapVariable($internalVariableName, $s)
212
    {
213
        $this->$internalVariableName = $s;
214
        return $this;
215
    }
216
}
217