Completed
Push — master ( 97f202...77971f )
by
unknown
02:40
created
src/ConstraintCheck/Message/ViolationMessageRenderer.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -332,7 +332,6 @@
 block discarded – undo
332 332
 	}
333 333
 
334 334
 	/**
335
-	 * @param string[] $text Context::TYPE_* constants
336 335
 	 * @param string|null $role one of the Role::* constants
337 336
 	 * @return array[] list of parameters as accepted by Message::params()
338 337
 	 */
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -66,21 +66,21 @@  discard block
 block discarded – undo
66 66
 	 * (temporarily, pre-rendered strings are allowed and returned without changes)
67 67
 	 * @return string
68 68
 	 */
69
-	public function render( $violationMessage ) {
70
-		if ( is_string( $violationMessage ) ) {
69
+	public function render($violationMessage) {
70
+		if (is_string($violationMessage)) {
71 71
 			// TODO remove this once all checkers produce ViolationMessage objects
72 72
 			return $violationMessage;
73 73
 		}
74 74
 
75 75
 		$messageKey = $violationMessage->getMessageKey();
76
-		$paramsLists = [ [] ];
77
-		foreach ( $violationMessage->getArguments() as $argument ) {
78
-			$params = $this->renderArgument( $argument );
76
+		$paramsLists = [[]];
77
+		foreach ($violationMessage->getArguments() as $argument) {
78
+			$params = $this->renderArgument($argument);
79 79
 			$paramsLists[] = $params;
80 80
 		}
81
-		$allParams = call_user_func_array( 'array_merge', $paramsLists );
82
-		return ( new Message( $messageKey ) )
83
-			->params( $allParams )
81
+		$allParams = call_user_func_array('array_merge', $paramsLists);
82
+		return (new Message($messageKey))
83
+			->params($allParams)
84 84
 			->escaped();
85 85
 	}
86 86
 
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	 * @param string|null $role one of the Role::* constants
90 90
 	 * @return string HTML
91 91
 	 */
92
-	private function addRole( $value, $role ) {
93
-		if ( $role === null ) {
92
+	private function addRole($value, $role) {
93
+		if ($role === null) {
94 94
 			return $value;
95 95
 		}
96 96
 
97
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
98
-			$value .
97
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
98
+			$value.
99 99
 			'</span>';
100 100
 	}
101 101
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @param array $argument
104 104
 	 * @return array[] params (for Message::params)
105 105
 	 */
106
-	private function renderArgument( array $argument ) {
106
+	private function renderArgument(array $argument) {
107 107
 		$methods = [
108 108
 			ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId',
109 109
 			ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList',
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 		$value = $argument['value'];
122 122
 		$role = $argument['role'];
123 123
 
124
-		if ( array_key_exists( $type, $methods ) ) {
124
+		if (array_key_exists($type, $methods)) {
125 125
 			$method = $methods[$type];
126
-			$params = $this->$method( $value, $role );
126
+			$params = $this->$method($value, $role);
127 127
 		} else {
128 128
 			throw new InvalidArgumentException(
129
-				'Unknown ViolationMessage argument type ' . $type . '!'
129
+				'Unknown ViolationMessage argument type '.$type.'!'
130 130
 			);
131 131
 		}
132 132
 
@@ -140,46 +140,46 @@  discard block
 block discarded – undo
140 140
 	 * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ])
141 141
 	 * @return array[] list of parameters as accepted by Message::params()
142 142
 	 */
143
-	private function renderList( array $list, $role, callable $render ) {
144
-		if ( $list === [] ) {
143
+	private function renderList(array $list, $role, callable $render) {
144
+		if ($list === []) {
145 145
 			return [
146
-				Message::numParam( 0 ),
147
-				Message::rawParam( '<ul></ul>' ),
146
+				Message::numParam(0),
147
+				Message::rawParam('<ul></ul>'),
148 148
 			];
149 149
 		}
150 150
 
151
-		if ( count( $list ) > $this->maxListLength ) {
152
-			$list = array_slice( $list, 0, $this->maxListLength );
151
+		if (count($list) > $this->maxListLength) {
152
+			$list = array_slice($list, 0, $this->maxListLength);
153 153
 			$truncated = true;
154 154
 		}
155 155
 
156 156
 		$renderedParamsLists = array_map(
157 157
 			$render,
158 158
 			$list,
159
-			array_fill( 0, count( $list ), $role )
159
+			array_fill(0, count($list), $role)
160 160
 		);
161 161
 		$renderedParams = array_map(
162
-			function ( $params ) {
162
+			function($params) {
163 163
 				return $params[0];
164 164
 			},
165 165
 			$renderedParamsLists
166 166
 		);
167 167
 		$renderedElements = array_map(
168
-			function ( $param ) {
168
+			function($param) {
169 169
 				return $param['raw'];
170 170
 			},
171 171
 			$renderedParams
172 172
 		);
173
-		if ( isset( $truncated ) ) {
174
-			$renderedElements[] = wfMessage( 'ellipsis' )->escaped();
173
+		if (isset($truncated)) {
174
+			$renderedElements[] = wfMessage('ellipsis')->escaped();
175 175
 		}
176 176
 
177 177
 		return array_merge(
178 178
 			[
179
-				Message::numParam( count( $list ) ),
179
+				Message::numParam(count($list)),
180 180
 				Message::rawParam(
181
-					'<ul><li>' .
182
-					implode( '</li><li>', $renderedElements ) .
181
+					'<ul><li>'.
182
+					implode('</li><li>', $renderedElements).
183 183
 					'</li></ul>'
184 184
 				),
185 185
 			],
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 	 * @param string|null $role one of the Role::* constants
193 193
 	 * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
194 194
 	 */
195
-	private function renderEntityId( EntityId $entityId, $role ) {
196
-		return [ Message::rawParam( $this->addRole(
197
-			$this->entityIdFormatter->formatEntityId( $entityId ),
195
+	private function renderEntityId(EntityId $entityId, $role) {
196
+		return [Message::rawParam($this->addRole(
197
+			$this->entityIdFormatter->formatEntityId($entityId),
198 198
 			$role
199
-		) ) ];
199
+		))];
200 200
 	}
201 201
 
202 202
 	/**
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 	 * @param string|null $role one of the Role::* constants
205 205
 	 * @return array[] list of parameters as accepted by Message::params()
206 206
 	 */
207
-	private function renderEntityIdList( array $entityIdList, $role ) {
208
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
207
+	private function renderEntityIdList(array $entityIdList, $role) {
208
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
209 209
 	}
210 210
 
211 211
 	/**
@@ -213,24 +213,24 @@  discard block
 block discarded – undo
213 213
 	 * @param string|null $role one of the Role::* constants
214 214
 	 * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
215 215
 	 */
216
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) {
217
-		switch ( true ) {
216
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) {
217
+		switch (true) {
218 218
 			case $value->isValue():
219
-				return $this->renderEntityId( $value->getItemId(), $role );
219
+				return $this->renderEntityId($value->getItemId(), $role);
220 220
 			case $value->isSomeValue():
221
-				return [ Message::rawParam( $this->addRole(
222
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
223
-						wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() .
221
+				return [Message::rawParam($this->addRole(
222
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
223
+						wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped().
224 224
 						'</span>',
225 225
 					$role
226
-				) ) ];
226
+				))];
227 227
 			case $value->isNoValue():
228
-				return [ Message::rawParam( $this->addRole(
229
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
230
-						wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() .
228
+				return [Message::rawParam($this->addRole(
229
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
230
+						wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped().
231 231
 						'</span>',
232 232
 					$role
233
-				) ) ];
233
+				))];
234 234
 			default:
235 235
 				// @codeCoverageIgnoreStart
236 236
 				throw new LogicException(
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 	 * @param string|null $role one of the Role::* constants
246 246
 	 * @return array[] list of parameters as accepted by Message::params()
247 247
 	 */
248
-	private function renderItemIdSnakValueList( array $valueList, $role ) {
249
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
248
+	private function renderItemIdSnakValueList(array $valueList, $role) {
249
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
250 250
 	}
251 251
 
252 252
 	/**
@@ -254,11 +254,11 @@  discard block
 block discarded – undo
254 254
 	 * @param string|null $role one of the Role::* constants
255 255
 	 * @return array[] list of parameters as accepted by Message::params()
256 256
 	 */
257
-	private function renderDataValue( DataValue $dataValue, $role ) {
258
-		return [ Message::rawParam( $this->addRole(
259
-			$this->dataValueFormatter->format( $dataValue ),
257
+	private function renderDataValue(DataValue $dataValue, $role) {
258
+		return [Message::rawParam($this->addRole(
259
+			$this->dataValueFormatter->format($dataValue),
260 260
 			$role
261
-		) ) ];
261
+		))];
262 262
 	}
263 263
 
264 264
 	/**
@@ -266,22 +266,22 @@  discard block
 block discarded – undo
266 266
 	 * @param string|null $role one of the Role::* constants
267 267
 	 * @return array[] list of parameters as accepted by Message::params()
268 268
 	 */
269
-	private function renderDataValueType( $dataValueType, $role ) {
269
+	private function renderDataValueType($dataValueType, $role) {
270 270
 		$messageKeys = [
271 271
 			'string' => 'datatypes-type-string',
272 272
 			'monolingualtext' => 'datatypes-monolingualtext',
273 273
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
274 274
 		];
275 275
 
276
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
277
-			return [ Message::rawParam( $this->addRole(
278
-				wfMessage( $messageKeys[$dataValueType] )->escaped(),
276
+		if (array_key_exists($dataValueType, $messageKeys)) {
277
+			return [Message::rawParam($this->addRole(
278
+				wfMessage($messageKeys[$dataValueType])->escaped(),
279 279
 				$role
280
-			) ) ];
280
+			))];
281 281
 		} else {
282 282
 			// @codeCoverageIgnoreStart
283 283
 			throw new LogicException(
284
-				'Unknown data value type ' . $dataValueType
284
+				'Unknown data value type '.$dataValueType
285 285
 			);
286 286
 			// @codeCoverageIgnoreEnd
287 287
 		}
@@ -292,11 +292,11 @@  discard block
 block discarded – undo
292 292
 	 * @param string|null $role one of the Role::* constants
293 293
 	 * @return array[] list of parameters as accepted by Message::params()
294 294
 	 */
295
-	private function renderInlineCode( $code, $role ) {
296
-		return [ Message::rawParam( $this->addRole(
297
-			'<code>' . htmlspecialchars( $code ) . '</code>',
295
+	private function renderInlineCode($code, $role) {
296
+		return [Message::rawParam($this->addRole(
297
+			'<code>'.htmlspecialchars($code).'</code>',
298 298
 			$role
299
-		) ) ];
299
+		))];
300 300
 	}
301 301
 
302 302
 	/**
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 	 * @param string|null $role one of the Role::* constants
305 305
 	 * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
306 306
 	 */
307
-	private function renderConstraintScope( $scope, $role ) {
308
-		switch ( $scope ) {
307
+	private function renderConstraintScope($scope, $role) {
308
+		switch ($scope) {
309 309
 			case Context::TYPE_STATEMENT:
310 310
 				$itemId = $this->config->get(
311 311
 					'WBQualityConstraintsConstraintCheckedOnMainValueId'
@@ -325,10 +325,10 @@  discard block
 block discarded – undo
325 325
 				// callers should never let this happen, but if it does happen,
326 326
 				// showing “unknown value” seems reasonable
327 327
 				// @codeCoverageIgnoreStart
328
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
328
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
329 329
 				// @codeCoverageIgnoreEnd
330 330
 		}
331
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
331
+		return $this->renderEntityId(new ItemId($itemId), $role);
332 332
 	}
333 333
 
334 334
 	/**
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
 	 * @param string|null $role one of the Role::* constants
337 337
 	 * @return array[] list of parameters as accepted by Message::params()
338 338
 	 */
339
-	private function renderConstraintScopeList( array $scopeList, $role ) {
340
-		return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] );
339
+	private function renderConstraintScopeList(array $scopeList, $role) {
340
+		return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']);
341 341
 	}
342 342
 
343 343
 	/**
@@ -345,10 +345,10 @@  discard block
 block discarded – undo
345 345
 	 * @param string|null $role one of the Role::* constants
346 346
 	 * @return array[] list of parameters as accepted by Message::params()
347 347
 	 */
348
-	private function renderLanguage( $languageCode, $role ) {
348
+	private function renderLanguage($languageCode, $role) {
349 349
 		return [
350
-			Message::plaintextParam( Language::fetchLanguageName( $languageCode ) ),
351
-			Message::plaintextParam( $languageCode ),
350
+			Message::plaintextParam(Language::fetchLanguageName($languageCode)),
351
+			Message::plaintextParam($languageCode),
352 352
 		];
353 353
 	}
354 354
 
Please login to merge, or discard this patch.