Completed
Push — master ( 81bc73...e04296 )
by
unknown
21s
created
src/ConstraintCheck/Message/MultilingualTextViolationMessageRenderer.php 1 patch
Spacing   +21 added lines, -21 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
 
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 		'wbqc-violation-message-format-clarification' => 'wbqc-violation-message-format',
29 29
 	];
30 30
 
31
-	public function render( ViolationMessage $violationMessage ): string {
32
-		if ( !array_key_exists( $violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS ) ) {
33
-			return parent::render( $violationMessage );
31
+	public function render(ViolationMessage $violationMessage): string {
32
+		if (!array_key_exists($violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS)) {
33
+			return parent::render($violationMessage);
34 34
 		}
35 35
 
36 36
 		$arguments = $violationMessage->getArguments();
37
-		$multilingualTextArgument = array_pop( $arguments );
37
+		$multilingualTextArgument = array_pop($arguments);
38 38
 		$multilingualTextParams = $this->renderMultilingualText(
39 39
 			// @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue
40 40
 			$multilingualTextArgument['value'],
@@ -42,22 +42,22 @@  discard block
 block discarded – undo
42 42
 			$multilingualTextArgument['role']
43 43
 		);
44 44
 
45
-		$paramsLists = [ [] ];
46
-		foreach ( $arguments as $argument ) {
47
-			$paramsLists[] = $this->renderArgument( $argument );
45
+		$paramsLists = [[]];
46
+		foreach ($arguments as $argument) {
47
+			$paramsLists[] = $this->renderArgument($argument);
48 48
 		}
49
-		$regularParams = call_user_func_array( 'array_merge', $paramsLists );
49
+		$regularParams = call_user_func_array('array_merge', $paramsLists);
50 50
 
51
-		if ( $multilingualTextParams === null ) {
51
+		if ($multilingualTextParams === null) {
52 52
 			return $this->messageLocalizer
53
-				->msg( self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()] )
54
-				->params( $regularParams )
53
+				->msg(self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()])
54
+				->params($regularParams)
55 55
 				->escaped();
56 56
 		} else {
57 57
 			return $this->messageLocalizer
58
-				->msg( $violationMessage->getMessageKey() )
59
-				->params( $regularParams )
60
-				->params( $multilingualTextParams )
58
+				->msg($violationMessage->getMessageKey())
59
+				->params($regularParams)
60
+				->params($multilingualTextParams)
61 61
 				->escaped();
62 62
 		}
63 63
 	}
@@ -68,14 +68,14 @@  discard block
 block discarded – undo
68 68
 	 * @return MessageParam[]|null list of parameters as accepted by Message::params(),
69 69
 	 * or null if the text is not available in the user’s language
70 70
 	 */
71
-	protected function renderMultilingualText( MultilingualTextValue $text, ?string $role ): ?array {
71
+	protected function renderMultilingualText(MultilingualTextValue $text, ?string $role): ?array {
72 72
 		$texts = $text->getTexts();
73
-		foreach ( $this->languageFallbackChain->getFetchLanguageCodes() as $languageCode ) {
74
-			if ( array_key_exists( $languageCode, $texts ) ) {
75
-				return [ Message::rawParam( $this->addRole(
76
-					htmlspecialchars( $texts[$languageCode]->getText() ),
73
+		foreach ($this->languageFallbackChain->getFetchLanguageCodes() as $languageCode) {
74
+			if (array_key_exists($languageCode, $texts)) {
75
+				return [Message::rawParam($this->addRole(
76
+					htmlspecialchars($texts[$languageCode]->getText()),
77 77
 					$role
78
-				) ) ];
78
+				))];
79 79
 			}
80 80
 		}
81 81
 
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +87 added lines, -87 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
 
@@ -67,17 +67,17 @@  discard block
 block discarded – undo
67 67
 		$this->maxListLength = $maxListLength;
68 68
 	}
69 69
 
70
-	public function render( ViolationMessage $violationMessage ): string {
70
+	public function render(ViolationMessage $violationMessage): string {
71 71
 		$messageKey = $violationMessage->getMessageKey();
72
-		$paramsLists = [ [] ];
73
-		foreach ( $violationMessage->getArguments() as $argument ) {
74
-			$params = $this->renderArgument( $argument );
72
+		$paramsLists = [[]];
73
+		foreach ($violationMessage->getArguments() as $argument) {
74
+			$params = $this->renderArgument($argument);
75 75
 			$paramsLists[] = $params;
76 76
 		}
77
-		$allParams = call_user_func_array( 'array_merge', $paramsLists );
77
+		$allParams = call_user_func_array('array_merge', $paramsLists);
78 78
 		return $this->messageLocalizer
79
-			->msg( $messageKey )
80
-			->params( $allParams )
79
+			->msg($messageKey)
80
+			->params($allParams)
81 81
 			->escaped();
82 82
 	}
83 83
 
@@ -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,36 +148,36 @@  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
-		if ( count( $list ) > $this->maxListLength ) {
160
-			$list = array_slice( $list, 0, $this->maxListLength );
159
+		if (count($list) > $this->maxListLength) {
160
+			$list = array_slice($list, 0, $this->maxListLength);
161 161
 			$truncated = true;
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( fn ( MessageParam $msg ) => $msg->getValue(), $renderedParams );
171
-		if ( isset( $truncated ) ) {
172
-			$renderedElements[] = $this->msgEscaped( 'ellipsis' );
169
+		$renderedParams = array_column($renderedParamsLists, 0);
170
+		$renderedElements = array_map(fn (MessageParam $msg) => $msg->getValue(), $renderedParams);
171
+		if (isset($truncated)) {
172
+			$renderedElements[] = $this->msgEscaped('ellipsis');
173 173
 		}
174 174
 
175 175
 		return array_merge(
176 176
 			[
177
-				Message::numParam( count( $list ) ),
177
+				Message::numParam(count($list)),
178 178
 				Message::rawParam(
179
-					'<ul><li>' .
180
-					implode( '</li><li>', $renderedElements ) .
179
+					'<ul><li>'.
180
+					implode('</li><li>', $renderedElements).
181 181
 					'</li></ul>'
182 182
 				),
183 183
 			],
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
 	 * @param string|null $role one of the Role::* constants
191 191
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
192 192
 	 */
193
-	private function renderEntityId( EntityId $entityId, ?string $role ): array {
194
-		return [ Message::rawParam( $this->addRole(
195
-			$this->entityIdFormatter->formatEntityId( $entityId ),
193
+	private function renderEntityId(EntityId $entityId, ?string $role): array {
194
+		return [Message::rawParam($this->addRole(
195
+			$this->entityIdFormatter->formatEntityId($entityId),
196 196
 			$role
197
-		) ) ];
197
+		))];
198 198
 	}
199 199
 
200 200
 	/**
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 	 * @param string|null $role one of the Role::* constants
203 203
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
204 204
 	 */
205
-	private function renderEntityIdList( array $entityIdList, ?string $role ): array {
206
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
205
+	private function renderEntityIdList(array $entityIdList, ?string $role): array {
206
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
207 207
 	}
208 208
 
209 209
 	/**
@@ -211,24 +211,24 @@  discard block
 block discarded – undo
211 211
 	 * @param string|null $role one of the Role::* constants
212 212
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
213 213
 	 */
214
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, ?string $role ): array {
215
-		switch ( true ) {
214
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, ?string $role): array {
215
+		switch (true) {
216 216
 			case $value->isValue():
217
-				return $this->renderEntityId( $value->getItemId(), $role );
217
+				return $this->renderEntityId($value->getItemId(), $role);
218 218
 			case $value->isSomeValue():
219
-				return [ Message::rawParam( $this->addRole(
220
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
221
-						$this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) .
219
+				return [Message::rawParam($this->addRole(
220
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
221
+						$this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue').
222 222
 						'</span>',
223 223
 					$role
224
-				) ) ];
224
+				))];
225 225
 			case $value->isNoValue():
226
-				return [ Message::rawParam( $this->addRole(
227
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
228
-					$this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) .
226
+				return [Message::rawParam($this->addRole(
227
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
228
+					$this->msgEscaped('wikibase-snakview-snaktypeselector-novalue').
229 229
 						'</span>',
230 230
 					$role
231
-				) ) ];
231
+				))];
232 232
 			default:
233 233
 				// @codeCoverageIgnoreStart
234 234
 				throw new LogicException(
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
 	 * @param string|null $role one of the Role::* constants
244 244
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
245 245
 	 */
246
-	private function renderItemIdSnakValueList( array $valueList, ?string $role ): array {
247
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
246
+	private function renderItemIdSnakValueList(array $valueList, ?string $role): array {
247
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
248 248
 	}
249 249
 
250 250
 	/**
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
 	 * @param string|null $role one of the Role::* constants
253 253
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
254 254
 	 */
255
-	private function renderDataValue( DataValue $dataValue, ?string $role ): array {
256
-		return [ Message::rawParam( $this->addRole(
257
-			$this->dataValueFormatter->format( $dataValue ),
255
+	private function renderDataValue(DataValue $dataValue, ?string $role): array {
256
+		return [Message::rawParam($this->addRole(
257
+			$this->dataValueFormatter->format($dataValue),
258 258
 			$role
259
-		) ) ];
259
+		))];
260 260
 	}
261 261
 
262 262
 	/**
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	 * @param string|null $role one of the Role::* constants
265 265
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
266 266
 	 */
267
-	private function renderDataValueType( string $dataValueType, ?string $role ): array {
267
+	private function renderDataValueType(string $dataValueType, ?string $role): array {
268 268
 		$messageKeys = [
269 269
 			'string' => 'datatypes-type-string',
270 270
 			'monolingualtext' => 'datatypes-type-monolingualtext',
@@ -273,15 +273,15 @@  discard block
 block discarded – undo
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
-				$this->msgEscaped( $messageKeys[$dataValueType] ),
276
+		if (array_key_exists($dataValueType, $messageKeys)) {
277
+			return [Message::rawParam($this->addRole(
278
+				$this->msgEscaped($messageKeys[$dataValueType]),
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 MessageParam[] list of parameters as accepted by Message::params()
294 294
 	 */
295
-	private function renderInlineCode( string $code, ?string $role ): array {
296
-		return [ Message::rawParam( $this->addRole(
297
-			'<code>' . htmlspecialchars( $code ) . '</code>',
295
+	private function renderInlineCode(string $code, ?string $role): array {
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 MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
306 306
 	 */
307
-	private function renderConstraintScope( string $scope, ?string $role ): array {
308
-		switch ( $scope ) {
307
+	private function renderConstraintScope(string $scope, ?string $role): array {
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 MessageParam[] list of parameters as accepted by Message::params()
338 338
 	 */
339
-	private function renderConstraintScopeList( array $scopeList, ?string $role ): array {
340
-		return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] );
339
+	private function renderConstraintScopeList(array $scopeList, ?string $role): array {
340
+		return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']);
341 341
 	}
342 342
 
343 343
 	/**
@@ -345,25 +345,25 @@  discard block
 block discarded – undo
345 345
 	 * @param string|null $role one of the Role::* constants
346 346
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
347 347
 	 */
348
-	private function renderPropertyScope( string $scope, ?string $role ): array {
349
-		switch ( $scope ) {
348
+	private function renderPropertyScope(string $scope, ?string $role): array {
349
+		switch ($scope) {
350 350
 			case Context::TYPE_STATEMENT:
351
-				$itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' );
351
+				$itemId = $this->config->get('WBQualityConstraintsAsMainValueId');
352 352
 				break;
353 353
 			case Context::TYPE_QUALIFIER:
354
-				$itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' );
354
+				$itemId = $this->config->get('WBQualityConstraintsAsQualifiersId');
355 355
 				break;
356 356
 			case Context::TYPE_REFERENCE:
357
-				$itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' );
357
+				$itemId = $this->config->get('WBQualityConstraintsAsReferencesId');
358 358
 				break;
359 359
 			default:
360 360
 				// callers should never let this happen, but if it does happen,
361 361
 				// showing “unknown value” seems reasonable
362 362
 				// @codeCoverageIgnoreStart
363
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
363
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
364 364
 				// @codeCoverageIgnoreEnd
365 365
 		}
366
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
366
+		return $this->renderEntityId(new ItemId($itemId), $role);
367 367
 	}
368 368
 
369 369
 	/**
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 	 * @param string|null $role one of the Role::* constants
372 372
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
373 373
 	 */
374
-	private function renderPropertyScopeList( array $scopeList, ?string $role ): array {
375
-		return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] );
374
+	private function renderPropertyScopeList(array $scopeList, ?string $role): array {
375
+		return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']);
376 376
 	}
377 377
 
378 378
 	/**
@@ -380,14 +380,14 @@  discard block
 block discarded – undo
380 380
 	 * @param string|null $role one of the Role::* constants
381 381
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
382 382
 	 */
383
-	private function renderLanguage( string $languageCode, ?string $role ): array {
383
+	private function renderLanguage(string $languageCode, ?string $role): array {
384 384
 		return [
385 385
 			// ::renderList (through ::renderLanguageList) requires 'raw' parameter
386 386
 			// so we effectively build Message::plaintextParam here
387
-			Message::rawParam( htmlspecialchars(
388
-				$this->languageNameUtils->getLanguageName( $languageCode, $this->userLanguageCode )
389
-			) ),
390
-			Message::plaintextParam( $languageCode ),
387
+			Message::rawParam(htmlspecialchars(
388
+				$this->languageNameUtils->getLanguageName($languageCode, $this->userLanguageCode)
389
+			)),
390
+			Message::plaintextParam($languageCode),
391 391
 		];
392 392
 	}
393 393
 
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
 	 * @param string|null $role one of the Role::* constants
397 397
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
398 398
 	 */
399
-	private function renderLanguageList( array $languageCodes, ?string $role ): array {
400
-		return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] );
399
+	private function renderLanguageList(array $languageCodes, ?string $role): array {
400
+		return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']);
401 401
 	}
402 402
 
403 403
 }
Please login to merge, or discard this patch.