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 | use SBL\HookRegistry; |
||
4 | use SBL\Options; |
||
5 | use SMW\ApplicationFactory; |
||
6 | |||
7 | /** |
||
8 | * @see https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/ |
||
9 | * |
||
10 | * @defgroup SBL Semantic Breadcrumb Links |
||
11 | */ |
||
12 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
13 | die( 'This file is part of the SemanticBreadcrumbLinks extension, it is not a valid entry point.' ); |
||
14 | } |
||
15 | |||
16 | if ( defined( 'SBL_VERSION' ) ) { |
||
17 | // Do not initialize more than once. |
||
18 | return 1; |
||
19 | } |
||
20 | |||
21 | SemanticBreadcrumbLinks::load(); |
||
22 | |||
23 | /** |
||
24 | * @codeCoverageIgnore |
||
25 | */ |
||
26 | class SemanticBreadcrumbLinks { |
||
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. ![]() |
|||
27 | |||
28 | /** |
||
29 | * @since 1.3 |
||
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 | // Load DefaultSettings |
||
38 | require_once __DIR__ . '/DefaultSettings.php'; |
||
39 | |||
40 | // In case extension.json is being used, the the succeeding steps will |
||
41 | // be handled by the ExtensionRegistry |
||
42 | self::initExtension(); |
||
43 | |||
44 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
45 | self::onExtensionFunction(); |
||
46 | }; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @since 1.3 |
||
51 | */ |
||
52 | 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);
}
}
![]() |
|||
53 | |||
54 | define( 'SBL_VERSION', '1.4.0-alpha' ); |
||
55 | define( 'SBL_PROP_PARENTPAGE', 'Has parent page' ); |
||
56 | |||
57 | // Register the extension |
||
58 | $GLOBALS['wgExtensionCredits']['semantic'][ ] = array( |
||
59 | 'path' => __FILE__, |
||
60 | 'name' => 'Semantic Breadcrumb Links', |
||
61 | 'author' => array( 'James Hong Kong' ), |
||
62 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/', |
||
63 | 'descriptionmsg' => 'sbl-desc', |
||
64 | 'version' => SBL_VERSION, |
||
65 | 'license-name' => 'GPL-2.0+', |
||
66 | ); |
||
67 | |||
68 | // Register message files |
||
69 | $GLOBALS['wgMessagesDirs']['SemanticBreadcrumbLinks'] = __DIR__ . '/i18n'; |
||
70 | $GLOBALS['wgExtensionMessagesFiles']['SemanticBreadcrumbLinksMagic'] = __DIR__ . '/i18n/SemanticBreadcrumbLinks.magic.php'; |
||
71 | |||
72 | // Register resource files |
||
73 | $GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks.styles'] = array( |
||
74 | 'styles' => 'res/sbl.styles.css', |
||
75 | 'localBasePath' => __DIR__ , |
||
76 | 'remoteExtPath' => 'SemanticBreadcrumbLinks', |
||
77 | 'position' => 'top', |
||
78 | 'group' => 'ext.smw', |
||
79 | 'targets' => array( |
||
80 | 'mobile', |
||
81 | 'desktop' |
||
82 | ) |
||
83 | ); |
||
84 | |||
85 | $GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks'] = array( |
||
86 | 'scripts' => 'res/sbl.tooltip.js', |
||
87 | 'localBasePath' => __DIR__ , |
||
88 | 'remoteExtPath' => 'SemanticBreadcrumbLinks', |
||
89 | 'position' => 'top', |
||
90 | 'group' => 'ext.smw', |
||
91 | 'dependencies' => array( |
||
92 | 'ext.semanticbreadcrumblinks.styles', |
||
93 | 'onoi.qtip' |
||
94 | ), |
||
95 | 'targets' => array( |
||
96 | 'mobile', |
||
97 | 'desktop' |
||
98 | ) |
||
99 | ); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @since 1.3 |
||
104 | */ |
||
105 | 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);
}
}
![]() |
|||
106 | |||
107 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) { |
||
108 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> is only compatible with MediaWiki 1.23 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 ![]() |
|||
109 | } |
||
110 | |||
111 | if ( !defined( 'SMW_VERSION' ) ) { |
||
112 | die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> requires <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a>, 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 ![]() |
|||
113 | } |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @since 1.3 |
||
118 | */ |
||
119 | 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);
}
}
![]() |
|||
120 | |||
121 | // Check requirements after LocalSetting.php has been processed |
||
122 | self::checkRequirements(); |
||
123 | |||
124 | // Default values are defined at this point to ensure |
||
125 | // NS contants are specified prior |
||
126 | $defaultPropertySearchPatternByNamespace = array( |
||
127 | NS_CATEGORY => array( |
||
128 | '_SUBC', |
||
129 | '_SUBC', |
||
130 | '_SUBC' |
||
131 | ), |
||
132 | SMW_NS_PROPERTY => array( |
||
133 | '_SUBP', |
||
134 | '_SUBP', |
||
135 | '_SUBP' |
||
136 | ), |
||
137 | NS_MAIN => array( |
||
138 | SBL_PROP_PARENTPAGE, |
||
139 | SBL_PROP_PARENTPAGE, |
||
140 | SBL_PROP_PARENTPAGE |
||
141 | ), |
||
142 | NS_HELP => array( |
||
143 | SBL_PROP_PARENTPAGE, |
||
144 | SBL_PROP_PARENTPAGE, |
||
145 | SBL_PROP_PARENTPAGE |
||
146 | ) |
||
147 | ); |
||
148 | |||
149 | $configuration = array( |
||
150 | 'hideSubpageParent' => $GLOBALS['egSBLPageTitleToHideSubpageParent'], |
||
151 | 'breadcrumbTrailStyleClass' => $GLOBALS['egSBLBreadcrumbTrailStyleClass'], |
||
152 | 'breadcrumbDividerStyleClass' => $GLOBALS['egSBLBreadcrumbDividerStyleClass'], |
||
153 | 'tryToFindClosestDescendant' => $GLOBALS['egSBLTryToFindClosestDescendant'], |
||
154 | 'useSubpageFinderFallback' => $GLOBALS['egSBLUseSubpageFinderFallback'], |
||
155 | 'enabledSubpageParentAnnotation' => $GLOBALS['egSBLEnabledSubpageParentAnnotation'], |
||
156 | 'wgNamespacesWithSubpages' => $GLOBALS['wgNamespacesWithSubpages'], |
||
157 | 'propertySearchPatternByNamespace' => $GLOBALS['egSBLPropertySearchPatternByNamespace'] + $defaultPropertySearchPatternByNamespace |
||
158 | ); |
||
159 | |||
160 | $hookRegistry = new HookRegistry( |
||
161 | ApplicationFactory::getInstance()->getStore(), |
||
162 | new Options( $configuration ) |
||
163 | ); |
||
164 | |||
165 | $hookRegistry->register(); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @since 1.3 |
||
170 | * |
||
171 | * @return string|null |
||
172 | */ |
||
173 | public static function getVersion() { |
||
174 | return SBL_VERSION; |
||
175 | } |
||
176 | |||
177 | } |
||
178 |
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.