Completed
Push — master ( d03c2d...c71f3c )
by
unknown
04:45
created

Lingo::onGetDoubleUnderscoreIDs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * File containing the Lingo class
4
 *
5
 * This file is part of the MediaWiki extension Lingo.
6
 *
7
 * @copyright 2011 - 2017, Stephan Gambke
8
 * @license   GNU General Public License, version 2 (or any later version)
9
 *
10
 * The Lingo extension is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by the Free
12
 * Software Foundation; either version 2 of the License, or (at your option) any
13
 * later version.
14
 *
15
 * The Lingo extension is distributed in the hope that it will be useful, but
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18
 * details.
19
 *
20
 * You should have received a copy of the GNU General Public License along
21
 * with this program. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 * @file
24
 * @ingroup Lingo
25
 */
26
27
namespace Lingo;
28
29
/**
30
 * Class Lingo
31
 *
32
 * @package Lingo
33
 * @ingroup Lingo
34
 */
35
class Lingo {
36
37
	/**
38
	 * Deferred settings
39
	 * - registration of _NOGLOSSARY_ magic word
40
	 * - extension description shown on Special:Version
41
	 *
42
	 * @since 2.0.2
43
	 */
44
	public static function initExtension() {
0 ignored issues
show
Coding Style introduced by
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);
    }
}
Loading history...
45
46
		$GLOBALS[ 'wgExtensionFunctions' ][] = function () {
47
48
			$parser = LingoParser::getInstance();
49
50
			$backend = new $GLOBALS[ 'wgexLingoBackend' ]();
51
52
			$parser->setBackend( $backend );
53
54
			\Hooks::register( 'ParserAfterParse', array( $parser, 'parse' ) );
55
56
			\Hooks::register('GetDoubleUnderscoreIDs', function ( array &$doubleUnderscoreIDs ) {
57
				$doubleUnderscoreIDs[] = 'noglossary';
58
				return true;
59
			} );
60
61
			\Hooks::register( 'ParserFirstCallInit', function ( \Parser $parser ) {
62
63
				$parser->setHook( 'noglossary', function ( $input, array $args, \Parser $parser, \PPFrame $frame ) {
64
					$output = $parser->recursiveTagParse( $input, $frame );
65
					return '<span class="noglossary">' . $output . '</span>';
66
				} );
67
68
				return true;
69
			} );
70
71
			\Hooks::register( 'SpecialPageBeforeExecute', function ( \SpecialPage $specialPage, $subPage ) {
0 ignored issues
show
Unused Code introduced by
The parameter $subPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
73
				if ( $specialPage instanceof \SpecialVersion ) {
1 ignored issue
show
Bug introduced by
The class SpecialVersion does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
74
					foreach ( $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ] as $index => $description ) {
75
						if ( $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ][ $index ][ 'name' ] === 'Lingo' ) {
76
							$GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ][ $index ][ 'description' ] = wfMessage( 'lingo-desc', $GLOBALS[ 'wgexLingoPage' ] ?: wfMessage( 'lingo-terminologypagename' )->inContentLanguage()->text() )->text();
77
						}
78
					}
79
				}
80
81
				return true;
82
			} );
83
		};
84
	}
85
86
}
87