Completed
Branch master (86dc85)
by
unknown
23:45
created

SearchInputWidget::getConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
/**
3
 * MediaWiki Widgets – SearchInputWidget class.
4
 *
5
 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
6
 * @license The MIT License (MIT); see LICENSE.txt
7
 */
8
namespace MediaWiki\Widget;
9
10
/**
11
 * Search input widget.
12
 */
13
class SearchInputWidget extends TitleInputWidget {
14
15
	protected $pushPending = false;
16
	protected $performSearchOnClick = true;
17
	protected $validateTitle = false;
18
	protected $highlightFirst = false;
19
20
	/**
21
	 * @param array $config Configuration options
22
	 * @param int|null $config['pushPending'] Whether the input should be visually marked as
0 ignored issues
show
Documentation introduced by
There is no parameter named $config['pushPending']. Did you maybe mean $config?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
23
	 *  "pending", while requesting suggestions (default: true)
24
	 * @param boolean|null $config['performSearchOnClick'] If true, the script will start a search
0 ignored issues
show
Documentation introduced by
There is no parameter named $config['performSearchOnClick']. Did you maybe mean $config?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
25
	 *  whenever a user hits a suggestion. If false, the text of the suggestion is inserted into the
26
	 *  text field only (default: true)
27
	 */
28
	public function __construct( array $config = [] ) {
29
		$config = array_merge( [
30
			'infusable' => true,
31
			'maxLength' => null,
32
			'type' => 'search',
33
			'icon' => 'search',
34
			'dataLocation' => 'content',
35
		], $config );
36
37
		// Parent constructor
38
		parent::__construct( $config );
39
40
		// Properties, which are ignored in PHP and just shipped back to JS
41
		if ( isset( $config['pushPending'] ) ) {
42
			$this->pushPending = $config['pushPending'];
43
		}
44
45
		if ( isset( $config['performSearchOnClick'] ) ) {
46
			$this->performSearchOnClick = $config['performSearchOnClick'];
47
		}
48
49
		if ( $config['dataLocation'] ) {
50
			// identifies the location of the search bar for tracking purposes
51
			$this->dataLocation = $config['dataLocation'];
0 ignored issues
show
Bug introduced by
The property dataLocation does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
		}
53
54
		// Initialization
55
		$this->addClasses( [ 'mw-widget-searchInputWidget' ] );
56
	}
57
58
	protected function getJavaScriptClassName() {
59
		return 'mw.widgets.SearchInputWidget';
60
	}
61
62
	public function getConfig( &$config ) {
63
		$config['pushPending'] = $this->pushPending;
64
		$config['performSearchOnClick'] = $this->performSearchOnClick;
65
		if ( $this->dataLocation ) {
66
			$config['dataLocation'] = $this->dataLocation;
67
		}
68
		return parent::getConfig( $config );
69
	}
70
}
71