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 SMW\ApprovedRevs\Hooks; |
||
4 | |||
5 | /** |
||
6 | * Extension ... |
||
7 | * |
||
8 | * @see https://github.com/SemanticMediaWiki/SemanticApprovedRevs |
||
9 | * |
||
10 | * @defgroup SemanticApprovedRevs Semantic Approved Revs |
||
11 | */ |
||
12 | SemanticApprovedRevs::load(); |
||
13 | |||
14 | /** |
||
15 | * @codeCoverageIgnore |
||
16 | */ |
||
17 | class SemanticApprovedRevs { |
||
18 | |||
19 | /** |
||
20 | * @since 1.0 |
||
21 | * |
||
22 | * @note It is expected that this function is loaded before LocalSettings.php |
||
23 | * to ensure that settings and global functions are available by the time |
||
24 | * the extension is activated. |
||
25 | */ |
||
26 | public static function load() { |
||
27 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
28 | include_once __DIR__ . '/vendor/autoload.php'; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @since 1.0 |
||
34 | * @see https://www.mediawiki.org/wiki/Manual:Extension.json/Schema#callback |
||
35 | */ |
||
36 | public static function initExtension( $credits = [] ) { |
||
37 | // See https://phabricator.wikimedia.org/T151136 |
||
38 | define( 'SMW_APPROVED_REVS_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' ); |
||
39 | |||
40 | $GLOBALS['wgMessagesDirs']['SemanticApprovedRevs'] = __DIR__ . '/i18n'; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @since 1.0 |
||
45 | */ |
||
46 | public static function onExtensionFunction() { |
||
47 | |||
48 | if ( !defined( 'SMW_VERSION' ) ) { |
||
49 | if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
||
50 | die( "\nThe 'Semantic Approved Revs' extension requires the 'Semantic MediaWiki' extension to be installed and enabled.\n" ); |
||
0 ignored issues
–
show
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 ![]() |
|||
51 | } else { |
||
52 | die( |
||
0 ignored issues
–
show
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 ![]() |
|||
53 | '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticApprovedRevs/">Semantic Approved Revs</a> extension' . |
||
54 | ' requires the <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> extension to be installed and enabled.<br />' |
||
55 | ); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | // We expected to check for APPROVED_REVS_VERSION but the extension and |
||
60 | // its `extension.json` doesn't set the constant so we have to rely on |
||
61 | // active class loading (which is an anti-pattern) to check whether the |
||
62 | // extension is enabled or not! |
||
63 | if ( !class_exists( 'ApprovedRevs' ) ) { |
||
64 | if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
||
65 | die( "\nThe 'Semantic Approved Revs' extension requires the 'Approved Revs' extension to be installed and enabled.\n" ); |
||
0 ignored issues
–
show
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 ![]() |
|||
66 | } else { |
||
67 | die( |
||
0 ignored issues
–
show
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 ![]() |
|||
68 | '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticApprovedRevs/">Semantic Approved Revs</a> extension' . |
||
69 | ' requires the <a href="https://www.mediawiki.org/wiki/Extension:Approved_Revs">Approved Revs</a> extension to be installed and enabled.<br />' |
||
70 | ); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | if ( defined( 'SESP_VERSION' ) && version_compare( SESP_VERSION, '2.1.0', '<' ) && ( $prop = Hooks::hasPropertyCollisions( $GLOBALS ) ) !== false ) { |
||
75 | die( |
||
0 ignored issues
–
show
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 ![]() |
|||
76 | "\nPlease remove the `$prop` property (defined by the SemanticExtraSpecialProperties extension) and switch to the new SESP version 2.1" . |
||
77 | " to avoid collision with the 'Semantic Approved Revs' list of properties.\n" |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | $hooks = new Hooks(); |
||
82 | $hooks->register(); |
||
83 | } |
||
84 | |||
85 | } |
||
86 |
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.