These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | /** |
||
4 | * @see https://github.com/SemanticMediaWiki/SemanticCompoundQueries/ |
||
5 | * |
||
6 | * @defgroup SemanticCompoundQueries SemanticCompoundQueries |
||
7 | */ |
||
8 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
9 | die( 'This file is part of the SemanticCompoundQueries extension, it is not a valid entry point.' ); |
||
10 | } |
||
11 | |||
12 | if ( defined( 'SCQ_VERSION' ) ) { |
||
13 | // Do not initialize more than once. |
||
14 | return 1; |
||
15 | } |
||
16 | |||
17 | SemanticCompoundQueries::load(); |
||
18 | |||
19 | /** |
||
20 | * @codeCoverageIgnore |
||
21 | */ |
||
22 | class SemanticCompoundQueries { |
||
0 ignored issues
–
show
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. ![]() |
|||
23 | |||
24 | /** |
||
25 | * @since 1.1 |
||
26 | * |
||
27 | * @note It is expected that this function is loaded before LocalSettings.php |
||
28 | * to ensure that settings and global functions are available by the time |
||
29 | * the extension is activated. |
||
30 | */ |
||
31 | public static function load() { |
||
0 ignored issues
–
show
load 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);
}
}
![]() |
|||
32 | |||
33 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
34 | include_once __DIR__ . '/vendor/autoload.php'; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * In case extension.json is being used, the succeeding steps are |
||
39 | * expected to be handled by the ExtensionRegistry aka extension.json |
||
40 | * ... |
||
41 | * |
||
42 | * "callback": "SemanticCompoundQueries::initExtension", |
||
43 | * "ExtensionFunctions": [ |
||
44 | * "SemanticCompoundQueries::onExtensionFunction" |
||
45 | * ], |
||
46 | */ |
||
47 | self::initExtension(); |
||
48 | |||
49 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
50 | self::onExtensionFunction(); |
||
51 | }; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @since 1.1 |
||
56 | */ |
||
57 | 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);
}
}
![]() |
|||
58 | |||
59 | define( 'SCQ_VERSION', '1.1.0-alpha' ); |
||
60 | |||
61 | // Register the extension |
||
62 | $GLOBALS['wgExtensionCredits']['semantic'][] = array( |
||
63 | 'path' => __FILE__, |
||
64 | 'name' => 'Semantic Compound Queries', |
||
65 | 'version' => SCQ_VERSION, |
||
66 | 'author' => array( |
||
67 | '[https://www.semantic-mediawiki.org/ Semantic MediaWiki project]', |
||
68 | 'Yaron Koren' |
||
69 | ), |
||
70 | 'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries', |
||
71 | 'descriptionmsg' => 'semanticcompoundqueries-desc', |
||
72 | 'license-name' => 'GPL-2.0+' |
||
73 | ); |
||
74 | |||
75 | // Register message files |
||
76 | $GLOBALS['wgMessagesDirs']['SemanticCompoundQueries'] = __DIR__ . '/i18n'; |
||
77 | $GLOBALS['wgExtensionMessagesFiles']['SemanticCompoundQueriesMagic'] = __DIR__ . '/i18n/SemanticCompoundQueries.i18n.magic.php'; |
||
78 | |||
79 | //$GLOBALS['wgAutoloadClasses']['SCQQueryProcessor'] = __DIR__ . '/SCQ_QueryProcessor.php'; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
80 | //$GLOBALS['wgAutoloadClasses']['SCQQueryResult'] = __DIR__ . '/SCQ_QueryResult.php'; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
81 | //$GLOBALS['wgAutoloadClasses']['SCQCompoundQueryApi'] = __DIR__ . '/SCQ_CompoundQueryApi.php'; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @since 1.1 |
||
86 | */ |
||
87 | public static function checkRequirements() { |
||
0 ignored issues
–
show
checkRequirements 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);
}
}
![]() |
|||
88 | |||
89 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.13', 'lt' ) ) { |
||
90 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticCompoundQueries/">Semantic Compound Queries</a> is only compatible with MediaWiki 1.13 or above. You need to upgrade MediaWiki first.' ); |
||
0 ignored issues
–
show
The method
checkRequirements() 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 ![]() |
|||
91 | } |
||
92 | |||
93 | if ( !defined( 'SMW_VERSION' ) ) { |
||
94 | die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticCompoundQueries/">Semantic Compound Queries</a> requires the <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a> extension, please enable or install the extension first.' ); |
||
0 ignored issues
–
show
The method
checkRequirements() 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 ![]() |
|||
95 | } |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @since 1.1 |
||
100 | */ |
||
101 | public static function onExtensionFunction() { |
||
0 ignored issues
–
show
onExtensionFunction 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);
}
}
![]() |
|||
102 | |||
103 | // Check requirements after LocalSetting.php has been processed, thid has |
||
104 | // be done here to ensure SMW is loaded in case |
||
105 | // wfLoadExtension( 'SemanticMediaWiki' ) is used |
||
106 | self::checkRequirements(); |
||
107 | |||
108 | // wgAPIModules |
||
109 | $GLOBALS['wgAPIModules']['compoundquery'] = 'SCQ\Api\CompoundQuery'; |
||
110 | |||
111 | $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
||
112 | $parser->setFunctionHook( 'compound_query', array( '\SCQ\CompoundQueryProcessor', 'doCompoundQuery' ) ); |
||
113 | |||
114 | // always return true, in order not to stop MW's hook processing! |
||
115 | return true; |
||
116 | }; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @since 1.1 |
||
121 | * |
||
122 | * @return string|null |
||
123 | */ |
||
124 | public static function getVersion() { |
||
125 | return SCQ_VERSION; |
||
126 | } |
||
127 | |||
128 | } |
||
129 | |||
130 |
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.