Conditions | 10 |
Paths | 27 |
Total Lines | 56 |
Code Lines | 31 |
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 | if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) { |
||
89 | SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension(); |
||
90 | } |
||
91 | |||
92 | return true; |
||
93 | } |
||
94 | |||
177 |
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: