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