Completed
Pull Request — master (#59)
by
unknown
05:02
created

Output::makeVariablesScript()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
ccs 7
cts 8
cp 0.875
cc 2
eloc 6
nc 2
nop 1
crap 2.0078
1
<?php
2
3
namespace SFS;
4
5
//use MWDebug;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 1.3
10
 *
11
 * @author mwjames
12
 * @author Alexander Gesinn
13
 */
14
class Output {
15
16
	/**
17
	 * @var array
18
	 */
19
	private static $headItems = array();
20
21
	/**
22
	 * Add an array of SF_Select field parameters as defined in Page Form's field tag.
23
	 *
24
	 * This will later be added to $wgOut so that JS can access it via mw.config.get
25
	 *
26
	 * @param array $data
27
	 */
28 1
	public static function addToHeadItem( Array $data = [] ) {
29 1
		return self::$headItems[] = $data;
30
	}
31
32
	/**
33
	 * Commit all SF_Select field parameters to Output
34
	 *
35
	 */
36
	public static function commitToParserOutput() {
37
		global $wgOut;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
38
39
		// to be used in JS like:
40
		// var SFSelect_fobjs = $.parseJSON( mw.config.get( 'sf_select' ) );
41
		$wgOut->addJsConfigVars('sf_select', json_encode( self::$headItems ));
42
43
		//self::$resourceModules = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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.

Loading history...
44
		//self::$headItems = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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.

Loading history...
45
	}
46
}
47