Completed
Push — master ( 833fb7...fe914d )
by mw
04:21
created

onExtensionFunction()   C

Complexity

Conditions 12
Paths 130

Size

Total Lines 68

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 6.0715
c 0
b 0
f 0
cc 12
nc 130
nop 0

How to fix   Long Method    Complexity   

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 26 and the first side effect is on line 13.

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 SESP\HookRegistry;
4
5
/**
6
 * Extension SemanticExtraSpecialProperties - Adds some extra special properties to all pages.
7
 *
8
 * @see https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties
9
 *
10
 * @defgroup SemanticExtraSpecialProperties Semantic Extra Special Properties
11
 */
12
if ( !defined( 'MEDIAWIKI' ) ) {
13
	die( 'This file is part of the SemanticExtraSpecialProperties extension, it is not a valid entry point.' );
14
}
15
16
if ( defined( 'SESP_VERSION' ) ) {
17
	// Do not initialize more than once.
18
	return 1;
19
}
20
21
SemanticExtraSpecialProperties::load();
22
23
/**
24
 * @codeCoverageIgnore
25
 */
26
class SemanticExtraSpecialProperties {
27
28
	/**
29
	 * @since 1.4
30
	 *
31
	 * @note It is expected that this function is loaded before LocalSettings.php
32
	 * to ensure that settings and global functions are available by the time
33
	 * the extension is activated.
34
	 */
35
	public static function load() {
36
37
		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
38
			include_once __DIR__ . '/vendor/autoload.php';
39
		}
40
41
		foreach ( include __DIR__ . '/DefaultSettings.php' as $key => $value ) {
42
			if ( !isset( $GLOBALS[$key] ) ) {
43
				$GLOBALS[$key] = $value;
44
			}
45
		}
46
	}
47
48
	/**
49
	 * @since 1.4
50
	 */
51
	public static function initExtension( $credits = array() ) {
52
53
		// See https://phabricator.wikimedia.org/T151136
54
		define( 'SESP_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
55
56
		$GLOBALS['wgMessagesDirs']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n';
57
58
		// Register hooks that require to be listed as soon as possible and preferable
59
		// before the execution of onExtensionFunction
60
		HookRegistry::initExtension( $GLOBALS );
61
	}
62
63
	/**
64
	 * @since 1.4
65
	 */
66
	public static function onExtensionFunction() {
67
68
		if ( !defined( 'SMW_VERSION' ) ) {
69
			if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
70
				die( "\nThe 'Semantic Extra Special Properties' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
0 ignored issues
show
Coding Style Compatibility introduced by
The method onExtensionFunction() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
71
			} else {
72
				die( '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties/">Semantic Extra Special Properties</a> extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be installed and enabled.<br />' );
0 ignored issues
show
Coding Style Compatibility introduced by
The method onExtensionFunction() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
73
			}
74
		}
75
76
		// Cover legacy settings
77
		$deprecationNotices = [];
78
79
		if ( isset( $GLOBALS['sespUseAsFixedTables'] ) ) {
80
			$GLOBALS['sespgUseFixedTables'] = $GLOBALS['sespUseAsFixedTables'];
81
			$deprecationNotices['replacement']['sespUseAsFixedTables'] = 'sespgUseFixedTables';
82
		}
83
84
		if ( isset( $GLOBALS['sespPropertyDefinitionFile'] ) ) {
85
			$GLOBALS['sespgDefinitionsFile'] = $GLOBALS['sespPropertyDefinitionFile'];
86
			$deprecationNotices['replacement']['sespPropertyDefinitionFile'] = 'sespgDefinitionsFile';
87
		}
88
89
		if ( isset( $GLOBALS['sespLocalPropertyDefinitions'] ) ) {
90
			$GLOBALS['sespgLocalDefinitions'] = $GLOBALS['sespLocalPropertyDefinitions'];
91
			$deprecationNotices['replacement']['sespLocalPropertyDefinitions'] = 'sespgLocalDefinitions';
92
		}
93
94
		if ( isset( $GLOBALS['sespSpecialProperties'] ) ) {
95
			$GLOBALS['sespgEnabledPropertyList'] = $GLOBALS['sespSpecialProperties'];
96
			$deprecationNotices['replacement']['sespSpecialProperties'] = 'sespgEnabledPropertyList';
97
		}
98
99
		if ( isset( $GLOBALS['sespLabelCacheVersion'] ) ) {
100
			$GLOBALS['sespgLabelCacheVersion'] = $GLOBALS['sespLabelCacheVersion'];
101
			$deprecationNotices['replacement']['sespLabelCacheVersion'] = 'sespgLabelCacheVersion';
102
		}
103
104
		if ( isset( $GLOBALS['wgSESPExcludeBots'] ) ) {
105
			$GLOBALS['sespgExcludeBotEdits'] = $GLOBALS['wgSESPExcludeBots'];
106
			$deprecationNotices['replacement']['wgSESPExcludeBots'] = 'sespgExcludeBotEdits';
107
		}
108
109
		// Allow deprecated settings to appear on the `Special:SemanticMediaWiki`
110
		// "Deprecation notices" section
111
		if ( $deprecationNotices !== [] && !isset( $GLOBALS['smwgDeprecationNotices']['sesp'] ) ) {
112
			$GLOBALS['smwgDeprecationNotices']['sesp'] = [ 'replacement' => $deprecationNotices['replacement'] ];
113
		}
114
115
		$config = [
116
			'sespgUseFixedTables'      => $GLOBALS['sespgUseFixedTables'],
117
			'sespgEnabledPropertyList' => $GLOBALS['sespgEnabledPropertyList'],
118
			'sespgExcludeBotEdits'     => $GLOBALS['sespgExcludeBotEdits'],
119
			'sespgDefinitionsFile'     => $GLOBALS['sespgDefinitionsFile'],
120
			'sespgLocalDefinitions'    => $GLOBALS['sespgLocalDefinitions'],
121
			'sespgLabelCacheVersion'   => $GLOBALS['sespgLabelCacheVersion'],
122
123
			// Non-SESP settings
124
			'wgDisableCounters'        => $GLOBALS['wgDisableCounters'],
125
			'wgShortUrlPrefix'         => $GLOBALS['wgShortUrlPrefix'],
126
		];
127
128
		$hookRegistry = new HookRegistry(
129
			$config
130
		);
131
132
		$hookRegistry->register();
133
	}
134
135
	/**
136
	 * @since 1.4
137
	 *
138
	 * @return string|null
139
	 */
140
	public static function getVersion() {
141
142
		if ( !defined( 'SESP_VERSION' ) ) {
143
			return null;
144
		}
145
146
		return SESP_VERSION;
147
	}
148
149
}
150