Completed
Push — vishual ( da6cc4...124318 )
by Jeroen De
07:54
created

MapsRegistration::onRegistration()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 8.5123
c 0
b 0
f 0
cc 6
nc 2
nop 0
1
<?php
2
3
use Maps\MapsSetup;
4
5
class MapsRegistration {
6
7
	public static function onRegistration() {
0 ignored issues
show
Coding Style introduced by
onRegistration uses the super-global variable $GLOBALS which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
8
		if ( defined( 'Maps_COORDS_FLOAT' ) ) {
9
			// Do not initialize more than once.
10
			return true;
11
		}
12
13
		// The different coordinate notations.
14
		define( 'Maps_COORDS_FLOAT', 'float' );
15
		define( 'Maps_COORDS_DMS', 'dms' );
16
		define( 'Maps_COORDS_DM', 'dm' );
17
		define( 'Maps_COORDS_DD', 'dd' );
18
19
		require_once __DIR__ . '/Maps_Settings.php';
20
21
		// Internationalization
22
		$GLOBALS['wgMessagesDirs']['Maps.class'] = __DIR__ . '/i18n';
23
		$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
24
		$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';
25
26
		$GLOBALS['wgExtensionFunctions'][] = function() {
27
			if ( $GLOBALS['egMapsDisableExtension'] ) {
28
				return true;
29
			}
30
31
			if ( defined( 'Maps_VERSION' ) ) {
32
				// Do not initialize more than once.
33
				return true;
34
			}
35
36
			// Only initialize the extension when all dependencies are present.
37
			if ( !defined( 'Validator_VERSION' ) ) {
38
				throw new Exception( 'You need to have Validator installed in order to use Maps' );
39
			}
40
41
			if ( version_compare( $GLOBALS['wgVersion'], '1.27c', '<' ) ) {
42
				throw new Exception(
43
					'This version of Maps requires MediaWiki 1.27 or above; use Maps 4.2.x for older versions.'
44
					. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
45
				);
46
			}
47
48
			( new MapsSetup( $GLOBALS ) )->setup();
49
50
			return true;
51
		};
52
53
		return true;
54
	}
55
56
}
57
58
59
60