Completed
Push — master ( 4b982e...a5f2e8 )
by Jeroen De
03:02
created

MapsRegistration.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use Maps\MapsSetup;
4
5
class MapsRegistration {
6
7
	public static function onRegistration( array $credits ) {
0 ignored issues
show
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_VERSION' ) ) {
9
			// Do not initialize more than once.
10
			return true;
11
		}
12
13
		if ( !defined( 'Maps_SETTINGS_LOADED' ) ) {
14
			require_once __DIR__ . '/Maps_Settings.php';
15
		}
16
17
		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
18
			include_once( __DIR__ . '/vendor/autoload.php' );
19
		}
20
21
		define( 'Maps_VERSION', $credits['version'] );
22
		define( 'SM_VERSION', Maps_VERSION );
23
24
		if ( !(bool)'Defining PHP constants in JSON is a bad idea and breaks tools' ) {
25
			define( 'NS_GEO_JSON', 420 );
26
			define( 'NS_GEO_JSON_TALK', 421 );
27
		}
28
29
		$GLOBALS['wgExtensionFunctions'][] = function() {
30
			if ( $GLOBALS['egMapsDisableExtension'] ) {
31
				return true;
32
			}
33
34
			// Only initialize the extension when all dependencies are present.
35
			if ( !defined( 'Validator_VERSION' ) ) {
36
				throw new Exception( 'You need to have Validator installed in order to use Maps' );
37
			}
38
39
			if ( version_compare( $GLOBALS['wgVersion'], '1.27c', '<' ) ) {
40
				throw new Exception(
41
					'This version of Maps requires MediaWiki 1.27 or above; use Maps 4.2.x for older versions.'
42
					. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
43
				);
44
			}
45
46
			( new MapsSetup( $GLOBALS ) )->setup();
47
48
			return true;
49
		};
50
51
		return true;
52
	}
53
54
}
55
56
57
58