@@ -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\Specials; |
| 6 | 6 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | Config $config, |
| 98 | 98 | IBufferingStatsdDataFactory $dataFactory |
| 99 | 99 | ) { |
| 100 | - parent::__construct( 'ConstraintReport' ); |
|
| 100 | + parent::__construct('ConstraintReport'); |
|
| 101 | 101 | |
| 102 | 102 | $this->entityLookup = $entityLookup; |
| 103 | 103 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $language = $this->getLanguage(); |
| 107 | 107 | |
| 108 | 108 | $formatterOptions = new FormatterOptions(); |
| 109 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
| 109 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
| 110 | 110 | $dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
| 111 | 111 | SnakFormatter::FORMAT_HTML, |
| 112 | 112 | $formatterOptions |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | ); |
| 131 | 131 | $this->violationMessageRenderer = $violationMessageRendererFactory->getViolationMessageRenderer( |
| 132 | 132 | $language, |
| 133 | - $languageFallbackChainFactory->newFromLanguage( $language ), |
|
| 133 | + $languageFallbackChainFactory->newFromLanguage($language), |
|
| 134 | 134 | $this->getContext() |
| 135 | 135 | ); |
| 136 | 136 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @return string |
| 166 | 166 | */ |
| 167 | 167 | public function getDescription() { |
| 168 | - return $this->msg( 'wbqc-constraintreport' )->text(); |
|
| 168 | + return $this->msg('wbqc-constraintreport')->text(); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -177,43 +177,43 @@ discard block |
||
| 177 | 177 | * @throws EntityIdParsingException |
| 178 | 178 | * @throws UnexpectedValueException |
| 179 | 179 | */ |
| 180 | - public function execute( $subPage ) { |
|
| 180 | + public function execute($subPage) { |
|
| 181 | 181 | $out = $this->getOutput(); |
| 182 | 182 | |
| 183 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
| 184 | - if ( $postRequest ) { |
|
| 185 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
| 183 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
| 184 | + if ($postRequest) { |
|
| 185 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
| 186 | 186 | return; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $out->enableOOUI(); |
| 190 | - $out->addModules( $this->getModules() ); |
|
| 190 | + $out->addModules($this->getModules()); |
|
| 191 | 191 | |
| 192 | 192 | $this->setHeaders(); |
| 193 | 193 | |
| 194 | - $out->addHTML( $this->getExplanationText() ); |
|
| 194 | + $out->addHTML($this->getExplanationText()); |
|
| 195 | 195 | $this->buildEntityIdForm(); |
| 196 | 196 | |
| 197 | - if ( !$subPage ) { |
|
| 197 | + if (!$subPage) { |
|
| 198 | 198 | return; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if ( !is_string( $subPage ) ) { |
|
| 202 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
| 201 | + if (!is_string($subPage)) { |
|
| 202 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | try { |
| 206 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
| 207 | - } catch ( EntityIdParsingException $e ) { |
|
| 206 | + $entityId = $this->entityIdParser->parse($subPage); |
|
| 207 | + } catch (EntityIdParsingException $e) { |
|
| 208 | 208 | $out->addHTML( |
| 209 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
| 209 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
| 210 | 210 | ); |
| 211 | 211 | return; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
| 214 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
| 215 | 215 | $out->addHTML( |
| 216 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
| 216 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
| 217 | 217 | ); |
| 218 | 218 | return; |
| 219 | 219 | } |
@@ -221,18 +221,18 @@ discard block |
||
| 221 | 221 | $this->dataFactory->increment( |
| 222 | 222 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
| 223 | 223 | ); |
| 224 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
| 224 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
| 225 | 225 | |
| 226 | - if ( $results !== [] ) { |
|
| 226 | + if ($results !== []) { |
|
| 227 | 227 | $out->addHTML( |
| 228 | - $this->buildResultHeader( $entityId ) |
|
| 229 | - . $this->buildSummary( $results ) |
|
| 230 | - . $this->buildResultTable( $entityId, $results ) |
|
| 228 | + $this->buildResultHeader($entityId) |
|
| 229 | + . $this->buildSummary($results) |
|
| 230 | + . $this->buildResultTable($entityId, $results) |
|
| 231 | 231 | ); |
| 232 | 232 | } else { |
| 233 | 233 | $out->addHTML( |
| 234 | - $this->buildResultHeader( $entityId ) |
|
| 235 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
| 234 | + $this->buildResultHeader($entityId) |
|
| 235 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
| 236 | 236 | ); |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -248,15 +248,15 @@ discard block |
||
| 248 | 248 | 'name' => 'entityid', |
| 249 | 249 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
| 250 | 250 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
| 251 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
| 251 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
| 252 | 252 | ] |
| 253 | 253 | ]; |
| 254 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
| 255 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
| 256 | - $htmlForm->setSubmitCallback( static function () { |
|
| 254 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
| 255 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
| 256 | + $htmlForm->setSubmitCallback(static function() { |
|
| 257 | 257 | return false; |
| 258 | 258 | } ); |
| 259 | - $htmlForm->setMethod( 'post' ); |
|
| 259 | + $htmlForm->setMethod('post'); |
|
| 260 | 260 | $htmlForm->show(); |
| 261 | 261 | } |
| 262 | 262 | |
@@ -270,9 +270,9 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return string HTML |
| 272 | 272 | */ |
| 273 | - private function buildNotice( string $messageKey, bool $error = false ): string { |
|
| 273 | + private function buildNotice(string $messageKey, bool $error = false): string { |
|
| 274 | 274 | $cssClasses = 'wbqc-constraintreport-notice'; |
| 275 | - if ( $error ) { |
|
| 275 | + if ($error) { |
|
| 276 | 276 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | [ |
| 282 | 282 | 'class' => $cssClasses |
| 283 | 283 | ], |
| 284 | - $this->msg( $messageKey )->escaped() |
|
| 284 | + $this->msg($messageKey)->escaped() |
|
| 285 | 285 | ); |
| 286 | 286 | } |
| 287 | 287 | |
@@ -291,16 +291,16 @@ discard block |
||
| 291 | 291 | private function getExplanationText(): string { |
| 292 | 292 | return Html::rawElement( |
| 293 | 293 | 'div', |
| 294 | - [ 'class' => 'wbqc-explanation' ], |
|
| 294 | + ['class' => 'wbqc-explanation'], |
|
| 295 | 295 | Html::rawElement( |
| 296 | 296 | 'p', |
| 297 | 297 | [], |
| 298 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
| 298 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
| 299 | 299 | ) |
| 300 | 300 | . Html::rawElement( |
| 301 | 301 | 'p', |
| 302 | 302 | [], |
| 303 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
| 303 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
| 304 | 304 | ) |
| 305 | 305 | ); |
| 306 | 306 | } |
@@ -312,31 +312,31 @@ discard block |
||
| 312 | 312 | * @return string HTML |
| 313 | 313 | * @suppress SecurityCheck-DoubleEscaped |
| 314 | 314 | */ |
| 315 | - private function buildResultTable( EntityId $entityId, array $results ): string { |
|
| 315 | + private function buildResultTable(EntityId $entityId, array $results): string { |
|
| 316 | 316 | // Set table headers |
| 317 | 317 | $table = new HtmlTableBuilder( |
| 318 | 318 | [ |
| 319 | 319 | new HtmlTableHeaderBuilder( |
| 320 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
| 320 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
| 321 | 321 | true |
| 322 | 322 | ), |
| 323 | 323 | new HtmlTableHeaderBuilder( |
| 324 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(), |
|
| 324 | + $this->msg('wbqc-constraintreport-result-table-header-property')->escaped(), |
|
| 325 | 325 | true |
| 326 | 326 | ), |
| 327 | 327 | new HtmlTableHeaderBuilder( |
| 328 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(), |
|
| 328 | + $this->msg('wbqc-constraintreport-result-table-header-message')->escaped(), |
|
| 329 | 329 | true |
| 330 | 330 | ), |
| 331 | 331 | new HtmlTableHeaderBuilder( |
| 332 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
| 332 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
| 333 | 333 | true |
| 334 | 334 | ) |
| 335 | 335 | ] |
| 336 | 336 | ); |
| 337 | 337 | |
| 338 | - foreach ( $results as $result ) { |
|
| 339 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
| 338 | + foreach ($results as $result) { |
|
| 339 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | return $table->toHtml(); |
@@ -348,40 +348,40 @@ discard block |
||
| 348 | 348 | CheckResult $result |
| 349 | 349 | ): HtmlTableBuilder { |
| 350 | 350 | $message = $result->getMessage(); |
| 351 | - if ( $message === null ) { |
|
| 351 | + if ($message === null) { |
|
| 352 | 352 | // no row for this result |
| 353 | 353 | return $table; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Status column |
| 357 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
| 357 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
| 358 | 358 | |
| 359 | 359 | // Property column |
| 360 | - $propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
| 360 | + $propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
| 361 | 361 | $propertyColumn = $this->getClaimLink( |
| 362 | 362 | $entityId, |
| 363 | 363 | $propertyId, |
| 364 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
| 364 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
| 365 | 365 | ); |
| 366 | 366 | |
| 367 | 367 | // Message column |
| 368 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
| 368 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
| 369 | 369 | |
| 370 | 370 | // Constraint column |
| 371 | 371 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
| 372 | 372 | try { |
| 373 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
| 374 | - } catch ( InvalidArgumentException $e ) { |
|
| 375 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
| 373 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
| 374 | + } catch (InvalidArgumentException $e) { |
|
| 375 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
| 376 | 376 | } |
| 377 | 377 | $constraintLink = $this->getClaimLink( |
| 378 | 378 | $propertyId, |
| 379 | - new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
| 379 | + new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
| 380 | 380 | $constraintTypeLabel |
| 381 | 381 | ); |
| 382 | 382 | $constraintColumn = $this->buildExpandableElement( |
| 383 | 383 | $constraintLink, |
| 384 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
| 384 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
| 385 | 385 | '[...]' |
| 386 | 386 | ); |
| 387 | 387 | |
@@ -421,15 +421,15 @@ discard block |
||
| 421 | 421 | * |
| 422 | 422 | * @return string HTML |
| 423 | 423 | */ |
| 424 | - protected function buildResultHeader( EntityId $entityId ): string { |
|
| 425 | - $entityLink = sprintf( '%s (%s)', |
|
| 426 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
| 427 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
| 424 | + protected function buildResultHeader(EntityId $entityId): string { |
|
| 425 | + $entityLink = sprintf('%s (%s)', |
|
| 426 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
| 427 | + htmlspecialchars($entityId->getSerialization())); |
|
| 428 | 428 | |
| 429 | 429 | return Html::rawElement( |
| 430 | 430 | 'h3', |
| 431 | 431 | [], |
| 432 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
| 432 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
| 433 | 433 | ); |
| 434 | 434 | } |
| 435 | 435 | |
@@ -440,24 +440,24 @@ discard block |
||
| 440 | 440 | * |
| 441 | 441 | * @return string HTML |
| 442 | 442 | */ |
| 443 | - protected function buildSummary( array $results ): string { |
|
| 443 | + protected function buildSummary(array $results): string { |
|
| 444 | 444 | $statuses = []; |
| 445 | - foreach ( $results as $result ) { |
|
| 446 | - $status = strtolower( $result->getStatus() ); |
|
| 447 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
| 445 | + foreach ($results as $result) { |
|
| 446 | + $status = strtolower($result->getStatus()); |
|
| 447 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | $statusElements = []; |
| 451 | - foreach ( $statuses as $status => $count ) { |
|
| 452 | - if ( $count > 0 ) { |
|
| 451 | + foreach ($statuses as $status => $count) { |
|
| 452 | + if ($count > 0) { |
|
| 453 | 453 | $statusElements[] = |
| 454 | - $this->formatStatus( $status ) |
|
| 454 | + $this->formatStatus($status) |
|
| 455 | 455 | . ': ' |
| 456 | 456 | . $count; |
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
| 460 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | ?string $expandableContent, |
| 478 | 478 | string $indicator |
| 479 | 479 | ): string { |
| 480 | - if ( empty( $expandableContent ) ) { |
|
| 480 | + if (empty($expandableContent)) { |
|
| 481 | 481 | return $content; |
| 482 | 482 | } |
| 483 | 483 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | $expandableContent |
| 498 | 498 | ); |
| 499 | 499 | |
| 500 | - return sprintf( '%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent ); |
|
| 500 | + return sprintf('%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | /** |
@@ -509,8 +509,8 @@ discard block |
||
| 509 | 509 | * |
| 510 | 510 | * @return string HTML |
| 511 | 511 | */ |
| 512 | - private function formatStatus( string $status ): string { |
|
| 513 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
| 512 | + private function formatStatus(string $status): string { |
|
| 513 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
| 514 | 514 | $statusIcons = [ |
| 515 | 515 | CheckResult::STATUS_SUGGESTION => [ |
| 516 | 516 | 'icon' => 'suggestion-constraint-violation', |
@@ -527,25 +527,25 @@ discard block |
||
| 527 | 527 | ], |
| 528 | 528 | ]; |
| 529 | 529 | |
| 530 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
| 531 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
| 532 | - $iconHtml = $iconWidget->toString() . ' '; |
|
| 530 | + if (array_key_exists($status, $statusIcons)) { |
|
| 531 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
| 532 | + $iconHtml = $iconWidget->toString().' '; |
|
| 533 | 533 | } else { |
| 534 | 534 | $iconHtml = ''; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - $labelWidget = new LabelWidget( [ |
|
| 538 | - 'label' => $this->msg( $messageName )->text(), |
|
| 539 | - ] ); |
|
| 537 | + $labelWidget = new LabelWidget([ |
|
| 538 | + 'label' => $this->msg($messageName)->text(), |
|
| 539 | + ]); |
|
| 540 | 540 | $labelHtml = $labelWidget->toString(); |
| 541 | 541 | |
| 542 | 542 | $formattedStatus = |
| 543 | 543 | Html::rawElement( |
| 544 | 544 | 'span', |
| 545 | 545 | [ |
| 546 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
| 546 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
| 547 | 547 | ], |
| 548 | - $iconHtml . $labelHtml |
|
| 548 | + $iconHtml.$labelHtml |
|
| 549 | 549 | ); |
| 550 | 550 | |
| 551 | 551 | return $formattedStatus; |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | return Html::rawElement( |
| 569 | 569 | 'a', |
| 570 | 570 | [ |
| 571 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
| 571 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
| 572 | 572 | 'target' => '_blank' |
| 573 | 573 | ], |
| 574 | 574 | $text |
@@ -582,8 +582,8 @@ discard block |
||
| 582 | 582 | EntityId $entityId, |
| 583 | 583 | NumericPropertyId $propertyId |
| 584 | 584 | ): string { |
| 585 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
| 586 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
| 585 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
| 586 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
| 587 | 587 | |
| 588 | 588 | return $entityUrl; |
| 589 | 589 | } |
@@ -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\Api; |
| 6 | 6 | |
@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | return new CheckResultsRenderer( |
| 41 | 41 | $this->entityTitleLookup, |
| 42 | 42 | $this->entityIdLabelFormatterFactory |
| 43 | - ->getEntityIdFormatter( $userLanguage ), |
|
| 43 | + ->getEntityIdFormatter($userLanguage), |
|
| 44 | 44 | $this->violationMessageRendererFactory |
| 45 | 45 | ->getViolationMessageRenderer( |
| 46 | 46 | $userLanguage, |
| 47 | - $this->languageFallbackChainFactory->newFromLanguage( $userLanguage ), |
|
| 47 | + $this->languageFallbackChainFactory->newFromLanguage($userLanguage), |
|
| 48 | 48 | $messageLocalizer |
| 49 | 49 | ) |
| 50 | 50 | ); |
@@ -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\Api; |
| 6 | 6 | |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | StatementGuidParser $statementGuidParser, |
| 80 | 80 | IBufferingStatsdDataFactory $dataFactory |
| 81 | 81 | ) { |
| 82 | - parent::__construct( $main, $name ); |
|
| 82 | + parent::__construct($main, $name); |
|
| 83 | 83 | |
| 84 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
| 84 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
| 85 | 85 | $this->languageFallbackChainFactory = $languageFallbackChainFactory; |
| 86 | 86 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
| 87 | 87 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
@@ -97,39 +97,39 @@ discard block |
||
| 97 | 97 | $params = $this->extractRequestParams(); |
| 98 | 98 | $result = $this->getResult(); |
| 99 | 99 | |
| 100 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
| 101 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
| 100 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
| 101 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
| 102 | 102 | |
| 103 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
| 104 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
| 103 | + $this->checkPropertyIds($propertyIds, $result); |
|
| 104 | + $this->checkConstraintIds($constraintIds, $result); |
|
| 105 | 105 | |
| 106 | - $result->addValue( null, 'success', 1 ); |
|
| 106 | + $result->addValue(null, 'success', 1); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * @param array|null $propertyIdSerializations |
| 111 | 111 | * @return NumericPropertyId[] |
| 112 | 112 | */ |
| 113 | - private function parsePropertyIds( ?array $propertyIdSerializations ): array { |
|
| 114 | - if ( $propertyIdSerializations === null ) { |
|
| 113 | + private function parsePropertyIds(?array $propertyIdSerializations): array { |
|
| 114 | + if ($propertyIdSerializations === null) { |
|
| 115 | 115 | return []; |
| 116 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
| 116 | + } elseif (empty($propertyIdSerializations)) { |
|
| 117 | 117 | $this->apiErrorReporter->dieError( |
| 118 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
| 118 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
| 119 | 119 | 'no-data' |
| 120 | 120 | ); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return array_map( |
| 124 | - function ( $propertyIdSerialization ) { |
|
| 124 | + function($propertyIdSerialization) { |
|
| 125 | 125 | try { |
| 126 | - return new NumericPropertyId( $propertyIdSerialization ); |
|
| 127 | - } catch ( InvalidArgumentException $e ) { |
|
| 126 | + return new NumericPropertyId($propertyIdSerialization); |
|
| 127 | + } catch (InvalidArgumentException $e) { |
|
| 128 | 128 | $this->apiErrorReporter->dieError( |
| 129 | 129 | "Invalid id: $propertyIdSerialization", |
| 130 | 130 | 'invalid-property-id', |
| 131 | 131 | 0, // default argument |
| 132 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
| 132 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
| 133 | 133 | ); |
| 134 | 134 | } |
| 135 | 135 | }, |
@@ -141,35 +141,35 @@ discard block |
||
| 141 | 141 | * @param array|null $constraintIds |
| 142 | 142 | * @return string[] |
| 143 | 143 | */ |
| 144 | - private function parseConstraintIds( ?array $constraintIds ): array { |
|
| 145 | - if ( $constraintIds === null ) { |
|
| 144 | + private function parseConstraintIds(?array $constraintIds): array { |
|
| 145 | + if ($constraintIds === null) { |
|
| 146 | 146 | return []; |
| 147 | - } elseif ( empty( $constraintIds ) ) { |
|
| 147 | + } elseif (empty($constraintIds)) { |
|
| 148 | 148 | $this->apiErrorReporter->dieError( |
| 149 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
| 149 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
| 150 | 150 | 'no-data' |
| 151 | 151 | ); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return array_map( |
| 155 | - function ( $constraintId ) { |
|
| 155 | + function($constraintId) { |
|
| 156 | 156 | try { |
| 157 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 158 | - if ( !$propertyId instanceof NumericPropertyId ) { |
|
| 157 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 158 | + if (!$propertyId instanceof NumericPropertyId) { |
|
| 159 | 159 | $this->apiErrorReporter->dieError( |
| 160 | 160 | "Invalid property ID: {$propertyId->getSerialization()}", |
| 161 | 161 | 'invalid-property-id', |
| 162 | 162 | 0, // default argument |
| 163 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
| 163 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
| 164 | 164 | ); |
| 165 | 165 | } |
| 166 | 166 | return $constraintId; |
| 167 | - } catch ( StatementGuidParsingException $e ) { |
|
| 167 | + } catch (StatementGuidParsingException $e) { |
|
| 168 | 168 | $this->apiErrorReporter->dieError( |
| 169 | 169 | "Invalid statement GUID: $constraintId", |
| 170 | 170 | 'invalid-guid', |
| 171 | 171 | 0, // default argument |
| 172 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
| 172 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
| 173 | 173 | ); |
| 174 | 174 | } |
| 175 | 175 | }, |
@@ -181,12 +181,12 @@ discard block |
||
| 181 | 181 | * @param NumericPropertyId[] $propertyIds |
| 182 | 182 | * @param ApiResult $result |
| 183 | 183 | */ |
| 184 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ): void { |
|
| 185 | - foreach ( $propertyIds as $propertyId ) { |
|
| 186 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
| 184 | + private function checkPropertyIds(array $propertyIds, ApiResult $result): void { |
|
| 185 | + foreach ($propertyIds as $propertyId) { |
|
| 186 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
| 187 | 187 | $allConstraintExceptions = $this->delegatingConstraintChecker |
| 188 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
| 189 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
| 188 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
| 189 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
| 190 | 190 | $this->addConstraintParameterExceptionsToResult( |
| 191 | 191 | $constraintId, |
| 192 | 192 | $constraintParameterExceptions, |
@@ -200,15 +200,15 @@ discard block |
||
| 200 | 200 | * @param string[] $constraintIds |
| 201 | 201 | * @param ApiResult $result |
| 202 | 202 | */ |
| 203 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ): void { |
|
| 204 | - foreach ( $constraintIds as $constraintId ) { |
|
| 205 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
| 203 | + private function checkConstraintIds(array $constraintIds, ApiResult $result): void { |
|
| 204 | + foreach ($constraintIds as $constraintId) { |
|
| 205 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
| 206 | 206 | // already checked as part of checkPropertyIds() |
| 207 | 207 | continue; |
| 208 | 208 | } |
| 209 | 209 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
| 210 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
| 211 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
| 210 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
| 211 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
@@ -216,18 +216,18 @@ discard block |
||
| 216 | 216 | * @param NumericPropertyId $propertyId |
| 217 | 217 | * @return string[] |
| 218 | 218 | */ |
| 219 | - private function getResultPathForPropertyId( NumericPropertyId $propertyId ): array { |
|
| 220 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
| 219 | + private function getResultPathForPropertyId(NumericPropertyId $propertyId): array { |
|
| 220 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
| 224 | 224 | * @param string $constraintId |
| 225 | 225 | * @return string[] |
| 226 | 226 | */ |
| 227 | - private function getResultPathForConstraintId( string $constraintId ): array { |
|
| 228 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 227 | + private function getResultPathForConstraintId(string $constraintId): array { |
|
| 228 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 229 | 229 | '@phan-var NumericPropertyId $propertyId'; |
| 230 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
| 230 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | ?array $constraintParameterExceptions, |
| 243 | 243 | ApiResult $result |
| 244 | 244 | ): void { |
| 245 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
| 246 | - if ( $constraintParameterExceptions === null ) { |
|
| 245 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
| 246 | + if ($constraintParameterExceptions === null) { |
|
| 247 | 247 | $result->addValue( |
| 248 | 248 | $path, |
| 249 | 249 | self::KEY_STATUS, |
@@ -253,18 +253,18 @@ discard block |
||
| 253 | 253 | $result->addValue( |
| 254 | 254 | $path, |
| 255 | 255 | self::KEY_STATUS, |
| 256 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
| 256 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
| 257 | 257 | ); |
| 258 | 258 | |
| 259 | 259 | $language = $this->getLanguage(); |
| 260 | 260 | $violationMessageRenderer = $this->violationMessageRendererFactory |
| 261 | 261 | ->getViolationMessageRenderer( |
| 262 | 262 | $language, |
| 263 | - $this->languageFallbackChainFactory->newFromLanguage( $language ), |
|
| 263 | + $this->languageFallbackChainFactory->newFromLanguage($language), |
|
| 264 | 264 | $this |
| 265 | 265 | ); |
| 266 | 266 | $problems = []; |
| 267 | - foreach ( $constraintParameterExceptions as $constraintParameterException ) { |
|
| 267 | + foreach ($constraintParameterExceptions as $constraintParameterException) { |
|
| 268 | 268 | $problems[] = [ |
| 269 | 269 | self::KEY_MESSAGE_HTML => $violationMessageRenderer->render( |
| 270 | 270 | $constraintParameterException->getViolationMessage() ), |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | return [ |
| 304 | 304 | 'action=wbcheckconstraintparameters&propertyid=P247' |
| 305 | 305 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
| 306 | - 'action=wbcheckconstraintparameters&' . |
|
| 307 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
| 306 | + 'action=wbcheckconstraintparameters&'. |
|
| 307 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
| 308 | 308 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
| 309 | 309 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
| 310 | 310 | ]; |
@@ -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 | |
@@ -27,13 +27,13 @@ discard block |
||
| 27 | 27 | 'wbqc-violation-message-format-clarification' => 'wbqc-violation-message-format', |
| 28 | 28 | ]; |
| 29 | 29 | |
| 30 | - public function render( ViolationMessage $violationMessage ): string { |
|
| 31 | - if ( !array_key_exists( $violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS ) ) { |
|
| 32 | - return parent::render( $violationMessage ); |
|
| 30 | + public function render(ViolationMessage $violationMessage): string { |
|
| 31 | + if (!array_key_exists($violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS)) { |
|
| 32 | + return parent::render($violationMessage); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $arguments = $violationMessage->getArguments(); |
| 36 | - $multilingualTextArgument = array_pop( $arguments ); |
|
| 36 | + $multilingualTextArgument = array_pop($arguments); |
|
| 37 | 37 | $multilingualTextParams = $this->renderMultilingualText( |
| 38 | 38 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue |
| 39 | 39 | $multilingualTextArgument['value'], |
@@ -41,22 +41,22 @@ discard block |
||
| 41 | 41 | $multilingualTextArgument['role'] |
| 42 | 42 | ); |
| 43 | 43 | |
| 44 | - $paramsLists = [ [] ]; |
|
| 45 | - foreach ( $arguments as $argument ) { |
|
| 46 | - $paramsLists[] = $this->renderArgument( $argument ); |
|
| 44 | + $paramsLists = [[]]; |
|
| 45 | + foreach ($arguments as $argument) { |
|
| 46 | + $paramsLists[] = $this->renderArgument($argument); |
|
| 47 | 47 | } |
| 48 | - $regularParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
| 48 | + $regularParams = call_user_func_array('array_merge', $paramsLists); |
|
| 49 | 49 | |
| 50 | - if ( $multilingualTextParams === null ) { |
|
| 50 | + if ($multilingualTextParams === null) { |
|
| 51 | 51 | return $this->messageLocalizer |
| 52 | - ->msg( self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()] ) |
|
| 53 | - ->params( $regularParams ) |
|
| 52 | + ->msg(self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()]) |
|
| 53 | + ->params($regularParams) |
|
| 54 | 54 | ->escaped(); |
| 55 | 55 | } else { |
| 56 | 56 | return $this->messageLocalizer |
| 57 | - ->msg( $violationMessage->getMessageKey() ) |
|
| 58 | - ->params( $regularParams ) |
|
| 59 | - ->params( $multilingualTextParams ) |
|
| 57 | + ->msg($violationMessage->getMessageKey()) |
|
| 58 | + ->params($regularParams) |
|
| 59 | + ->params($multilingualTextParams) |
|
| 60 | 60 | ->escaped(); |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -67,14 +67,14 @@ discard block |
||
| 67 | 67 | * @return array[]|null list of parameters as accepted by Message::params(), |
| 68 | 68 | * or null if the text is not available in the user’s language |
| 69 | 69 | */ |
| 70 | - protected function renderMultilingualText( MultilingualTextValue $text, ?string $role ): ?array { |
|
| 70 | + protected function renderMultilingualText(MultilingualTextValue $text, ?string $role): ?array { |
|
| 71 | 71 | $texts = $text->getTexts(); |
| 72 | - foreach ( $this->languageFallbackChain->getFetchLanguageCodes() as $languageCode ) { |
|
| 73 | - if ( array_key_exists( $languageCode, $texts ) ) { |
|
| 74 | - return [ Message::rawParam( $this->addRole( |
|
| 75 | - htmlspecialchars( $texts[$languageCode]->getText() ), |
|
| 72 | + foreach ($this->languageFallbackChain->getFetchLanguageCodes() as $languageCode) { |
|
| 73 | + if (array_key_exists($languageCode, $texts)) { |
|
| 74 | + return [Message::rawParam($this->addRole( |
|
| 75 | + htmlspecialchars($texts[$languageCode]->getText()), |
|
| 76 | 76 | $role |
| 77 | - ) ) ]; |
|
| 77 | + ))]; |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -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 | |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | ): ViolationMessageRenderer { |
| 44 | 44 | $userLanguageCode = $userLanguage->getCode(); |
| 45 | 45 | $formatterOptions = new FormatterOptions(); |
| 46 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $userLanguageCode ); |
|
| 46 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $userLanguageCode); |
|
| 47 | 47 | return new MultilingualTextViolationMessageRenderer( |
| 48 | 48 | $this->entityIdHtmlLinkFormatterFactory |
| 49 | - ->getEntityIdFormatter( $userLanguage ), |
|
| 49 | + ->getEntityIdFormatter($userLanguage), |
|
| 50 | 50 | $this->valueFormatterFactory |
| 51 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ), |
|
| 51 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions), |
|
| 52 | 52 | $this->languageNameUtils, |
| 53 | 53 | $userLanguageCode, |
| 54 | 54 | $languageFallbackChain, |