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