Completed
Push — master ( 602e35...1095ca )
by
unknown
20s
created
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message;
6 6
 
@@ -70,15 +70,15 @@  discard block
 block discarded – undo
70 70
 		$this->maxListLength = $maxListLength;
71 71
 	}
72 72
 
73
-	public function render( ViolationMessage $violationMessage ): string {
73
+	public function render(ViolationMessage $violationMessage): string {
74 74
 		$messageKey = $violationMessage->getMessageKey();
75
-		$paramsLists = [ [] ];
76
-		foreach ( $violationMessage->getArguments() as $argument ) {
77
-			$params = $this->renderArgument( $argument );
75
+		$paramsLists = [[]];
76
+		foreach ($violationMessage->getArguments() as $argument) {
77
+			$params = $this->renderArgument($argument);
78 78
 			$paramsLists[] = $params;
79 79
 		}
80
-		$allParams = array_merge( ...$paramsLists );
81
-		return $this->messageLocalizer->msg( $messageKey, ...$allParams )->escaped();
80
+		$allParams = array_merge(...$paramsLists);
81
+		return $this->messageLocalizer->msg($messageKey, ...$allParams)->escaped();
82 82
 	}
83 83
 
84 84
 	/**
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
 	 * @param string|null $role one of the Role::* constants
87 87
 	 * @return string HTML
88 88
 	 */
89
-	protected function addRole( string $value, ?string $role ): string {
90
-		if ( $role === null ) {
89
+	protected function addRole(string $value, ?string $role): string {
90
+		if ($role === null) {
91 91
 			return $value;
92 92
 		}
93 93
 
94
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
95
-			$value .
94
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
95
+			$value.
96 96
 			'</span>';
97 97
 	}
98 98
 
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 	 * @param string $key message key
101 101
 	 * @return string HTML
102 102
 	 */
103
-	protected function msgEscaped( string $key ): string {
104
-		return $this->messageLocalizer->msg( $key )->escaped();
103
+	protected function msgEscaped(string $key): string {
104
+		return $this->messageLocalizer->msg($key)->escaped();
105 105
 	}
106 106
 
107 107
 	/**
108 108
 	 * @param array $argument
109 109
 	 * @return MessageParam[] params (for Message::params)
110 110
 	 */
111
-	protected function renderArgument( array $argument ): array {
111
+	protected function renderArgument(array $argument): array {
112 112
 		$methods = [
113 113
 			ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId',
114 114
 			ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList',
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		$value = $argument['value'];
130 130
 		$role = $argument['role'];
131 131
 
132
-		if ( array_key_exists( $type, $methods ) ) {
132
+		if (array_key_exists($type, $methods)) {
133 133
 			$method = $methods[$type];
134
-			$params = $this->$method( $value, $role );
134
+			$params = $this->$method($value, $role);
135 135
 		} else {
136 136
 			throw new InvalidArgumentException(
137
-				'Unknown ViolationMessage argument type ' . $type . '!'
137
+				'Unknown ViolationMessage argument type '.$type.'!'
138 138
 			);
139 139
 		}
140 140
 
@@ -148,34 +148,34 @@  discard block
 block discarded – undo
148 148
 	 * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ])
149 149
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
150 150
 	 */
151
-	private function renderList( array $list, ?string $role, callable $render ): array {
152
-		if ( $list === [] ) {
151
+	private function renderList(array $list, ?string $role, callable $render): array {
152
+		if ($list === []) {
153 153
 			return [
154
-				Message::numParam( 0 ),
155
-				Message::rawParam( '<ul></ul>' ),
154
+				Message::numParam(0),
155
+				Message::rawParam('<ul></ul>'),
156 156
 			];
157 157
 		}
158 158
 
159
-		$truncated = count( $list ) > $this->maxListLength;
160
-		if ( $truncated ) {
161
-			$list = array_slice( $list, 0, $this->maxListLength );
159
+		$truncated = count($list) > $this->maxListLength;
160
+		if ($truncated) {
161
+			$list = array_slice($list, 0, $this->maxListLength);
162 162
 		}
163 163
 
164 164
 		$renderedParamsLists = array_map(
165 165
 			$render,
166 166
 			$list,
167
-			array_fill( 0, count( $list ), $role )
167
+			array_fill(0, count($list), $role)
168 168
 		);
169
-		$renderedParams = array_column( $renderedParamsLists, 0 );
170
-		$renderedElements = array_map( static fn ( MessageParam $p ) => $p->getValue(), $renderedParams );
171
-		if ( $truncated ) {
172
-			$renderedElements[] = $this->msgEscaped( 'ellipsis' );
169
+		$renderedParams = array_column($renderedParamsLists, 0);
170
+		$renderedElements = array_map(static fn (MessageParam $p) => $p->getValue(), $renderedParams);
171
+		if ($truncated) {
172
+			$renderedElements[] = $this->msgEscaped('ellipsis');
173 173
 		}
174 174
 
175 175
 		return [
176
-			Message::numParam( count( $list ) ),
176
+			Message::numParam(count($list)),
177 177
 			Message::rawParam(
178
-				'<ul><li>' . implode( '</li><li>', $renderedElements ) . '</li></ul>'
178
+				'<ul><li>'.implode('</li><li>', $renderedElements).'</li></ul>'
179 179
 			),
180 180
 			...$renderedParams,
181 181
 		];
@@ -186,11 +186,11 @@  discard block
 block discarded – undo
186 186
 	 * @param string|null $role one of the Role::* constants
187 187
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
188 188
 	 */
189
-	private function renderEntityId( EntityId $entityId, ?string $role ): array {
190
-		return [ Message::rawParam( $this->addRole(
191
-			$this->entityIdFormatter->formatEntityId( $entityId ),
189
+	private function renderEntityId(EntityId $entityId, ?string $role): array {
190
+		return [Message::rawParam($this->addRole(
191
+			$this->entityIdFormatter->formatEntityId($entityId),
192 192
 			$role
193
-		) ) ];
193
+		))];
194 194
 	}
195 195
 
196 196
 	/**
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
 	 * @param string|null $role one of the Role::* constants
199 199
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
200 200
 	 */
201
-	private function renderEntityIdList( array $entityIdList, ?string $role ): array {
202
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
201
+	private function renderEntityIdList(array $entityIdList, ?string $role): array {
202
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
203 203
 	}
204 204
 
205 205
 	/**
@@ -207,24 +207,24 @@  discard block
 block discarded – undo
207 207
 	 * @param string|null $role one of the Role::* constants
208 208
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
209 209
 	 */
210
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, ?string $role ): array {
211
-		switch ( true ) {
210
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, ?string $role): array {
211
+		switch (true) {
212 212
 			case $value->isValue():
213
-				return $this->renderEntityId( $value->getItemId(), $role );
213
+				return $this->renderEntityId($value->getItemId(), $role);
214 214
 			case $value->isSomeValue():
215
-				return [ Message::rawParam( $this->addRole(
216
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
217
-						$this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) .
215
+				return [Message::rawParam($this->addRole(
216
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
217
+						$this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue').
218 218
 						'</span>',
219 219
 					$role
220
-				) ) ];
220
+				))];
221 221
 			case $value->isNoValue():
222
-				return [ Message::rawParam( $this->addRole(
223
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
224
-					$this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) .
222
+				return [Message::rawParam($this->addRole(
223
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
224
+					$this->msgEscaped('wikibase-snakview-snaktypeselector-novalue').
225 225
 						'</span>',
226 226
 					$role
227
-				) ) ];
227
+				))];
228 228
 			default:
229 229
 				// @codeCoverageIgnoreStart
230 230
 				throw new LogicException(
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
 	 * @param string|null $role one of the Role::* constants
240 240
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
241 241
 	 */
242
-	private function renderItemIdSnakValueList( array $valueList, ?string $role ): array {
243
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
242
+	private function renderItemIdSnakValueList(array $valueList, ?string $role): array {
243
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
244 244
 	}
245 245
 
246 246
 	/**
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
 	 * @param string|null $role one of the Role::* constants
249 249
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
250 250
 	 */
251
-	private function renderDataValue( DataValue $dataValue, ?string $role ): array {
252
-		return [ Message::rawParam( $this->addRole(
253
-			$this->dataValueFormatter->format( $dataValue ),
251
+	private function renderDataValue(DataValue $dataValue, ?string $role): array {
252
+		return [Message::rawParam($this->addRole(
253
+			$this->dataValueFormatter->format($dataValue),
254 254
 			$role
255
-		) ) ];
255
+		))];
256 256
 	}
257 257
 
258 258
 	/**
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * @param string|null $role one of the Role::* constants
261 261
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
262 262
 	 */
263
-	private function renderDataValueType( string $dataValueType, ?string $role ): array {
263
+	private function renderDataValueType(string $dataValueType, ?string $role): array {
264 264
 		$messageKeys = [
265 265
 			'string' => 'datatypes-type-string',
266 266
 			'monolingualtext' => 'datatypes-type-monolingualtext',
@@ -269,15 +269,15 @@  discard block
 block discarded – undo
269 269
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
270 270
 		];
271 271
 
272
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
273
-			return [ Message::rawParam( $this->addRole(
274
-				$this->msgEscaped( $messageKeys[$dataValueType] ),
272
+		if (array_key_exists($dataValueType, $messageKeys)) {
273
+			return [Message::rawParam($this->addRole(
274
+				$this->msgEscaped($messageKeys[$dataValueType]),
275 275
 				$role
276
-			) ) ];
276
+			))];
277 277
 		} else {
278 278
 			// @codeCoverageIgnoreStart
279 279
 			throw new LogicException(
280
-				'Unknown data value type ' . $dataValueType
280
+				'Unknown data value type '.$dataValueType
281 281
 			);
282 282
 			// @codeCoverageIgnoreEnd
283 283
 		}
@@ -288,11 +288,11 @@  discard block
 block discarded – undo
288 288
 	 * @param string|null $role one of the Role::* constants
289 289
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
290 290
 	 */
291
-	private function renderInlineCode( string $code, ?string $role ): array {
292
-		return [ Message::rawParam( $this->addRole(
293
-			'<code>' . htmlspecialchars( $code ) . '</code>',
291
+	private function renderInlineCode(string $code, ?string $role): array {
292
+		return [Message::rawParam($this->addRole(
293
+			'<code>'.htmlspecialchars($code).'</code>',
294 294
 			$role
295
-		) ) ];
295
+		))];
296 296
 	}
297 297
 
298 298
 	/**
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	 * @param string|null $role one of the Role::* constants
301 301
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
302 302
 	 */
303
-	private function renderConstraintScope( string $scope, ?string $role ): array {
304
-		switch ( $scope ) {
303
+	private function renderConstraintScope(string $scope, ?string $role): array {
304
+		switch ($scope) {
305 305
 			case Context::TYPE_STATEMENT:
306 306
 				$itemId = $this->config->get(
307 307
 					'WBQualityConstraintsConstraintCheckedOnMainValueId'
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
 				// callers should never let this happen, but if it does happen,
322 322
 				// showing “unknown value” seems reasonable
323 323
 				// @codeCoverageIgnoreStart
324
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
324
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
325 325
 				// @codeCoverageIgnoreEnd
326 326
 		}
327
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
327
+		return $this->renderEntityId(new ItemId($itemId), $role);
328 328
 	}
329 329
 
330 330
 	/**
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
 	 * @param string|null $role one of the Role::* constants
333 333
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
334 334
 	 */
335
-	private function renderConstraintScopeList( array $scopeList, ?string $role ): array {
336
-		return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] );
335
+	private function renderConstraintScopeList(array $scopeList, ?string $role): array {
336
+		return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']);
337 337
 	}
338 338
 
339 339
 	/**
@@ -341,25 +341,25 @@  discard block
 block discarded – undo
341 341
 	 * @param string|null $role one of the Role::* constants
342 342
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
343 343
 	 */
344
-	private function renderPropertyScope( string $scope, ?string $role ): array {
345
-		switch ( $scope ) {
344
+	private function renderPropertyScope(string $scope, ?string $role): array {
345
+		switch ($scope) {
346 346
 			case Context::TYPE_STATEMENT:
347
-				$itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' );
347
+				$itemId = $this->config->get('WBQualityConstraintsAsMainValueId');
348 348
 				break;
349 349
 			case Context::TYPE_QUALIFIER:
350
-				$itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' );
350
+				$itemId = $this->config->get('WBQualityConstraintsAsQualifiersId');
351 351
 				break;
352 352
 			case Context::TYPE_REFERENCE:
353
-				$itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' );
353
+				$itemId = $this->config->get('WBQualityConstraintsAsReferencesId');
354 354
 				break;
355 355
 			default:
356 356
 				// callers should never let this happen, but if it does happen,
357 357
 				// showing “unknown value” seems reasonable
358 358
 				// @codeCoverageIgnoreStart
359
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
359
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
360 360
 				// @codeCoverageIgnoreEnd
361 361
 		}
362
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
362
+		return $this->renderEntityId(new ItemId($itemId), $role);
363 363
 	}
364 364
 
365 365
 	/**
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
 	 * @param string|null $role one of the Role::* constants
368 368
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
369 369
 	 */
370
-	private function renderPropertyScopeList( array $scopeList, ?string $role ): array {
371
-		return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] );
370
+	private function renderPropertyScopeList(array $scopeList, ?string $role): array {
371
+		return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']);
372 372
 	}
373 373
 
374 374
 	/**
@@ -377,14 +377,14 @@  discard block
 block discarded – undo
377 377
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
378 378
 	 * @suppress PhanUnusedPrivateMethodParameter
379 379
 	 */
380
-	private function renderLanguage( string $languageCode, ?string $role ): array {
380
+	private function renderLanguage(string $languageCode, ?string $role): array {
381 381
 		return [
382 382
 			// ::renderList (through ::renderLanguageList) requires 'raw' parameter
383 383
 			// so we effectively build Message::plaintextParam here
384
-			Message::rawParam( htmlspecialchars(
385
-				$this->languageNameUtils->getLanguageName( $languageCode, $this->userLanguageCode )
386
-			) ),
387
-			Message::plaintextParam( $languageCode ),
384
+			Message::rawParam(htmlspecialchars(
385
+				$this->languageNameUtils->getLanguageName($languageCode, $this->userLanguageCode)
386
+			)),
387
+			Message::plaintextParam($languageCode),
388 388
 		];
389 389
 	}
390 390
 
@@ -393,8 +393,8 @@  discard block
 block discarded – undo
393 393
 	 * @param string|null $role one of the Role::* constants
394 394
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
395 395
 	 */
396
-	private function renderLanguageList( array $languageCodes, ?string $role ): array {
397
-		return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] );
396
+	private function renderLanguageList(array $languageCodes, ?string $role): array {
397
+		return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']);
398 398
 	}
399 399
 
400 400
 }
Please login to merge, or discard this patch.