Conditions | 2 |
Paths | 1 |
Total Lines | 190 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
50 | public function addParameterInfo( array &$params ) { |
||
|
|||
51 | global $egMapsGMaps3Type, $egMapsGMaps3Types, $egMapsGMaps3Controls, $egMapsGMaps3Layers; |
||
52 | global $egMapsGMaps3DefTypeStyle, $egMapsGMaps3DefZoomStyle, $egMapsGMaps3AutoInfoWindows; |
||
53 | global $egMapsResizableByDefault, $egMapsGMaps3DefaultTilt; |
||
54 | |||
55 | $params['zoom'] = [ |
||
56 | 'type' => 'integer', |
||
57 | 'range' => [ 0, 20 ], |
||
58 | 'default' => self::getDefaultZoom(), |
||
59 | 'message' => 'maps-par-zoom', |
||
60 | ]; |
||
61 | |||
62 | $params['type'] = [ |
||
63 | 'default' => $egMapsGMaps3Type, |
||
64 | 'values' => self::getTypeNames(), |
||
65 | 'message' => 'maps-googlemaps3-par-type', |
||
66 | 'post-format' => function ( $value ) { |
||
67 | return GoogleMapsService::$mapTypes[strtolower( $value )]; |
||
68 | }, |
||
69 | ]; |
||
70 | |||
71 | $params['types'] = [ |
||
72 | 'dependencies' => 'type', |
||
73 | 'default' => $egMapsGMaps3Types, |
||
74 | 'values' => self::getTypeNames(), |
||
75 | 'message' => 'maps-googlemaps3-par-types', |
||
76 | 'islist' => true, |
||
77 | 'post-format' => function ( array $value ) { |
||
78 | foreach ( $value as &$part ) { |
||
79 | $part = self::$mapTypes[strtolower( $part )]; |
||
80 | } |
||
81 | |||
82 | return $value; |
||
83 | }, |
||
84 | ]; |
||
85 | |||
86 | $params['layers'] = [ |
||
87 | 'default' => $egMapsGMaps3Layers, |
||
88 | 'values' => [ |
||
89 | 'traffic', |
||
90 | 'bicycling' |
||
91 | ], |
||
92 | 'message' => 'maps-googlemaps3-par-layers', |
||
93 | 'islist' => true, |
||
94 | ]; |
||
95 | |||
96 | $params['controls'] = [ |
||
97 | 'default' => $egMapsGMaps3Controls, |
||
98 | 'values' => [ |
||
99 | 'pan', |
||
100 | 'zoom', |
||
101 | 'type', |
||
102 | 'scale', |
||
103 | 'streetview', |
||
104 | 'rotate' |
||
105 | ], |
||
106 | 'message' => 'maps-googlemaps3-par-controls', |
||
107 | 'islist' => true, |
||
108 | 'post-format' => function ( $value ) { |
||
109 | return array_map( 'strtolower', $value ); |
||
110 | }, |
||
111 | ]; |
||
112 | |||
113 | $params['zoomstyle'] = [ |
||
114 | 'default' => $egMapsGMaps3DefZoomStyle, |
||
115 | 'values' => [ 'default', 'small', 'large' ], |
||
116 | 'message' => 'maps-googlemaps3-par-zoomstyle', |
||
117 | 'post-format' => 'strtoupper', |
||
118 | ]; |
||
119 | |||
120 | $params['typestyle'] = [ |
||
121 | 'default' => $egMapsGMaps3DefTypeStyle, |
||
122 | 'values' => array_keys( self::$typeControlStyles ), |
||
123 | 'message' => 'maps-googlemaps3-par-typestyle', |
||
124 | 'post-format' => function ( $value ) { |
||
125 | return self::$typeControlStyles[strtolower( $value )]; |
||
126 | }, |
||
127 | ]; |
||
128 | |||
129 | $params['autoinfowindows'] = [ |
||
130 | 'type' => 'boolean', |
||
131 | 'default' => $egMapsGMaps3AutoInfoWindows, |
||
132 | 'message' => 'maps-googlemaps3-par-autoinfowindows', |
||
133 | ]; |
||
134 | |||
135 | $params['resizable'] = [ |
||
136 | 'type' => 'boolean', |
||
137 | 'default' => $egMapsResizableByDefault, |
||
138 | 'message' => 'maps-par-resizable', |
||
139 | ]; |
||
140 | |||
141 | $params['kmlrezoom'] = [ |
||
142 | 'type' => 'boolean', |
||
143 | 'default' => $GLOBALS['egMapsRezoomForKML'], |
||
144 | 'message' => 'maps-googlemaps3-par-kmlrezoom', |
||
145 | ]; |
||
146 | |||
147 | $params['poi'] = [ |
||
148 | 'type' => 'boolean', |
||
149 | 'default' => $GLOBALS['egMapsShowPOI'], |
||
150 | 'message' => 'maps-googlemaps3-par-poi', |
||
151 | ]; |
||
152 | |||
153 | $params['markercluster'] = [ |
||
154 | 'type' => 'boolean', |
||
155 | 'default' => false, |
||
156 | 'message' => 'maps-par-markercluster', |
||
157 | ]; |
||
158 | |||
159 | $params['clustergridsize'] = [ |
||
160 | 'type' => 'integer', |
||
161 | 'default' => 60, |
||
162 | 'message' => 'maps-googlemaps3-par-clustergridsize', |
||
163 | ]; |
||
164 | |||
165 | $params['clustermaxzoom'] = [ |
||
166 | 'type' => 'integer', |
||
167 | 'default' => 20, |
||
168 | 'message' => 'maps-par-clustermaxzoom', |
||
169 | ]; |
||
170 | |||
171 | $params['clusterzoomonclick'] = [ |
||
172 | 'type' => 'boolean', |
||
173 | 'default' => true, |
||
174 | 'message' => 'maps-par-clusterzoomonclick', |
||
175 | ]; |
||
176 | |||
177 | $params['clusteraveragecenter'] = [ |
||
178 | 'type' => 'boolean', |
||
179 | 'default' => true, |
||
180 | 'message' => 'maps-googlemaps3-par-clusteraveragecenter', |
||
181 | ]; |
||
182 | |||
183 | $params['clusterminsize'] = [ |
||
184 | 'type' => 'integer', |
||
185 | 'default' => 2, |
||
186 | 'message' => 'maps-googlemaps3-par-clusterminsize', |
||
187 | ]; |
||
188 | |||
189 | $params['tilt'] = [ |
||
190 | 'type' => 'integer', |
||
191 | 'default' => $egMapsGMaps3DefaultTilt, |
||
192 | 'message' => 'maps-googlemaps3-par-tilt', |
||
193 | ]; |
||
194 | |||
195 | $params['imageoverlays'] = [ |
||
196 | 'type' => 'mapsimageoverlay', |
||
197 | 'default' => [], |
||
198 | 'delimiter' => ';', |
||
199 | 'islist' => true, |
||
200 | 'message' => 'maps-googlemaps3-par-imageoverlays', |
||
201 | ]; |
||
202 | |||
203 | $params['kml'] = [ |
||
204 | 'default' => [], |
||
205 | 'message' => 'maps-par-kml', |
||
206 | 'islist' => true, |
||
207 | // new MapsParamFile() FIXME |
||
208 | ]; |
||
209 | |||
210 | $params['gkml'] = [ |
||
211 | 'default' => [], |
||
212 | 'message' => 'maps-googlemaps3-par-gkml', |
||
213 | 'islist' => true, |
||
214 | ]; |
||
215 | |||
216 | $params['fusiontables'] = [ |
||
217 | 'default' => [], |
||
218 | 'message' => 'maps-googlemaps3-par-fusiontables', |
||
219 | 'islist' => true, |
||
220 | ]; |
||
221 | |||
222 | $params['searchmarkers'] = [ |
||
223 | 'default' => '', |
||
224 | 'message' => 'maps-par-searchmarkers', |
||
225 | // new CriterionSearchMarkers() FIXME |
||
226 | ]; |
||
227 | |||
228 | $params['enablefullscreen'] = [ |
||
229 | 'type' => 'boolean', |
||
230 | 'default' => false, |
||
231 | 'message' => 'maps-par-enable-fullscreen', |
||
232 | ]; |
||
233 | |||
234 | $params['scrollwheelzoom'] = [ |
||
235 | 'type' => 'boolean', |
||
236 | 'default' => false, |
||
237 | 'message' => 'maps-par-scrollwheelzoom', |
||
238 | ]; |
||
239 | } |
||
240 | |||
339 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: