@@ -1,6 +1,6 @@ discard block |
||
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 | |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | $this->maxListLength = $maxListLength; |
63 | 63 | } |
64 | 64 | |
65 | - public function render( ViolationMessage $violationMessage ): string { |
|
65 | + public function render(ViolationMessage $violationMessage): string { |
|
66 | 66 | $messageKey = $violationMessage->getMessageKey(); |
67 | - $paramsLists = [ [] ]; |
|
68 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
69 | - $params = $this->renderArgument( $argument ); |
|
67 | + $paramsLists = [[]]; |
|
68 | + foreach ($violationMessage->getArguments() as $argument) { |
|
69 | + $params = $this->renderArgument($argument); |
|
70 | 70 | $paramsLists[] = $params; |
71 | 71 | } |
72 | - $allParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
72 | + $allParams = call_user_func_array('array_merge', $paramsLists); |
|
73 | 73 | return $this->messageLocalizer |
74 | - ->msg( $messageKey ) |
|
75 | - ->params( $allParams ) |
|
74 | + ->msg($messageKey) |
|
75 | + ->params($allParams) |
|
76 | 76 | ->escaped(); |
77 | 77 | } |
78 | 78 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param string|null $role one of the Role::* constants |
82 | 82 | * @return string HTML |
83 | 83 | */ |
84 | - protected function addRole( string $value, ?string $role ): string { |
|
85 | - if ( $role === null ) { |
|
84 | + protected function addRole(string $value, ?string $role): string { |
|
85 | + if ($role === null) { |
|
86 | 86 | return $value; |
87 | 87 | } |
88 | 88 | |
89 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
90 | - $value . |
|
89 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
90 | + $value. |
|
91 | 91 | '</span>'; |
92 | 92 | } |
93 | 93 | |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | * @param string $key message key |
96 | 96 | * @return string HTML |
97 | 97 | */ |
98 | - protected function msgEscaped( string $key ): string { |
|
99 | - return $this->messageLocalizer->msg( $key )->escaped(); |
|
98 | + protected function msgEscaped(string $key): string { |
|
99 | + return $this->messageLocalizer->msg($key)->escaped(); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @param array $argument |
104 | 104 | * @return array[] params (for Message::params) |
105 | 105 | */ |
106 | - protected function renderArgument( array $argument ): array { |
|
106 | + protected function renderArgument(array $argument): array { |
|
107 | 107 | $methods = [ |
108 | 108 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
109 | 109 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -124,12 +124,12 @@ discard block |
||
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,36 +143,36 @@ discard block |
||
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, ?string $role, callable $render ): array { |
|
147 | - if ( $list === [] ) { |
|
146 | + private function renderList(array $list, ?string $role, callable $render): array { |
|
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 | - $renderedParams = array_column( $renderedParamsLists, 0 ); |
|
165 | - $renderedElements = array_column( $renderedParams, 'raw' ); |
|
166 | - if ( isset( $truncated ) ) { |
|
167 | - $renderedElements[] = $this->msgEscaped( 'ellipsis' ); |
|
164 | + $renderedParams = array_column($renderedParamsLists, 0); |
|
165 | + $renderedElements = array_column($renderedParams, 'raw'); |
|
166 | + if (isset($truncated)) { |
|
167 | + $renderedElements[] = $this->msgEscaped('ellipsis'); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return array_merge( |
171 | 171 | [ |
172 | - Message::numParam( count( $list ) ), |
|
172 | + Message::numParam(count($list)), |
|
173 | 173 | Message::rawParam( |
174 | - '<ul><li>' . |
|
175 | - implode( '</li><li>', $renderedElements ) . |
|
174 | + '<ul><li>'. |
|
175 | + implode('</li><li>', $renderedElements). |
|
176 | 176 | '</li></ul>' |
177 | 177 | ), |
178 | 178 | ], |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * @param string|null $role one of the Role::* constants |
186 | 186 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
187 | 187 | */ |
188 | - private function renderEntityId( EntityId $entityId, ?string $role ): array { |
|
189 | - return [ Message::rawParam( $this->addRole( |
|
190 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
188 | + private function renderEntityId(EntityId $entityId, ?string $role): array { |
|
189 | + return [Message::rawParam($this->addRole( |
|
190 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
191 | 191 | $role |
192 | - ) ) ]; |
|
192 | + ))]; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @param string|null $role one of the Role::* constants |
198 | 198 | * @return array[] list of parameters as accepted by Message::params() |
199 | 199 | */ |
200 | - private function renderEntityIdList( array $entityIdList, ?string $role ): array { |
|
201 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
200 | + private function renderEntityIdList(array $entityIdList, ?string $role): array { |
|
201 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -206,24 +206,24 @@ discard block |
||
206 | 206 | * @param string|null $role one of the Role::* constants |
207 | 207 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
208 | 208 | */ |
209 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, ?string $role ): array { |
|
210 | - switch ( true ) { |
|
209 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, ?string $role): array { |
|
210 | + switch (true) { |
|
211 | 211 | case $value->isValue(): |
212 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
212 | + return $this->renderEntityId($value->getItemId(), $role); |
|
213 | 213 | case $value->isSomeValue(): |
214 | - return [ Message::rawParam( $this->addRole( |
|
215 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
216 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) . |
|
214 | + return [Message::rawParam($this->addRole( |
|
215 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
216 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue'). |
|
217 | 217 | '</span>', |
218 | 218 | $role |
219 | - ) ) ]; |
|
219 | + ))]; |
|
220 | 220 | case $value->isNoValue(): |
221 | - return [ Message::rawParam( $this->addRole( |
|
222 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
223 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) . |
|
221 | + return [Message::rawParam($this->addRole( |
|
222 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
223 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-novalue'). |
|
224 | 224 | '</span>', |
225 | 225 | $role |
226 | - ) ) ]; |
|
226 | + ))]; |
|
227 | 227 | default: |
228 | 228 | // @codeCoverageIgnoreStart |
229 | 229 | throw new LogicException( |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | * @param string|null $role one of the Role::* constants |
239 | 239 | * @return array[] list of parameters as accepted by Message::params() |
240 | 240 | */ |
241 | - private function renderItemIdSnakValueList( array $valueList, ?string $role ): array { |
|
242 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
241 | + private function renderItemIdSnakValueList(array $valueList, ?string $role): array { |
|
242 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | * @param string|null $role one of the Role::* constants |
248 | 248 | * @return array[] list of parameters as accepted by Message::params() |
249 | 249 | */ |
250 | - private function renderDataValue( DataValue $dataValue, ?string $role ): array { |
|
251 | - return [ Message::rawParam( $this->addRole( |
|
252 | - $this->dataValueFormatter->format( $dataValue ), |
|
250 | + private function renderDataValue(DataValue $dataValue, ?string $role): array { |
|
251 | + return [Message::rawParam($this->addRole( |
|
252 | + $this->dataValueFormatter->format($dataValue), |
|
253 | 253 | $role |
254 | - ) ) ]; |
|
254 | + ))]; |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @param string|null $role one of the Role::* constants |
260 | 260 | * @return array[] list of parameters as accepted by Message::params() |
261 | 261 | */ |
262 | - private function renderDataValueType( string $dataValueType, ?string $role ): array { |
|
262 | + private function renderDataValueType(string $dataValueType, ?string $role): array { |
|
263 | 263 | $messageKeys = [ |
264 | 264 | 'string' => 'datatypes-type-string', |
265 | 265 | 'monolingualtext' => 'datatypes-type-monolingualtext', |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
269 | 269 | ]; |
270 | 270 | |
271 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
272 | - return [ Message::rawParam( $this->addRole( |
|
273 | - $this->msgEscaped( $messageKeys[$dataValueType] ), |
|
271 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
272 | + return [Message::rawParam($this->addRole( |
|
273 | + $this->msgEscaped($messageKeys[$dataValueType]), |
|
274 | 274 | $role |
275 | - ) ) ]; |
|
275 | + ))]; |
|
276 | 276 | } else { |
277 | 277 | // @codeCoverageIgnoreStart |
278 | 278 | throw new LogicException( |
279 | - 'Unknown data value type ' . $dataValueType |
|
279 | + 'Unknown data value type '.$dataValueType |
|
280 | 280 | ); |
281 | 281 | // @codeCoverageIgnoreEnd |
282 | 282 | } |
@@ -287,11 +287,11 @@ discard block |
||
287 | 287 | * @param string|null $role one of the Role::* constants |
288 | 288 | * @return array[] list of parameters as accepted by Message::params() |
289 | 289 | */ |
290 | - private function renderInlineCode( string $code, ?string $role ): array { |
|
291 | - return [ Message::rawParam( $this->addRole( |
|
292 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
290 | + private function renderInlineCode(string $code, ?string $role): array { |
|
291 | + return [Message::rawParam($this->addRole( |
|
292 | + '<code>'.htmlspecialchars($code).'</code>', |
|
293 | 293 | $role |
294 | - ) ) ]; |
|
294 | + ))]; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | * @param string|null $role one of the Role::* constants |
300 | 300 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
301 | 301 | */ |
302 | - private function renderConstraintScope( string $scope, ?string $role ): array { |
|
303 | - switch ( $scope ) { |
|
302 | + private function renderConstraintScope(string $scope, ?string $role): array { |
|
303 | + switch ($scope) { |
|
304 | 304 | case Context::TYPE_STATEMENT: |
305 | 305 | $itemId = $this->config->get( |
306 | 306 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -320,10 +320,10 @@ discard block |
||
320 | 320 | // callers should never let this happen, but if it does happen, |
321 | 321 | // showing “unknown value” seems reasonable |
322 | 322 | // @codeCoverageIgnoreStart |
323 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
323 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
324 | 324 | // @codeCoverageIgnoreEnd |
325 | 325 | } |
326 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
326 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | * @param string|null $role one of the Role::* constants |
332 | 332 | * @return array[] list of parameters as accepted by Message::params() |
333 | 333 | */ |
334 | - private function renderConstraintScopeList( array $scopeList, ?string $role ): array { |
|
335 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
334 | + private function renderConstraintScopeList(array $scopeList, ?string $role): array { |
|
335 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -340,25 +340,25 @@ discard block |
||
340 | 340 | * @param string|null $role one of the Role::* constants |
341 | 341 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
342 | 342 | */ |
343 | - private function renderPropertyScope( string $scope, ?string $role ): array { |
|
344 | - switch ( $scope ) { |
|
343 | + private function renderPropertyScope(string $scope, ?string $role): array { |
|
344 | + switch ($scope) { |
|
345 | 345 | case Context::TYPE_STATEMENT: |
346 | - $itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
346 | + $itemId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
347 | 347 | break; |
348 | 348 | case Context::TYPE_QUALIFIER: |
349 | - $itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
349 | + $itemId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
350 | 350 | break; |
351 | 351 | case Context::TYPE_REFERENCE: |
352 | - $itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
352 | + $itemId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
353 | 353 | break; |
354 | 354 | default: |
355 | 355 | // callers should never let this happen, but if it does happen, |
356 | 356 | // showing “unknown value” seems reasonable |
357 | 357 | // @codeCoverageIgnoreStart |
358 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
358 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
359 | 359 | // @codeCoverageIgnoreEnd |
360 | 360 | } |
361 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
361 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | * @param string|null $role one of the Role::* constants |
367 | 367 | * @return array[] list of parameters as accepted by Message::params() |
368 | 368 | */ |
369 | - private function renderPropertyScopeList( array $scopeList, ?string $role ): array { |
|
370 | - return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] ); |
|
369 | + private function renderPropertyScopeList(array $scopeList, ?string $role): array { |
|
370 | + return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -375,14 +375,14 @@ discard block |
||
375 | 375 | * @param string|null $role one of the Role::* constants |
376 | 376 | * @return array[] list of parameters as accepted by Message::params() |
377 | 377 | */ |
378 | - private function renderLanguage( string $languageCode, ?string $role ): array { |
|
378 | + private function renderLanguage(string $languageCode, ?string $role): array { |
|
379 | 379 | return [ |
380 | 380 | // ::renderList (through ::renderLanguageList) requires 'raw' parameter |
381 | 381 | // so we effectively build Message::plaintextParam here |
382 | - Message::rawParam( htmlspecialchars( |
|
383 | - $this->languageNameUtils->getLanguageName( $languageCode, $this->userLanguageCode ) |
|
384 | - ) ), |
|
385 | - Message::plaintextParam( $languageCode ), |
|
382 | + Message::rawParam(htmlspecialchars( |
|
383 | + $this->languageNameUtils->getLanguageName($languageCode, $this->userLanguageCode) |
|
384 | + )), |
|
385 | + Message::plaintextParam($languageCode), |
|
386 | 386 | ]; |
387 | 387 | } |
388 | 388 | |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | * @param string|null $role one of the Role::* constants |
392 | 392 | * @return array[] list of parameters as accepted by Message::params() |
393 | 393 | */ |
394 | - private function renderLanguageList( array $languageCodes, ?string $role ): array { |
|
395 | - return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] ); |
|
394 | + private function renderLanguageList(array $languageCodes, ?string $role): array { |
|
395 | + return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | } |
@@ -1,6 +1,6 @@ discard block |
||
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 | |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | ): ViolationMessageRenderer { |
42 | 42 | $userLanguageCode = $userLanguage->getCode(); |
43 | 43 | $formatterOptions = new FormatterOptions(); |
44 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $userLanguageCode ); |
|
44 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $userLanguageCode); |
|
45 | 45 | return new MultilingualTextViolationMessageRenderer( |
46 | 46 | $this->entityIdHtmlLinkFormatterFactory |
47 | - ->getEntityIdFormatter( $userLanguage ), |
|
47 | + ->getEntityIdFormatter($userLanguage), |
|
48 | 48 | $this->valueFormatterFactory |
49 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ), |
|
49 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions), |
|
50 | 50 | $this->languageNameUtils, |
51 | 51 | $userLanguageCode, |
52 | 52 | $messageLocalizer, |