| Conditions | 10 |
| Paths | 27 |
| Total Lines | 96 |
| Code Lines | 51 |
| 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 |
||
| 49 | public static function onExtensionFunction() { |
||
| 50 | if ( $GLOBALS['egMapsDisableExtension'] ) { |
||
| 51 | return true; |
||
| 52 | } |
||
| 53 | if ( defined( 'Maps_VERSION' ) ) { |
||
| 54 | // Do not initialize more than once. |
||
| 55 | return true; |
||
| 56 | } |
||
| 57 | |||
| 58 | // Only initialize the extension when all dependencies are present. |
||
| 59 | if ( !defined( 'Validator_VERSION' ) ) { |
||
| 60 | throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
||
| 61 | } |
||
| 62 | |||
| 63 | define( 'Maps_VERSION' , '4.2.1' ); |
||
| 64 | define( 'SM_VERSION', Maps_VERSION ); |
||
| 65 | |||
| 66 | if ( $GLOBALS['egMapsGMaps3Language'] === '' ) { |
||
| 67 | $GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang']; |
||
| 68 | } |
||
| 69 | |||
| 70 | MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class ); |
||
| 71 | |||
| 72 | $googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' ); |
||
| 73 | $googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
||
| 74 | |||
| 75 | MapsMappingServices::registerService( |
||
| 76 | 'openlayers', |
||
| 77 | MapsOpenLayers::class, |
||
| 78 | [ 'display_map' => MapsDisplayMapRenderer::class ] |
||
| 79 | ); |
||
| 80 | |||
| 81 | MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class ); |
||
| 82 | $leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' ); |
||
| 83 | $leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
||
| 84 | |||
| 85 | if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) { |
||
| 86 | $GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor'; |
||
| 87 | $GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps'; |
||
| 88 | } |
||
| 89 | |||
| 90 | $GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION; |
||
| 91 | |||
| 92 | // Users that can geocode. By default the same as those that can edit. |
||
| 93 | foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) { |
||
| 94 | if ( array_key_exists( 'edit' , $rights ) ) { |
||
| 95 | $GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit']; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | $GLOBALS['wgParamDefinitions']['coordinate'] = [ |
||
| 100 | 'string-parser' => GeoCoordinateParser::class, |
||
| 101 | ]; |
||
| 102 | |||
| 103 | $GLOBALS['wgParamDefinitions']['mappingservice'] = [ |
||
| 104 | 'definition'=> ServiceParam::class, |
||
| 105 | ]; |
||
| 106 | |||
| 107 | $GLOBALS['wgParamDefinitions']['mapslocation'] = [ |
||
| 108 | 'string-parser' => LocationParser::class, |
||
| 109 | ]; |
||
| 110 | |||
| 111 | $GLOBALS['wgParamDefinitions']['mapsline'] = [ |
||
| 112 | 'string-parser' => LineParser::class, |
||
| 113 | ]; |
||
| 114 | |||
| 115 | $GLOBALS['wgParamDefinitions']['mapscircle'] = [ |
||
| 116 | 'string-parser' => CircleParser::class, |
||
| 117 | ]; |
||
| 118 | |||
| 119 | $GLOBALS['wgParamDefinitions']['mapsrectangle'] = [ |
||
| 120 | 'string-parser' => RectangleParser::class, |
||
| 121 | ]; |
||
| 122 | |||
| 123 | $GLOBALS['wgParamDefinitions']['mapspolygon'] = [ |
||
| 124 | 'string-parser' => PolygonParser::class, |
||
| 125 | ]; |
||
| 126 | |||
| 127 | $GLOBALS['wgParamDefinitions']['distance'] = [ |
||
| 128 | 'string-parser' => DistanceParser::class, |
||
| 129 | ]; |
||
| 130 | |||
| 131 | $GLOBALS['wgParamDefinitions']['wmsoverlay'] = [ |
||
| 132 | 'string-parser' => WmsOverlayParser::class, |
||
| 133 | ]; |
||
| 134 | |||
| 135 | $GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [ |
||
| 136 | 'string-parser' => ImageOverlayParser::class, |
||
| 137 | ]; |
||
| 138 | |||
| 139 | if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) { |
||
| 140 | SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension(); |
||
| 141 | } |
||
| 142 | |||
| 143 | return true; |
||
| 144 | } |
||
| 145 | |||
| 228 |
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: