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 SMW\Scribunto\HookRegistry; |
||
4 | |||
5 | /** |
||
6 | * @see https://github.com/SemanticMediaWiki/SemanticScribunto/ |
||
7 | * |
||
8 | * @defgroup SemanticScribunto Semantic Scribunto |
||
9 | */ |
||
10 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
11 | die( 'This file is part of the Semantic Scribunto extension, it is not a valid entry point.' ); |
||
12 | } |
||
13 | |||
14 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.26', 'lt' ) ) { |
||
15 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticScribunto/">Semantic Scribunto</a> is only compatible with MediaWiki 1.26 or above. You need to upgrade MediaWiki first.' ); |
||
16 | } |
||
17 | |||
18 | if ( defined( 'SMW_SCRIBUNTO_VERSION' ) ) { |
||
19 | // Do not initialize more than once. |
||
20 | return 1; |
||
21 | } |
||
22 | |||
23 | define( 'SMW_SCRIBUNTO_VERSION', '1.0.0-alpha' ); |
||
24 | |||
25 | SemanticScribunto::initExtension(); |
||
26 | |||
27 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
28 | SemanticScribunto::onExtensionFunction(); |
||
29 | }; |
||
30 | |||
31 | /** |
||
32 | * @codeCoverageIgnore |
||
33 | */ |
||
34 | class SemanticScribunto { |
||
0 ignored issues
–
show
|
|||
35 | |||
36 | /** |
||
37 | * @since 1.0 |
||
38 | */ |
||
39 | public static function initExtension() { |
||
0 ignored issues
–
show
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);
}
}
![]() |
|||
40 | |||
41 | // Register extension info |
||
42 | $GLOBALS['wgExtensionCredits']['semantic'][] = array( |
||
43 | 'path' => __FILE__, |
||
44 | 'name' => 'Semantic Scribunto', |
||
45 | 'author' => array( 'James Hong Kong' ), |
||
46 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticScribunto/', |
||
47 | 'descriptionmsg' => 'smw-scribunto-desc', |
||
48 | 'version' => SMW_SCRIBUNTO_VERSION, |
||
49 | 'license-name' => 'GPL-2.0+', |
||
50 | ); |
||
51 | |||
52 | // MW 1.26+ |
||
53 | if ( !function_exists( 'wfGlobalCacheKey' ) ) { |
||
54 | function wfGlobalCacheKey( /*...*/ ) { |
||
0 ignored issues
–
show
|
|||
55 | $args = func_get_args(); |
||
56 | $key = 'global:' . implode( ':', $args ); |
||
57 | return strtr( $key, ' ', '_' ); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | // Register message files |
||
62 | $GLOBALS['wgMessagesDirs']['SemanticScribunto'] = __DIR__ . '/i18n'; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @since 1.0 |
||
67 | */ |
||
68 | public static function onExtensionFunction() { |
||
69 | $hookRegistry = new HookRegistry(); |
||
70 | $hookRegistry->register(); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @since 1.0 |
||
75 | * |
||
76 | * @return string|null |
||
77 | */ |
||
78 | public static function getVersion() { |
||
79 | return SMW_SCRIBUNTO_VERSION; |
||
80 | } |
||
81 | |||
82 | } |
||
83 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.