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