Conditions | 20 |
Paths | 38 |
Total Lines | 101 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
189 | public static function evilOpenLayersHack( $layers ) { |
||
190 | global $egMapsOLLayerGroups, $egMapsOLAvailableLayers; |
||
191 | |||
192 | $layerDefs = []; |
||
193 | $layerNames = []; |
||
194 | |||
195 | foreach ( $layers as $layerOrGroup ) { |
||
196 | $lcLayerOrGroup = strtolower( $layerOrGroup ); |
||
197 | |||
198 | // Layer groups. Loop over all items and add them if not present yet: |
||
199 | if ( array_key_exists( $lcLayerOrGroup, $egMapsOLLayerGroups ) ) { |
||
200 | foreach ( $egMapsOLLayerGroups[$lcLayerOrGroup] as $layerName ) { |
||
201 | if ( !in_array( $layerName, $layerNames ) ) { |
||
202 | if ( is_array( $egMapsOLAvailableLayers[$layerName] ) ) { |
||
203 | $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$layerName][0]; |
||
204 | } |
||
205 | else { |
||
206 | $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$layerName]; |
||
207 | } |
||
208 | $layerNames[] = $layerName; |
||
209 | } |
||
210 | } |
||
211 | } |
||
212 | // Single layers. Add them if not present yet: |
||
213 | elseif ( array_key_exists( $lcLayerOrGroup, $egMapsOLAvailableLayers ) ) { |
||
214 | if ( !in_array( $lcLayerOrGroup, $layerNames ) ) { |
||
215 | if ( is_array( $egMapsOLAvailableLayers[$lcLayerOrGroup] ) ) { |
||
216 | $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$lcLayerOrGroup][0]; |
||
217 | } |
||
218 | else { |
||
219 | $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$lcLayerOrGroup]; |
||
220 | } |
||
221 | |||
222 | $layerNames[] = $lcLayerOrGroup; |
||
223 | } |
||
224 | } |
||
225 | // Image layers. Check validity and add if not present yet: |
||
226 | else { |
||
227 | $layerParts = explode( ';', $layerOrGroup, 2 ); |
||
228 | $layerGroup = $layerParts[0]; |
||
229 | $layerName = count( $layerParts ) > 1 ? $layerParts[1] : null; |
||
230 | |||
231 | $title = Title::newFromText( $layerGroup, Maps_NS_LAYER ); |
||
232 | |||
233 | if ( $title !== null && $title->getNamespace() == Maps_NS_LAYER ) { |
||
234 | // TODO: FIXME: This shouldn't be here and using $wgParser, instead it should |
||
235 | // be somewhere around MapsBaseMap::renderMap. But since we do a lot more than |
||
236 | // 'parameter manipulation' in here, we already diminish the information needed |
||
237 | // for this which will never arrive there. |
||
238 | global $wgParser; |
||
239 | // add dependency to the layer page so if the layer definition gets updated, |
||
240 | // the page where it is used will be updated as well: |
||
241 | $rev = Revision::newFromTitle( $title ); |
||
242 | $revId = null; |
||
243 | if( $rev !== null ) { |
||
244 | $revId = $rev->getId(); |
||
245 | } |
||
246 | $wgParser->getOutput()->addTemplate( $title, $title->getArticleID(), $revId ); |
||
247 | |||
248 | // if the whole layer group is not yet loaded into the map and the group exists: |
||
249 | if( !in_array( $layerGroup, $layerNames ) |
||
250 | && $title->exists() |
||
251 | ) { |
||
252 | if( $layerName !== null ) { |
||
253 | // load specific layer with name: |
||
254 | $layer = MapsLayers::loadLayer( $title, $layerName ); |
||
255 | $layers = new MapsLayerGroup( $layer ); |
||
256 | $usedLayer = $layerOrGroup; |
||
257 | } |
||
258 | else { |
||
259 | // load all layers from group: |
||
260 | $layers = MapsLayers::loadLayerGroup( $title ); |
||
261 | $usedLayer = $layerGroup; |
||
262 | } |
||
263 | |||
264 | foreach( $layers->getLayers() as $layer ) { |
||
265 | if( ( // make sure named layer is only taken once (in case it was requested on its own before) |
||
266 | $layer->getName() === null |
||
267 | || !in_array( $layerGroup . ';' . $layer->getName(), $layerNames ) |
||
268 | ) |
||
269 | && $layer->isOk() |
||
270 | ) { |
||
271 | $layerDefs[] = $layer->getJavaScriptDefinition(); |
||
272 | } |
||
273 | } |
||
274 | |||
275 | $layerNames[] = $usedLayer; // have to add this after loop of course! |
||
276 | } |
||
277 | } |
||
278 | else { |
||
279 | wfWarn( "Invalid layer ($layerOrGroup) encountered after validation." ); |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | |||
284 | MapsMappingServices::getServiceInstance( 'openlayers' )->addLayerDependencies( self::getLayerDependencies( $layerNames ) ); |
||
285 | |||
286 | // print_r( $layerDefs ); |
||
287 | // die(); |
||
288 | return $layerDefs; |
||
289 | } |
||
290 | |||
313 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.