Completed
Push — master ( e11051...f173c0 )
by mw
10s
created

SummaryCards::initExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 75
rs 9
cc 1
eloc 51
nc 1
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 33 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use SUC\HookRegistry;
4
use SUC\Options;
5
6
/**
7
 * @see https://github.com/SemanticMediaWiki/SummaryCards/
8
 *
9
 * @defgroup SummaryCards Summary Cards
10
 */
11
if ( !defined( 'MEDIAWIKI' ) ) {
12
	die( 'This file is part of the SummaryCards extension, it is not a valid entry point.' );
13
}
14
15
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.24', 'lt' ) ) {
16
	die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SummaryCards/">SummaryCards</a> is only compatible with MediaWiki 1.24 or above. You need to upgrade MediaWiki first.' );
17
}
18
19
if ( defined( 'SUC_VERSION' ) ) {
20
	// Do not initialize more than once.
21
	return 1;
22
}
23
24
SummaryCards::initExtension();
25
26
$GLOBALS['wgExtensionFunctions'][] = function() {
27
	SummaryCards::onExtensionFunction();
28
};
29
30
/**
31
 * @codeCoverageIgnore
32
 */
33
class SummaryCards {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
34
35
	/**
36
	 * @since 1.0
37
	 */
38
	public static function initExtension() {
0 ignored issues
show
Coding Style introduced by
initExtension 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...
39
40
		// Load DefaultSettings
41
		require_once __DIR__ . '/DefaultSettings.php';
42
43
		define( 'SUC_VERSION', '1.0.0-alpha' );
44
45
		// Register the extension
46
		$GLOBALS['wgExtensionCredits']['others'][ ] = array(
47
			'path'           => __DIR__,
48
			'name'           => 'Summary Cards',
49
			'author'         => array(
50
				'James Hong Kong'
51
			),
52
			'url'            => 'https://github.com/SemanticMediaWiki/SummaryCards/',
53
			'descriptionmsg' => 'suc-desc',
54
			'version'        => SUC_VERSION,
55
			'license-name'   => 'GPL-2.0+',
56
		);
57
58
		// Register message files
59
		$GLOBALS['wgMessagesDirs']['SummaryCards'] = __DIR__ . '/i18n';
60
61
		$GLOBALS['wgAPIModules']['ctparse'] = '\SUC\ApiCacheableTemplateParse';
62
63
		$GLOBALS['wgResourceModules']['ext.summary.cards.styles'] = array(
64
			'styles'  => 'res/ext.suc.styles.css',
65
			'localBasePath' => __DIR__ ,
66
			'remoteExtPath' => 'SummaryCards',
67
			'position' => 'top',
68
			'targets' => array(
69
				'mobile',
70
				'desktop'
71
			)
72
		);
73
74
		$GLOBALS['wgResourceModules']['ext.summary.cards.tooltip'] = array(
75
			'localBasePath' => __DIR__ ,
76
			'remoteExtPath' => 'SummaryCards',
77
			'position' => 'bottom',
78
			'dependencies'  => array(
79
				'onoi.qtip',
80
				'onoi.md5',
81
				'onoi.blobstore',
82
				'onoi.util'
83
			),
84
			'targets' => array(
85
				'mobile',
86
				'desktop'
87
			)
88
		);
89
90
		$GLOBALS['wgResourceModules']['ext.summary.cards'] = array(
91
			'scripts' => array(
92
				'res/ext.suc.cards.js'
93
			),
94
			'localBasePath' => __DIR__ ,
95
			'remoteExtPath' => 'SummaryCards',
96
			'position' => 'bottom',
97
			'dependencies'  => array(
98
				'mediawiki.api',
99
				'mediawiki.api.parse',
100
				'ext.summary.cards.styles',
101
				'ext.summary.cards.tooltip',
102
			),
103
			'messages' => array(
104
				'suc-tooltip-title',
105
				'suc-tooltip-error'
106
			),
107
			'targets' => array(
108
				'mobile',
109
				'desktop'
110
			)
111
		);
112
	}
113
114
	/**
115
	 * @since 1.0
116
	 */
117
	public static function onExtensionFunction() {
118
119
		$hookRegistry = new HookRegistry(
120
			Options::newFromGlobals()
121
		);
122
123
		$hookRegistry->register();
124
	}
125
126
	/**
127
	 * @since 1.0
128
	 *
129
	 * @return string|null
130
	 */
131
	public static function getVersion() {
132
		return SUC_VERSION;
133
	}
134
135
}
136