@@ -77,17 +77,17 @@ discard block |
||
| 77 | 77 | * @param ViolationMessage $violationMessage |
| 78 | 78 | * @return string |
| 79 | 79 | */ |
| 80 | - public function render( ViolationMessage $violationMessage ) { |
|
| 80 | + public function render(ViolationMessage $violationMessage) { |
|
| 81 | 81 | $messageKey = $violationMessage->getMessageKey(); |
| 82 | - $paramsLists = [ [] ]; |
|
| 83 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
| 84 | - $params = $this->renderArgument( $argument ); |
|
| 82 | + $paramsLists = [[]]; |
|
| 83 | + foreach ($violationMessage->getArguments() as $argument) { |
|
| 84 | + $params = $this->renderArgument($argument); |
|
| 85 | 85 | $paramsLists[] = $params; |
| 86 | 86 | } |
| 87 | - $allParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
| 87 | + $allParams = call_user_func_array('array_merge', $paramsLists); |
|
| 88 | 88 | return $this->messageLocalizer |
| 89 | - ->msg( $messageKey ) |
|
| 90 | - ->params( $allParams ) |
|
| 89 | + ->msg($messageKey) |
|
| 90 | + ->params($allParams) |
|
| 91 | 91 | ->escaped(); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -96,13 +96,13 @@ discard block |
||
| 96 | 96 | * @param string|null $role one of the Role::* constants |
| 97 | 97 | * @return string HTML |
| 98 | 98 | */ |
| 99 | - protected function addRole( $value, $role ) { |
|
| 100 | - if ( $role === null ) { |
|
| 99 | + protected function addRole($value, $role) { |
|
| 100 | + if ($role === null) { |
|
| 101 | 101 | return $value; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
| 105 | - $value . |
|
| 104 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
| 105 | + $value. |
|
| 106 | 106 | '</span>'; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | * @param string $key message key |
| 111 | 111 | * @return string HTML |
| 112 | 112 | */ |
| 113 | - protected function msgEscaped( $key ) { |
|
| 114 | - return $this->messageLocalizer->msg( $key )->escaped(); |
|
| 113 | + protected function msgEscaped($key) { |
|
| 114 | + return $this->messageLocalizer->msg($key)->escaped(); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * @param array $argument |
| 119 | 119 | * @return array[] params (for Message::params) |
| 120 | 120 | */ |
| 121 | - protected function renderArgument( array $argument ) { |
|
| 121 | + protected function renderArgument(array $argument) { |
|
| 122 | 122 | $methods = [ |
| 123 | 123 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
| 124 | 124 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | $value = $argument['value']; |
| 140 | 140 | $role = $argument['role']; |
| 141 | 141 | |
| 142 | - if ( array_key_exists( $type, $methods ) ) { |
|
| 142 | + if (array_key_exists($type, $methods)) { |
|
| 143 | 143 | $method = $methods[$type]; |
| 144 | - $params = $this->$method( $value, $role ); |
|
| 144 | + $params = $this->$method($value, $role); |
|
| 145 | 145 | } else { |
| 146 | 146 | throw new InvalidArgumentException( |
| 147 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
| 147 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -158,36 +158,36 @@ discard block |
||
| 158 | 158 | * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ]) |
| 159 | 159 | * @return array[] list of parameters as accepted by Message::params() |
| 160 | 160 | */ |
| 161 | - private function renderList( array $list, $role, callable $render ) { |
|
| 162 | - if ( $list === [] ) { |
|
| 161 | + private function renderList(array $list, $role, callable $render) { |
|
| 162 | + if ($list === []) { |
|
| 163 | 163 | return [ |
| 164 | - Message::numParam( 0 ), |
|
| 165 | - Message::rawParam( '<ul></ul>' ), |
|
| 164 | + Message::numParam(0), |
|
| 165 | + Message::rawParam('<ul></ul>'), |
|
| 166 | 166 | ]; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ( count( $list ) > $this->maxListLength ) { |
|
| 170 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
| 169 | + if (count($list) > $this->maxListLength) { |
|
| 170 | + $list = array_slice($list, 0, $this->maxListLength); |
|
| 171 | 171 | $truncated = true; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $renderedParamsLists = array_map( |
| 175 | 175 | $render, |
| 176 | 176 | $list, |
| 177 | - array_fill( 0, count( $list ), $role ) |
|
| 177 | + array_fill(0, count($list), $role) |
|
| 178 | 178 | ); |
| 179 | - $renderedParams = array_column( $renderedParamsLists, 0 ); |
|
| 180 | - $renderedElements = array_column( $renderedParams, 'raw' ); |
|
| 181 | - if ( isset( $truncated ) ) { |
|
| 182 | - $renderedElements[] = $this->msgEscaped( 'ellipsis' ); |
|
| 179 | + $renderedParams = array_column($renderedParamsLists, 0); |
|
| 180 | + $renderedElements = array_column($renderedParams, 'raw'); |
|
| 181 | + if (isset($truncated)) { |
|
| 182 | + $renderedElements[] = $this->msgEscaped('ellipsis'); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return array_merge( |
| 186 | 186 | [ |
| 187 | - Message::numParam( count( $list ) ), |
|
| 187 | + Message::numParam(count($list)), |
|
| 188 | 188 | Message::rawParam( |
| 189 | - '<ul><li>' . |
|
| 190 | - implode( '</li><li>', $renderedElements ) . |
|
| 189 | + '<ul><li>'. |
|
| 190 | + implode('</li><li>', $renderedElements). |
|
| 191 | 191 | '</li></ul>' |
| 192 | 192 | ), |
| 193 | 193 | ], |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | * @param string|null $role one of the Role::* constants |
| 201 | 201 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
| 202 | 202 | */ |
| 203 | - private function renderEntityId( EntityId $entityId, $role ) { |
|
| 204 | - return [ Message::rawParam( $this->addRole( |
|
| 205 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
| 203 | + private function renderEntityId(EntityId $entityId, $role) { |
|
| 204 | + return [Message::rawParam($this->addRole( |
|
| 205 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
| 206 | 206 | $role |
| 207 | - ) ) ]; |
|
| 207 | + ))]; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @param string|null $role one of the Role::* constants |
| 213 | 213 | * @return array[] list of parameters as accepted by Message::params() |
| 214 | 214 | */ |
| 215 | - private function renderEntityIdList( array $entityIdList, $role ) { |
|
| 216 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
| 215 | + private function renderEntityIdList(array $entityIdList, $role) { |
|
| 216 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -221,24 +221,24 @@ discard block |
||
| 221 | 221 | * @param string|null $role one of the Role::* constants |
| 222 | 222 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
| 223 | 223 | */ |
| 224 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) { |
|
| 225 | - switch ( true ) { |
|
| 224 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) { |
|
| 225 | + switch (true) { |
|
| 226 | 226 | case $value->isValue(): |
| 227 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
| 227 | + return $this->renderEntityId($value->getItemId(), $role); |
|
| 228 | 228 | case $value->isSomeValue(): |
| 229 | - return [ Message::rawParam( $this->addRole( |
|
| 230 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
| 231 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) . |
|
| 229 | + return [Message::rawParam($this->addRole( |
|
| 230 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
| 231 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue'). |
|
| 232 | 232 | '</span>', |
| 233 | 233 | $role |
| 234 | - ) ) ]; |
|
| 234 | + ))]; |
|
| 235 | 235 | case $value->isNoValue(): |
| 236 | - return [ Message::rawParam( $this->addRole( |
|
| 237 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
| 238 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) . |
|
| 236 | + return [Message::rawParam($this->addRole( |
|
| 237 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
| 238 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-novalue'). |
|
| 239 | 239 | '</span>', |
| 240 | 240 | $role |
| 241 | - ) ) ]; |
|
| 241 | + ))]; |
|
| 242 | 242 | default: |
| 243 | 243 | // @codeCoverageIgnoreStart |
| 244 | 244 | throw new LogicException( |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * @param string|null $role one of the Role::* constants |
| 254 | 254 | * @return array[] list of parameters as accepted by Message::params() |
| 255 | 255 | */ |
| 256 | - private function renderItemIdSnakValueList( array $valueList, $role ) { |
|
| 257 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
| 256 | + private function renderItemIdSnakValueList(array $valueList, $role) { |
|
| 257 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -262,11 +262,11 @@ discard block |
||
| 262 | 262 | * @param string|null $role one of the Role::* constants |
| 263 | 263 | * @return array[] list of parameters as accepted by Message::params() |
| 264 | 264 | */ |
| 265 | - private function renderDataValue( DataValue $dataValue, $role ) { |
|
| 266 | - return [ Message::rawParam( $this->addRole( |
|
| 267 | - $this->dataValueFormatter->format( $dataValue ), |
|
| 265 | + private function renderDataValue(DataValue $dataValue, $role) { |
|
| 266 | + return [Message::rawParam($this->addRole( |
|
| 267 | + $this->dataValueFormatter->format($dataValue), |
|
| 268 | 268 | $role |
| 269 | - ) ) ]; |
|
| 269 | + ))]; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @param string|null $role one of the Role::* constants |
| 275 | 275 | * @return array[] list of parameters as accepted by Message::params() |
| 276 | 276 | */ |
| 277 | - private function renderDataValueType( $dataValueType, $role ) { |
|
| 277 | + private function renderDataValueType($dataValueType, $role) { |
|
| 278 | 278 | $messageKeys = [ |
| 279 | 279 | 'string' => 'datatypes-type-string', |
| 280 | 280 | 'monolingualtext' => 'datatypes-type-monolingualtext', |
@@ -283,15 +283,15 @@ discard block |
||
| 283 | 283 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
| 284 | 284 | ]; |
| 285 | 285 | |
| 286 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
| 287 | - return [ Message::rawParam( $this->addRole( |
|
| 288 | - $this->msgEscaped( $messageKeys[$dataValueType] ), |
|
| 286 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
| 287 | + return [Message::rawParam($this->addRole( |
|
| 288 | + $this->msgEscaped($messageKeys[$dataValueType]), |
|
| 289 | 289 | $role |
| 290 | - ) ) ]; |
|
| 290 | + ))]; |
|
| 291 | 291 | } else { |
| 292 | 292 | // @codeCoverageIgnoreStart |
| 293 | 293 | throw new LogicException( |
| 294 | - 'Unknown data value type ' . $dataValueType |
|
| 294 | + 'Unknown data value type '.$dataValueType |
|
| 295 | 295 | ); |
| 296 | 296 | // @codeCoverageIgnoreEnd |
| 297 | 297 | } |
@@ -302,11 +302,11 @@ discard block |
||
| 302 | 302 | * @param string|null $role one of the Role::* constants |
| 303 | 303 | * @return array[] list of parameters as accepted by Message::params() |
| 304 | 304 | */ |
| 305 | - private function renderInlineCode( $code, $role ) { |
|
| 306 | - return [ Message::rawParam( $this->addRole( |
|
| 307 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
| 305 | + private function renderInlineCode($code, $role) { |
|
| 306 | + return [Message::rawParam($this->addRole( |
|
| 307 | + '<code>'.htmlspecialchars($code).'</code>', |
|
| 308 | 308 | $role |
| 309 | - ) ) ]; |
|
| 309 | + ))]; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | * @param string|null $role one of the Role::* constants |
| 315 | 315 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
| 316 | 316 | */ |
| 317 | - private function renderConstraintScope( $scope, $role ) { |
|
| 318 | - switch ( $scope ) { |
|
| 317 | + private function renderConstraintScope($scope, $role) { |
|
| 318 | + switch ($scope) { |
|
| 319 | 319 | case Context::TYPE_STATEMENT: |
| 320 | 320 | $itemId = $this->config->get( |
| 321 | 321 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -335,10 +335,10 @@ discard block |
||
| 335 | 335 | // callers should never let this happen, but if it does happen, |
| 336 | 336 | // showing “unknown value” seems reasonable |
| 337 | 337 | // @codeCoverageIgnoreStart |
| 338 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
| 338 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
| 339 | 339 | // @codeCoverageIgnoreEnd |
| 340 | 340 | } |
| 341 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
| 341 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -346,8 +346,8 @@ discard block |
||
| 346 | 346 | * @param string|null $role one of the Role::* constants |
| 347 | 347 | * @return array[] list of parameters as accepted by Message::params() |
| 348 | 348 | */ |
| 349 | - private function renderConstraintScopeList( array $scopeList, $role ) { |
|
| 350 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
| 349 | + private function renderConstraintScopeList(array $scopeList, $role) { |
|
| 350 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -355,25 +355,25 @@ discard block |
||
| 355 | 355 | * @param string|null $role one of the Role::* constants |
| 356 | 356 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
| 357 | 357 | */ |
| 358 | - private function renderPropertyScope( $scope, $role ) { |
|
| 359 | - switch ( $scope ) { |
|
| 358 | + private function renderPropertyScope($scope, $role) { |
|
| 359 | + switch ($scope) { |
|
| 360 | 360 | case Context::TYPE_STATEMENT: |
| 361 | - $itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
| 361 | + $itemId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
| 362 | 362 | break; |
| 363 | 363 | case Context::TYPE_QUALIFIER: |
| 364 | - $itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
| 364 | + $itemId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
| 365 | 365 | break; |
| 366 | 366 | case Context::TYPE_REFERENCE: |
| 367 | - $itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
| 367 | + $itemId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
| 368 | 368 | break; |
| 369 | 369 | default: |
| 370 | 370 | // callers should never let this happen, but if it does happen, |
| 371 | 371 | // showing “unknown value” seems reasonable |
| 372 | 372 | // @codeCoverageIgnoreStart |
| 373 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
| 373 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
| 374 | 374 | // @codeCoverageIgnoreEnd |
| 375 | 375 | } |
| 376 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
| 376 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | * @param string|null $role one of the Role::* constants |
| 382 | 382 | * @return array[] list of parameters as accepted by Message::params() |
| 383 | 383 | */ |
| 384 | - private function renderPropertyScopeList( array $scopeList, $role ) { |
|
| 385 | - return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] ); |
|
| 384 | + private function renderPropertyScopeList(array $scopeList, $role) { |
|
| 385 | + return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -390,12 +390,12 @@ 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 renderLanguage( $languageCode, $role ) { |
|
| 393 | + private function renderLanguage($languageCode, $role) { |
|
| 394 | 394 | return [ |
| 395 | 395 | // ::renderList (through ::renderLanguageList) requires 'raw' parameter |
| 396 | 396 | // so we effectively build Message::plaintextParam here |
| 397 | - Message::rawParam( htmlspecialchars( Language::fetchLanguageName( $languageCode ) ) ), |
|
| 398 | - Message::plaintextParam( $languageCode ), |
|
| 397 | + Message::rawParam(htmlspecialchars(Language::fetchLanguageName($languageCode))), |
|
| 398 | + Message::plaintextParam($languageCode), |
|
| 399 | 399 | ]; |
| 400 | 400 | } |
| 401 | 401 | |
@@ -404,8 +404,8 @@ discard block |
||
| 404 | 404 | * @param string|null $role one of the Role::* constants |
| 405 | 405 | * @return array[] list of parameters as accepted by Message::params() |
| 406 | 406 | */ |
| 407 | - private function renderLanguageList( $languageCodes, $role ) { |
|
| 408 | - return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] ); |
|
| 407 | + private function renderLanguageList($languageCodes, $role) { |
|
| 408 | + return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | } |