Completed
Push — master ( c0e2ef...2173f1 )
by Karsten
07:19
created

formats/widget/SRF_ListWidget.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use SMW\Query\ResultPrinters\ListResultPrinter\ListResultBuilder;
4
use SMW\Query\ResultPrinters\ResultPrinter;
5
6
/**
7
 * Extends the list result printer (SMW_QP_List.php) with a JavaScript
8
 * navigation widget
9
 *
10
 * @since 1.8
11
 *
12
 * @author mwjames
13
 *
14
 * @ingroup SemanticResultFormats
15
 * @file SRF_ListWidget.php
16
 */
17
class SRFListWidget extends ResultPrinter {
18
19
	/**
20
	 * Get a human readable label for this printer.
21
	 *
22
	 * @return string
23
	 */
24
	public function getName() {
25
		return wfMessage( 'srf-printername-listwidget' )->text();
26
	}
27
28
	/**
29
	 * @see SMWResultPrinter::getResultText
30
	 *
31
	 * @param SMWQueryResult $res
32
	 * @param array $params
33
	 * @param $outputmode
34
	 *
35
	 * @return string
36
	 */
37 1
	protected function getResultText( SMWQueryResult $res, $outputmode ) {
38
		// Initialize
39 1
		static $statNr = 0;
40
		//$this->isHTML = true;
41
42 1
		$listType = $this->params[ 'listtype' ] === 'ordered' || $this->params[ 'listtype' ] === 'ol' ? 'ol' : 'ul';
43
44 1
		$builder = new ListResultBuilder( $res, $this->mLinker );
45
46 1
		$builder->set( $this->params );
47 1
		$builder->set( [
0 ignored issues
show
array('format' => $listT...=> $this->mShowHeaders) is of type array<string,string|bool...ow-headers":"integer"}>, but the function expects a string|array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48 1
			'format' => $listType,
49 1
			'link-first' => $this->mLinkFirst,
50 1
			'link-others' => $this->mLinkOthers,
51 1
			'show-headers' => $this->mShowHeaders,
52
		] );
53
54
		// Get results from SMWListResultPrinter
55 1
		$result = $builder->getResultText();
56
57
		// Count widgets
58 1
		$listwidgetID = 'listwidget-' . ++$statNr;
59
60
		// OL/UL container items
61 1
		$result = Html::rawElement(
62 1
			'div',
63
			[
64 1
				'id' => $listwidgetID,
65 1
				'class' => 'listwidget-container',
66 1
				'style' => 'display:none; position: relative; margin-bottom:5px; margin-top:5px;'
67
			],
68 1
			$result
69
		);
70
71
		// Placeholder
72 1
		$processing = SRFUtils::htmlProcessingElement( $this->isHTML );
73
74
		// RL module
75 1
		$resource = 'ext.srf.listwidget.' . $this->params['widget'];
76 1
		SMWOutputs::requireResource( $resource );
77
78
		// Wrap results
79 1
		return Html::rawElement(
80 1
			'div',
81
			[
82 1
				'class' => 'srf-listwidget ' . htmlspecialchars( $this->params['class'] ),
83 1
				'data-listtype' => $listType,
84 1
				'data-widget' => $this->params['widget'],
85 1
				'data-pageitems' => $this->params['pageitems'],
86
			],
87 1
			$processing . $result
88
		);
89
	}
90
91
	/**
92
	 * @see SMWResultPrinter::getParamDefinitions
93
	 *
94
	 * @since 1.8
95
	 *
96
	 * @param $definitions array of IParamDefinition
97
	 *
98
	 * @return array of IParamDefinition|array
99
	 */
100 1
	public function getParamDefinitions( array $definitions ) {
101 1
		$params = parent::getParamDefinitions( $definitions );
102
103 1
		$params['class'] = [
104
			'name' => 'class',
105
			'message' => 'srf-paramdesc-class',
106
			'default' => '',
107
		];
108
109 1
		$params['listtype'] = [
110
			'name' => 'listtype',
111
			'message' => 'srf-paramdesc-listtype',
112
			'values' => [ 'unordered', 'ordered' ],
113
			'default' => 'unordered'
114
		];
115
116 1
		$params['widget'] = [
117
			'name' => 'widget',
118
			'message' => 'srf-paramdesc-widget',
119
			'values' => [ 'alphabet', 'menu', 'pagination' ],
120
			'default' => 'alphabet'
121
		];
122
123 1
		$params['pageitems'] = [
124
			'type' => 'integer',
125
			'name' => 'pageitems',
126
			'message' => 'srf-paramdesc-pageitems',
127
			'default' => 5,
128
		];
129
130 1
		return $params;
131
	}
132
}