@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | Config $config, |
135 | 135 | IBufferingStatsdDataFactory $dataFactory |
136 | 136 | ) { |
137 | - parent::__construct( 'ConstraintReport' ); |
|
137 | + parent::__construct('ConstraintReport'); |
|
138 | 138 | |
139 | 139 | $this->entityLookup = $entityLookup; |
140 | 140 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $language = $this->getLanguage(); |
144 | 144 | |
145 | 145 | $formatterOptions = new FormatterOptions(); |
146 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
146 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
147 | 147 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
148 | 148 | SnakFormatter::FORMAT_HTML, |
149 | 149 | $formatterOptions |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function getDescription() { |
206 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
206 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -215,43 +215,43 @@ discard block |
||
215 | 215 | * @throws EntityIdParsingException |
216 | 216 | * @throws UnexpectedValueException |
217 | 217 | */ |
218 | - public function execute( $subPage ) { |
|
218 | + public function execute($subPage) { |
|
219 | 219 | $out = $this->getOutput(); |
220 | 220 | |
221 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
222 | - if ( $postRequest ) { |
|
223 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
221 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
222 | + if ($postRequest) { |
|
223 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
224 | 224 | return; |
225 | 225 | } |
226 | 226 | |
227 | 227 | $out->enableOOUI(); |
228 | - $out->addModules( $this->getModules() ); |
|
228 | + $out->addModules($this->getModules()); |
|
229 | 229 | |
230 | 230 | $this->setHeaders(); |
231 | 231 | |
232 | - $out->addHTML( $this->getExplanationText() ); |
|
232 | + $out->addHTML($this->getExplanationText()); |
|
233 | 233 | $this->buildEntityIdForm(); |
234 | 234 | |
235 | - if ( !$subPage ) { |
|
235 | + if (!$subPage) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
239 | - if ( !is_string( $subPage ) ) { |
|
240 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
239 | + if (!is_string($subPage)) { |
|
240 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | try { |
244 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
245 | - } catch ( EntityIdParsingException $e ) { |
|
244 | + $entityId = $this->entityIdParser->parse($subPage); |
|
245 | + } catch (EntityIdParsingException $e) { |
|
246 | 246 | $out->addHTML( |
247 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
247 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
248 | 248 | ); |
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
252 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
253 | 253 | $out->addHTML( |
254 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
254 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
255 | 255 | ); |
256 | 256 | return; |
257 | 257 | } |
@@ -259,18 +259,18 @@ discard block |
||
259 | 259 | $this->dataFactory->increment( |
260 | 260 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
261 | 261 | ); |
262 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
262 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
263 | 263 | |
264 | - if ( $results !== [] ) { |
|
264 | + if ($results !== []) { |
|
265 | 265 | $out->addHTML( |
266 | - $this->buildResultHeader( $entityId ) |
|
267 | - . $this->buildSummary( $results ) |
|
268 | - . $this->buildResultTable( $entityId, $results ) |
|
266 | + $this->buildResultHeader($entityId) |
|
267 | + . $this->buildSummary($results) |
|
268 | + . $this->buildResultTable($entityId, $results) |
|
269 | 269 | ); |
270 | 270 | } else { |
271 | 271 | $out->addHTML( |
272 | - $this->buildResultHeader( $entityId ) |
|
273 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
272 | + $this->buildResultHeader($entityId) |
|
273 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
274 | 274 | ); |
275 | 275 | } |
276 | 276 | } |
@@ -286,15 +286,15 @@ discard block |
||
286 | 286 | 'name' => 'entityid', |
287 | 287 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
288 | 288 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
289 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
289 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
290 | 290 | ] |
291 | 291 | ]; |
292 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
293 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
294 | - $htmlForm->setSubmitCallback( static function () { |
|
292 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
293 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
294 | + $htmlForm->setSubmitCallback(static function() { |
|
295 | 295 | return false; |
296 | 296 | } ); |
297 | - $htmlForm->setMethod( 'post' ); |
|
297 | + $htmlForm->setMethod('post'); |
|
298 | 298 | $htmlForm->show(); |
299 | 299 | } |
300 | 300 | |
@@ -308,16 +308,16 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @return string HTML |
310 | 310 | */ |
311 | - private function buildNotice( $messageKey, $error = false ) { |
|
312 | - if ( !is_string( $messageKey ) ) { |
|
313 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
311 | + private function buildNotice($messageKey, $error = false) { |
|
312 | + if (!is_string($messageKey)) { |
|
313 | + throw new InvalidArgumentException('$message must be string.'); |
|
314 | 314 | } |
315 | - if ( !is_bool( $error ) ) { |
|
316 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
315 | + if (!is_bool($error)) { |
|
316 | + throw new InvalidArgumentException('$error must be bool.'); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | $cssClasses = 'wbqc-constraintreport-notice'; |
320 | - if ( $error ) { |
|
320 | + if ($error) { |
|
321 | 321 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
322 | 322 | } |
323 | 323 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | [ |
327 | 327 | 'class' => $cssClasses |
328 | 328 | ], |
329 | - $this->msg( $messageKey )->escaped() |
|
329 | + $this->msg($messageKey)->escaped() |
|
330 | 330 | ); |
331 | 331 | } |
332 | 332 | |
@@ -336,16 +336,16 @@ discard block |
||
336 | 336 | private function getExplanationText() { |
337 | 337 | return Html::rawElement( |
338 | 338 | 'div', |
339 | - [ 'class' => 'wbqc-explanation' ], |
|
339 | + ['class' => 'wbqc-explanation'], |
|
340 | 340 | Html::rawElement( |
341 | 341 | 'p', |
342 | 342 | [], |
343 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
343 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
344 | 344 | ) |
345 | 345 | . Html::rawElement( |
346 | 346 | 'p', |
347 | 347 | [], |
348 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
348 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
349 | 349 | ) |
350 | 350 | ); |
351 | 351 | } |
@@ -357,72 +357,72 @@ discard block |
||
357 | 357 | * @return string HTML |
358 | 358 | * @suppress SecurityCheck-DoubleEscaped |
359 | 359 | */ |
360 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
360 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
361 | 361 | // Set table headers |
362 | 362 | $table = new HtmlTableBuilder( |
363 | 363 | [ |
364 | 364 | new HtmlTableHeaderBuilder( |
365 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
365 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
366 | 366 | true |
367 | 367 | ), |
368 | 368 | new HtmlTableHeaderBuilder( |
369 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(), |
|
369 | + $this->msg('wbqc-constraintreport-result-table-header-property')->escaped(), |
|
370 | 370 | true |
371 | 371 | ), |
372 | 372 | new HtmlTableHeaderBuilder( |
373 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(), |
|
373 | + $this->msg('wbqc-constraintreport-result-table-header-message')->escaped(), |
|
374 | 374 | true |
375 | 375 | ), |
376 | 376 | new HtmlTableHeaderBuilder( |
377 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
377 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
378 | 378 | true |
379 | 379 | ) |
380 | 380 | ] |
381 | 381 | ); |
382 | 382 | |
383 | - foreach ( $results as $result ) { |
|
384 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
383 | + foreach ($results as $result) { |
|
384 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return $table->toHtml(); |
388 | 388 | } |
389 | 389 | |
390 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
390 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
391 | 391 | $message = $result->getMessage(); |
392 | - if ( $message === null ) { |
|
392 | + if ($message === null) { |
|
393 | 393 | // no row for this result |
394 | 394 | return $table; |
395 | 395 | } |
396 | 396 | |
397 | 397 | // Status column |
398 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
398 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
399 | 399 | |
400 | 400 | // Property column |
401 | - $propertyId = new PropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
401 | + $propertyId = new PropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
402 | 402 | $propertyColumn = $this->getClaimLink( |
403 | 403 | $entityId, |
404 | 404 | $propertyId, |
405 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
405 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
406 | 406 | ); |
407 | 407 | |
408 | 408 | // Message column |
409 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
409 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
410 | 410 | |
411 | 411 | // Constraint column |
412 | 412 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
413 | 413 | try { |
414 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
415 | - } catch ( InvalidArgumentException $e ) { |
|
416 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
414 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
415 | + } catch (InvalidArgumentException $e) { |
|
416 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
417 | 417 | } |
418 | 418 | $constraintLink = $this->getClaimLink( |
419 | 419 | $propertyId, |
420 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
420 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
421 | 421 | $constraintTypeLabel |
422 | 422 | ); |
423 | 423 | $constraintColumn = $this->buildExpandableElement( |
424 | 424 | $constraintLink, |
425 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
425 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
426 | 426 | '[...]' |
427 | 427 | ); |
428 | 428 | |
@@ -462,15 +462,15 @@ discard block |
||
462 | 462 | * |
463 | 463 | * @return string HTML |
464 | 464 | */ |
465 | - protected function buildResultHeader( EntityId $entityId ) { |
|
466 | - $entityLink = sprintf( '%s (%s)', |
|
467 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
468 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
465 | + protected function buildResultHeader(EntityId $entityId) { |
|
466 | + $entityLink = sprintf('%s (%s)', |
|
467 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
468 | + htmlspecialchars($entityId->getSerialization())); |
|
469 | 469 | |
470 | 470 | return Html::rawElement( |
471 | 471 | 'h3', |
472 | 472 | [], |
473 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
473 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
474 | 474 | ); |
475 | 475 | } |
476 | 476 | |
@@ -481,24 +481,24 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @return string HTML |
483 | 483 | */ |
484 | - protected function buildSummary( array $results ) { |
|
484 | + protected function buildSummary(array $results) { |
|
485 | 485 | $statuses = []; |
486 | - foreach ( $results as $result ) { |
|
487 | - $status = strtolower( $result->getStatus() ); |
|
488 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
486 | + foreach ($results as $result) { |
|
487 | + $status = strtolower($result->getStatus()); |
|
488 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | $statusElements = []; |
492 | - foreach ( $statuses as $status => $count ) { |
|
493 | - if ( $count > 0 ) { |
|
492 | + foreach ($statuses as $status => $count) { |
|
493 | + if ($count > 0) { |
|
494 | 494 | $statusElements[] = |
495 | - $this->formatStatus( $status ) |
|
495 | + $this->formatStatus($status) |
|
496 | 496 | . ': ' |
497 | 497 | . $count; |
498 | 498 | } |
499 | 499 | } |
500 | 500 | |
501 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
501 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | /** |
@@ -513,15 +513,15 @@ discard block |
||
513 | 513 | * |
514 | 514 | * @return string HTML |
515 | 515 | */ |
516 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
517 | - if ( !is_string( $content ) ) { |
|
518 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
516 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
517 | + if (!is_string($content)) { |
|
518 | + throw new InvalidArgumentException('$content has to be string.'); |
|
519 | 519 | } |
520 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
521 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
520 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
521 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
522 | 522 | } |
523 | 523 | |
524 | - if ( empty( $expandableContent ) ) { |
|
524 | + if (empty($expandableContent)) { |
|
525 | 525 | return $content; |
526 | 526 | } |
527 | 527 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | $expandableContent |
542 | 542 | ); |
543 | 543 | |
544 | - return sprintf( '%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent ); |
|
544 | + return sprintf('%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -553,8 +553,8 @@ discard block |
||
553 | 553 | * |
554 | 554 | * @return string HTML |
555 | 555 | */ |
556 | - private function formatStatus( $status ) { |
|
557 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
556 | + private function formatStatus($status) { |
|
557 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
558 | 558 | $statusIcons = [ |
559 | 559 | CheckResult::STATUS_SUGGESTION => [ |
560 | 560 | 'icon' => 'suggestion-constraint-violation', |
@@ -571,25 +571,25 @@ discard block |
||
571 | 571 | ], |
572 | 572 | ]; |
573 | 573 | |
574 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
575 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
576 | - $iconHtml = $iconWidget->toString() . ' '; |
|
574 | + if (array_key_exists($status, $statusIcons)) { |
|
575 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
576 | + $iconHtml = $iconWidget->toString().' '; |
|
577 | 577 | } else { |
578 | 578 | $iconHtml = ''; |
579 | 579 | } |
580 | 580 | |
581 | - $labelWidget = new LabelWidget( [ |
|
582 | - 'label' => $this->msg( $messageName )->text(), |
|
583 | - ] ); |
|
581 | + $labelWidget = new LabelWidget([ |
|
582 | + 'label' => $this->msg($messageName)->text(), |
|
583 | + ]); |
|
584 | 584 | $labelHtml = $labelWidget->toString(); |
585 | 585 | |
586 | 586 | $formattedStatus = |
587 | 587 | Html::rawElement( |
588 | 588 | 'span', |
589 | 589 | [ |
590 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
590 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
591 | 591 | ], |
592 | - $iconHtml . $labelHtml |
|
592 | + $iconHtml.$labelHtml |
|
593 | 593 | ); |
594 | 594 | |
595 | 595 | return $formattedStatus; |
@@ -605,26 +605,26 @@ discard block |
||
605 | 605 | * |
606 | 606 | * @return string HTML |
607 | 607 | */ |
608 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
609 | - if ( $dataValues instanceof DataValue ) { |
|
610 | - $dataValues = [ $dataValues ]; |
|
611 | - } elseif ( !is_array( $dataValues ) ) { |
|
612 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
608 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
609 | + if ($dataValues instanceof DataValue) { |
|
610 | + $dataValues = [$dataValues]; |
|
611 | + } elseif (!is_array($dataValues)) { |
|
612 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | $formattedDataValues = []; |
616 | - foreach ( $dataValues as $dataValue ) { |
|
617 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
618 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
616 | + foreach ($dataValues as $dataValue) { |
|
617 | + if (!($dataValue instanceof DataValue)) { |
|
618 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
619 | 619 | } |
620 | - if ( $dataValue instanceof EntityIdValue ) { |
|
621 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
620 | + if ($dataValue instanceof EntityIdValue) { |
|
621 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
622 | 622 | } else { |
623 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
623 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
627 | - return implode( $separator, $formattedDataValues ); |
|
627 | + return implode($separator, $formattedDataValues); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -636,11 +636,11 @@ discard block |
||
636 | 636 | * |
637 | 637 | * @return string HTML |
638 | 638 | */ |
639 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
639 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
640 | 640 | return Html::rawElement( |
641 | 641 | 'a', |
642 | 642 | [ |
643 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
643 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
644 | 644 | 'target' => '_blank' |
645 | 645 | ], |
646 | 646 | $text |
@@ -655,9 +655,9 @@ discard block |
||
655 | 655 | * |
656 | 656 | * @return string |
657 | 657 | */ |
658 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
659 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
660 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
658 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
659 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
660 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
661 | 661 | |
662 | 662 | return $entityUrl; |
663 | 663 | } |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | $this->dataFactory = $dataFactory; |
54 | 54 | $this->logger = $logger; |
55 | 55 | $this->constraintCheckDurationLimits = [ |
56 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
57 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
56 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
57 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
58 | 58 | ]; |
59 | 59 | $this->constraintCheckOnEntityDurationLimits = [ |
60 | - 'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ), |
|
61 | - 'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ), |
|
60 | + 'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'), |
|
61 | + 'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'), |
|
62 | 62 | ]; |
63 | 63 | } |
64 | 64 | |
@@ -69,23 +69,23 @@ discard block |
||
69 | 69 | * @param float $durationSeconds |
70 | 70 | * @return array [ $limitSeconds, $logLevel ] |
71 | 71 | */ |
72 | - private function findLimit( $limits, $durationSeconds ) { |
|
72 | + private function findLimit($limits, $durationSeconds) { |
|
73 | 73 | $limitSeconds = null; |
74 | 74 | $logLevel = null; |
75 | 75 | |
76 | - foreach ( $limits as $level => $limit ) { |
|
76 | + foreach ($limits as $level => $limit) { |
|
77 | 77 | if ( |
78 | 78 | // duration exceeds this limit |
79 | - isset( $limit ) && $durationSeconds > $limit && |
|
79 | + isset($limit) && $durationSeconds > $limit && |
|
80 | 80 | // this limit is longer than previous longest limit |
81 | - ( $limitSeconds === null || $limit > $limitSeconds ) |
|
81 | + ($limitSeconds === null || $limit > $limitSeconds) |
|
82 | 82 | ) { |
83 | 83 | $limitSeconds = $limit; |
84 | 84 | $logLevel = $level; |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - return [ $limitSeconds, $logLevel ]; |
|
88 | + return [$limitSeconds, $logLevel]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -110,31 +110,31 @@ discard block |
||
110 | 110 | $durationSeconds, |
111 | 111 | $method |
112 | 112 | ) { |
113 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
113 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
114 | 114 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
115 | 115 | |
116 | 116 | $this->dataFactory->timing( |
117 | - 'wikibase.quality.constraints.check.timing.' . |
|
118 | - $constraintTypeItemId . '-' . |
|
117 | + 'wikibase.quality.constraints.check.timing.'. |
|
118 | + $constraintTypeItemId.'-'. |
|
119 | 119 | $constraintCheckerClassShortName, |
120 | 120 | $durationSeconds * 1000 |
121 | 121 | ); |
122 | 122 | |
123 | 123 | // find the longest limit (and associated log level) that the duration exceeds |
124 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
124 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
125 | 125 | $this->constraintCheckDurationLimits, |
126 | 126 | $durationSeconds |
127 | 127 | ); |
128 | - if ( $limitSeconds === null ) { |
|
128 | + if ($limitSeconds === null) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
131 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
132 | 132 | // TODO log less details but still log something |
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $resultMessage = $result->getMessage(); |
137 | - if ( $resultMessage !== null ) { |
|
137 | + if ($resultMessage !== null) { |
|
138 | 138 | $resultMessageKey = $resultMessage->getMessageKey(); |
139 | 139 | } else { |
140 | 140 | $resultMessageKey = null; |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | |
143 | 143 | $this->logger->log( |
144 | 144 | $logLevel, |
145 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
146 | - 'took longer than {limitSeconds} second(s) ' . |
|
145 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
146 | + 'took longer than {limitSeconds} second(s) '. |
|
147 | 147 | '(duration: {durationSeconds} seconds).', |
148 | 148 | [ |
149 | 149 | 'method' => $method, |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | 'constraintId' => $constraint->getConstraintId(), |
154 | 154 | 'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(), |
155 | 155 | 'constraintTypeItemId' => $constraintTypeItemId, |
156 | - 'constraintParameters' => json_encode( $constraint->getConstraintParameters() ), |
|
156 | + 'constraintParameters' => json_encode($constraint->getConstraintParameters()), |
|
157 | 157 | 'constraintCheckerClass' => $constraintCheckerClass, |
158 | 158 | 'constraintCheckerClassShortName' => $constraintCheckerClassShortName, |
159 | 159 | 'entityId' => $context->getEntity()->getId()->getSerialization(), |
160 | 160 | 'statementGuid' => $context->getSnakStatement()->getGuid(), |
161 | 161 | 'resultStatus' => $result->getStatus(), |
162 | - 'resultParameters' => json_encode( $result->getParameters() ), |
|
162 | + 'resultParameters' => json_encode($result->getParameters()), |
|
163 | 163 | 'resultMessage' => $resultMessageKey, |
164 | 164 | ] |
165 | 165 | ); |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | ); |
190 | 190 | |
191 | 191 | // find the longest limit (and associated log level) that the duration exceeds |
192 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
192 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
193 | 193 | $this->constraintCheckOnEntityDurationLimits, |
194 | 194 | $durationSeconds |
195 | 195 | ); |
196 | - if ( $limitSeconds === null ) { |
|
196 | + if ($limitSeconds === null) { |
|
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
200 | 200 | $this->logger->log( |
201 | 201 | $logLevel, |
202 | - 'Full constraint check on {entityId} ' . |
|
203 | - 'took longer than {limitSeconds} second(s) ' . |
|
202 | + 'Full constraint check on {entityId} '. |
|
203 | + 'took longer than {limitSeconds} second(s) '. |
|
204 | 204 | '(duration: {durationSeconds} seconds).', |
205 | 205 | [ |
206 | 206 | 'method' => $method, |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @param EntityId $entityId |
220 | 220 | */ |
221 | - public function logCheckConstraintsCacheHit( EntityId $entityId ) { |
|
221 | + public function logCheckConstraintsCacheHit(EntityId $entityId) { |
|
222 | 222 | $this->dataFactory->increment( |
223 | 223 | 'wikibase.quality.constraints.cache.entity.hit' |
224 | 224 | ); |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @param EntityId[] $entityIds |
231 | 231 | */ |
232 | - public function logCheckConstraintsCacheMisses( array $entityIds ) { |
|
232 | + public function logCheckConstraintsCacheMisses(array $entityIds) { |
|
233 | 233 | $this->dataFactory->updateCount( |
234 | 234 | 'wikibase.quality.constraints.cache.entity.miss', |
235 | - count( $entityIds ) |
|
235 | + count($entityIds) |
|
236 | 236 | ); |
237 | 237 | } |
238 | 238 | |
@@ -259,17 +259,17 @@ discard block |
||
259 | 259 | * @param EntityId[] $entityIds |
260 | 260 | * @param int $maxRevisionIds |
261 | 261 | */ |
262 | - public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) { |
|
262 | + public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) { |
|
263 | 263 | $this->logger->log( |
264 | 264 | 'warning', |
265 | - 'Dependency metadata for constraint check result has huge set of entity IDs ' . |
|
266 | - '(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' . |
|
265 | + 'Dependency metadata for constraint check result has huge set of entity IDs '. |
|
266 | + '(count '.count($entityIds).', limit '.$maxRevisionIds.'); '. |
|
267 | 267 | 'caching disabled for this check result.', |
268 | 268 | [ |
269 | 269 | 'loggingMethod' => __METHOD__, |
270 | 270 | 'entityIds' => json_encode( |
271 | 271 | array_map( |
272 | - static function ( EntityId $entityId ) { |
|
272 | + static function(EntityId $entityId) { |
|
273 | 273 | return $entityId->getSerialization(); |
274 | 274 | }, |
275 | 275 | $entityIds |
@@ -288,17 +288,17 @@ discard block |
||
288 | 288 | 'Sparql API replied with status 429 and a retry-after header. Requesting to retry after {retryAfterTime}', |
289 | 289 | [ |
290 | 290 | 'retryAfterTime' => $retryAfterTime, |
291 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
291 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
292 | 292 | 'responseContent' => $request->getContent(), |
293 | 293 | ] |
294 | 294 | ); |
295 | 295 | } |
296 | 296 | |
297 | - public function logSparqlHelperTooManyRequestsRetryAfterInvalid( MWHttpRequest $request ) { |
|
297 | + public function logSparqlHelperTooManyRequestsRetryAfterInvalid(MWHttpRequest $request) { |
|
298 | 298 | $this->logger->warning( |
299 | 299 | 'Sparql API replied with status 429 and no valid retry-after header.', |
300 | 300 | [ |
301 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
301 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
302 | 302 | 'responseContent' => $request->getContent(), |
303 | 303 | ] |
304 | 304 | ); |
@@ -199,73 +199,73 @@ discard block |
||
199 | 199 | $this->defaultUserAgent = $defaultUserAgent; |
200 | 200 | $this->requestFactory = $requestFactory; |
201 | 201 | $this->entityPrefixes = []; |
202 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
203 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
202 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
203 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
204 | 204 | } |
205 | 205 | |
206 | - $this->endpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
207 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
208 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
209 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
210 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
206 | + $this->endpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
207 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
208 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
209 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
210 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
211 | 211 | $this->timeoutExceptionClasses = $config->get( |
212 | 212 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
213 | 213 | ); |
214 | 214 | $this->sparqlHasWikibaseSupport = $config->get( |
215 | 215 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
216 | 216 | ); |
217 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
217 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
218 | 218 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
219 | 219 | ); |
220 | 220 | |
221 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
221 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
222 | 222 | } |
223 | 223 | |
224 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
224 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
225 | 225 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
226 | 226 | $prefixes = ''; |
227 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
227 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
228 | 228 | $prefixes .= <<<END |
229 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
229 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
230 | 230 | END; |
231 | 231 | } |
232 | 232 | $prefixes .= <<<END |
233 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
234 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
233 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
234 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
235 | 235 | END; |
236 | 236 | |
237 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
237 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
238 | 238 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
239 | 239 | $prefixes .= <<<END |
240 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
240 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
241 | 241 | END; |
242 | 242 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
243 | 243 | $prefixes .= <<<END |
244 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
244 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
245 | 245 | END; |
246 | 246 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
247 | 247 | $prefixes .= <<<END |
248 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
248 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
249 | 249 | END; |
250 | 250 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
251 | 251 | $prefixes .= <<<END |
252 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
252 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
253 | 253 | END; |
254 | 254 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
255 | 255 | $prefixes .= <<<END |
256 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
256 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
257 | 257 | END; |
258 | 258 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
259 | 259 | $prefixes .= <<<END |
260 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
260 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
261 | 261 | END; |
262 | 262 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
263 | 263 | $prefixes .= <<<END |
264 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
264 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
265 | 265 | END; |
266 | 266 | } |
267 | 267 | $prefixes .= <<<END |
268 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
268 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
269 | 269 | END; |
270 | 270 | return $prefixes; |
271 | 271 | } |
@@ -277,21 +277,20 @@ discard block |
||
277 | 277 | * @return CachedBool |
278 | 278 | * @throws SparqlHelperException if the query times out or some other error occurs |
279 | 279 | */ |
280 | - public function hasType( $id, array $classes ) { |
|
280 | + public function hasType($id, array $classes) { |
|
281 | 281 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
282 | 282 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
283 | - ' hint:Prior hint:gearing "forward".' : |
|
284 | - ''; |
|
283 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
285 | 284 | |
286 | 285 | $metadatas = []; |
287 | 286 | |
288 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
289 | - $classesValues = implode( ' ', array_map( |
|
290 | - static function ( $class ) { |
|
291 | - return 'wd:' . $class; |
|
287 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
288 | + $classesValues = implode(' ', array_map( |
|
289 | + static function($class) { |
|
290 | + return 'wd:'.$class; |
|
292 | 291 | }, |
293 | 292 | $classesChunk |
294 | - ) ); |
|
293 | + )); |
|
295 | 294 | |
296 | 295 | $query = <<<EOF |
297 | 296 | ASK { |
@@ -301,19 +300,19 @@ discard block |
||
301 | 300 | } |
302 | 301 | EOF; |
303 | 302 | |
304 | - $result = $this->runQuery( $query ); |
|
303 | + $result = $this->runQuery($query); |
|
305 | 304 | $metadatas[] = $result->getMetadata(); |
306 | - if ( $result->getArray()['boolean'] ) { |
|
305 | + if ($result->getArray()['boolean']) { |
|
307 | 306 | return new CachedBool( |
308 | 307 | true, |
309 | - Metadata::merge( $metadatas ) |
|
308 | + Metadata::merge($metadatas) |
|
310 | 309 | ); |
311 | 310 | } |
312 | 311 | } |
313 | 312 | |
314 | 313 | return new CachedBool( |
315 | 314 | false, |
316 | - Metadata::merge( $metadatas ) |
|
315 | + Metadata::merge($metadatas) |
|
317 | 316 | ); |
318 | 317 | } |
319 | 318 | |
@@ -329,10 +328,10 @@ discard block |
||
329 | 328 | $ignoreDeprecatedStatements |
330 | 329 | ) { |
331 | 330 | $pid = $statement->getPropertyId()->serialize(); |
332 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
331 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
333 | 332 | |
334 | 333 | $deprecatedFilter = ''; |
335 | - if ( $ignoreDeprecatedStatements ) { |
|
334 | + if ($ignoreDeprecatedStatements) { |
|
336 | 335 | $deprecatedFilter = 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
337 | 336 | } |
338 | 337 | |
@@ -351,9 +350,9 @@ discard block |
||
351 | 350 | LIMIT 10 |
352 | 351 | EOF; |
353 | 352 | |
354 | - $result = $this->runQuery( $query ); |
|
353 | + $result = $this->runQuery($query); |
|
355 | 354 | |
356 | - return $this->getOtherEntities( $result ); |
|
355 | + return $this->getOtherEntities($result); |
|
357 | 356 | } |
358 | 357 | |
359 | 358 | /** |
@@ -378,16 +377,15 @@ discard block |
||
378 | 377 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
379 | 378 | $snak->getPropertyId() |
380 | 379 | ); |
381 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
382 | - if ( $isFullValue ) { |
|
380 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
381 | + if ($isFullValue) { |
|
383 | 382 | $prefix .= 'v'; |
384 | 383 | } |
385 | 384 | $path = $type === Context::TYPE_QUALIFIER ? |
386 | - "$prefix:$pid" : |
|
387 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
385 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
388 | 386 | |
389 | 387 | $deprecatedFilter = ''; |
390 | - if ( $ignoreDeprecatedStatements ) { |
|
388 | + if ($ignoreDeprecatedStatements) { |
|
391 | 389 | $deprecatedFilter = <<< EOF |
392 | 390 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
393 | 391 | EOF; |
@@ -407,9 +405,9 @@ discard block |
||
407 | 405 | LIMIT 10 |
408 | 406 | EOF; |
409 | 407 | |
410 | - $result = $this->runQuery( $query ); |
|
408 | + $result = $this->runQuery($query); |
|
411 | 409 | |
412 | - return $this->getOtherEntities( $result ); |
|
410 | + return $this->getOtherEntities($result); |
|
413 | 411 | } |
414 | 412 | |
415 | 413 | /** |
@@ -419,8 +417,8 @@ discard block |
||
419 | 417 | * |
420 | 418 | * @return string |
421 | 419 | */ |
422 | - private function stringLiteral( $text ) { |
|
423 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
420 | + private function stringLiteral($text) { |
|
421 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
424 | 422 | } |
425 | 423 | |
426 | 424 | /** |
@@ -430,18 +428,18 @@ discard block |
||
430 | 428 | * |
431 | 429 | * @return CachedEntityIds |
432 | 430 | */ |
433 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
434 | - return new CachedEntityIds( array_map( |
|
435 | - function ( $resultBindings ) { |
|
431 | + private function getOtherEntities(CachedQueryResults $results) { |
|
432 | + return new CachedEntityIds(array_map( |
|
433 | + function($resultBindings) { |
|
436 | 434 | $entityIRI = $resultBindings['otherEntity']['value']; |
437 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
438 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
439 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
435 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
436 | + $entityPrefixLength = strlen($entityPrefix); |
|
437 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
440 | 438 | try { |
441 | 439 | return $this->entityIdParser->parse( |
442 | - substr( $entityIRI, $entityPrefixLength ) |
|
440 | + substr($entityIRI, $entityPrefixLength) |
|
443 | 441 | ); |
444 | - } catch ( EntityIdParsingException $e ) { |
|
442 | + } catch (EntityIdParsingException $e) { |
|
445 | 443 | // fall through |
446 | 444 | } |
447 | 445 | } |
@@ -452,7 +450,7 @@ discard block |
||
452 | 450 | return null; |
453 | 451 | }, |
454 | 452 | $results->getArray()['results']['bindings'] |
455 | - ), $results->getMetadata() ); |
|
453 | + ), $results->getMetadata()); |
|
456 | 454 | } |
457 | 455 | |
458 | 456 | // phpcs:disable Generic.Metrics.CyclomaticComplexity,Squiz.WhiteSpace.FunctionSpacing |
@@ -465,50 +463,50 @@ discard block |
||
465 | 463 | * @return array the literal or IRI as a string in SPARQL syntax, |
466 | 464 | * and a boolean indicating whether it refers to a full value node or not |
467 | 465 | */ |
468 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
469 | - switch ( $dataType ) { |
|
466 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
467 | + switch ($dataType) { |
|
470 | 468 | case 'string': |
471 | 469 | case 'external-id': |
472 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
470 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
473 | 471 | case 'commonsMedia': |
474 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
475 | - return [ '<' . $url . '>', false ]; |
|
472 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
473 | + return ['<'.$url.'>', false]; |
|
476 | 474 | case 'geo-shape': |
477 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
478 | - return [ '<' . $url . '>', false ]; |
|
475 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
476 | + return ['<'.$url.'>', false]; |
|
479 | 477 | case 'tabular-data': |
480 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
481 | - return [ '<' . $url . '>', false ]; |
|
478 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
479 | + return ['<'.$url.'>', false]; |
|
482 | 480 | case 'url': |
483 | 481 | $url = $dataValue->getValue(); |
484 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
482 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
485 | 483 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
486 | 484 | // such an URL should never reach us, so just throw |
487 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
485 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
488 | 486 | } |
489 | - return [ '<' . $url . '>', false ]; |
|
487 | + return ['<'.$url.'>', false]; |
|
490 | 488 | case 'wikibase-item': |
491 | 489 | case 'wikibase-property': |
492 | 490 | /** @var EntityIdValue $dataValue */ |
493 | 491 | '@phan-var EntityIdValue $dataValue'; |
494 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
492 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
495 | 493 | case 'monolingualtext': |
496 | 494 | /** @var MonolingualTextValue $dataValue */ |
497 | 495 | '@phan-var MonolingualTextValue $dataValue'; |
498 | 496 | $lang = $dataValue->getLanguageCode(); |
499 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
497 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
500 | 498 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
501 | 499 | // such a language tag should never reach us, so just throw |
502 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
500 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
503 | 501 | } |
504 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
502 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
505 | 503 | case 'globe-coordinate': |
506 | 504 | case 'quantity': |
507 | 505 | case 'time': |
508 | 506 | // @phan-suppress-next-line PhanUndeclaredMethod |
509 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
507 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
510 | 508 | default: |
511 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
509 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
512 | 510 | } |
513 | 511 | } |
514 | 512 | // phpcs:enable |
@@ -521,43 +519,43 @@ discard block |
||
521 | 519 | * @throws SparqlHelperException if the query times out or some other error occurs |
522 | 520 | * @throws ConstraintParameterException if the $regex is invalid |
523 | 521 | */ |
524 | - public function matchesRegularExpression( $text, $regex ) { |
|
522 | + public function matchesRegularExpression($text, $regex) { |
|
525 | 523 | // caching wrapper around matchesRegularExpressionWithSparql |
526 | 524 | |
527 | - $textHash = hash( 'sha256', $text ); |
|
525 | + $textHash = hash('sha256', $text); |
|
528 | 526 | $cacheKey = $this->cache->makeKey( |
529 | 527 | 'WikibaseQualityConstraints', // extension |
530 | 528 | 'regex', // action |
531 | 529 | 'WDQS-Java', // regex flavor |
532 | - hash( 'sha256', $regex ) |
|
530 | + hash('sha256', $regex) |
|
533 | 531 | ); |
534 | 532 | |
535 | 533 | $cacheMapArray = $this->cache->getWithSetCallback( |
536 | 534 | $cacheKey, |
537 | 535 | WANObjectCache::TTL_DAY, |
538 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
536 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
539 | 537 | // Initialize the cache map if not set |
540 | - if ( $cacheMapArray === false ) { |
|
538 | + if ($cacheMapArray === false) { |
|
541 | 539 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
542 | - $this->dataFactory->increment( $key ); |
|
540 | + $this->dataFactory->increment($key); |
|
543 | 541 | return []; |
544 | 542 | } |
545 | 543 | |
546 | 544 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
547 | - $this->dataFactory->increment( $key ); |
|
548 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
549 | - if ( $cacheMap->has( $textHash ) ) { |
|
545 | + $this->dataFactory->increment($key); |
|
546 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
547 | + if ($cacheMap->has($textHash)) { |
|
550 | 548 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
551 | - $this->dataFactory->increment( $key ); |
|
552 | - $cacheMap->get( $textHash ); // ping cache |
|
549 | + $this->dataFactory->increment($key); |
|
550 | + $cacheMap->get($textHash); // ping cache |
|
553 | 551 | } else { |
554 | 552 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
555 | - $this->dataFactory->increment( $key ); |
|
553 | + $this->dataFactory->increment($key); |
|
556 | 554 | try { |
557 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
558 | - } catch ( ConstraintParameterException $e ) { |
|
559 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
560 | - } catch ( SparqlHelperException $e ) { |
|
555 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
556 | + } catch (ConstraintParameterException $e) { |
|
557 | + $matches = $this->serializeConstraintParameterException($e); |
|
558 | + } catch (SparqlHelperException $e) { |
|
561 | 559 | // don’t cache this |
562 | 560 | return $cacheMap->toArray(); |
563 | 561 | } |
@@ -581,42 +579,42 @@ discard block |
||
581 | 579 | ] |
582 | 580 | ); |
583 | 581 | |
584 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
582 | + if (isset($cacheMapArray[$textHash])) { |
|
585 | 583 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
586 | - $this->dataFactory->increment( $key ); |
|
584 | + $this->dataFactory->increment($key); |
|
587 | 585 | $matches = $cacheMapArray[$textHash]; |
588 | - if ( is_bool( $matches ) ) { |
|
586 | + if (is_bool($matches)) { |
|
589 | 587 | return $matches; |
590 | - } elseif ( is_array( $matches ) && |
|
591 | - $matches['type'] == ConstraintParameterException::class ) { |
|
592 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
588 | + } elseif (is_array($matches) && |
|
589 | + $matches['type'] == ConstraintParameterException::class) { |
|
590 | + throw $this->deserializeConstraintParameterException($matches); |
|
593 | 591 | } else { |
594 | 592 | throw new MWException( |
595 | - 'Value of unknown type in object cache (' . |
|
596 | - 'cache key: ' . $cacheKey . ', ' . |
|
597 | - 'cache map key: ' . $textHash . ', ' . |
|
598 | - 'value type: ' . gettype( $matches ) . ')' |
|
593 | + 'Value of unknown type in object cache ('. |
|
594 | + 'cache key: '.$cacheKey.', '. |
|
595 | + 'cache map key: '.$textHash.', '. |
|
596 | + 'value type: '.gettype($matches).')' |
|
599 | 597 | ); |
600 | 598 | } |
601 | 599 | } else { |
602 | 600 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
603 | - $this->dataFactory->increment( $key ); |
|
604 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
601 | + $this->dataFactory->increment($key); |
|
602 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
605 | 603 | } |
606 | 604 | } |
607 | 605 | |
608 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
606 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
609 | 607 | return [ |
610 | 608 | 'type' => ConstraintParameterException::class, |
611 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
609 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
612 | 610 | ]; |
613 | 611 | } |
614 | 612 | |
615 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
613 | + private function deserializeConstraintParameterException(array $serialization) { |
|
616 | 614 | $message = $this->violationMessageDeserializer->deserialize( |
617 | 615 | $serialization['violationMessage'] |
618 | 616 | ); |
619 | - return new ConstraintParameterException( $message ); |
|
617 | + return new ConstraintParameterException($message); |
|
620 | 618 | } |
621 | 619 | |
622 | 620 | /** |
@@ -630,25 +628,25 @@ discard block |
||
630 | 628 | * @throws SparqlHelperException if the query times out or some other error occurs |
631 | 629 | * @throws ConstraintParameterException if the $regex is invalid |
632 | 630 | */ |
633 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
634 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
635 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
631 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
632 | + $textStringLiteral = $this->stringLiteral($text); |
|
633 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
636 | 634 | |
637 | 635 | $query = <<<EOF |
638 | 636 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
639 | 637 | EOF; |
640 | 638 | |
641 | - $result = $this->runQuery( $query, false ); |
|
639 | + $result = $this->runQuery($query, false); |
|
642 | 640 | |
643 | 641 | $vars = $result->getArray()['results']['bindings'][0]; |
644 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
642 | + if (array_key_exists('matches', $vars)) { |
|
645 | 643 | // true or false ⇒ regex okay, text matches or not |
646 | 644 | return $vars['matches']['value'] === 'true'; |
647 | 645 | } else { |
648 | 646 | // empty result: regex broken |
649 | 647 | throw new ConstraintParameterException( |
650 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
651 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
648 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
649 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
652 | 650 | ); |
653 | 651 | } |
654 | 652 | } |
@@ -660,14 +658,14 @@ discard block |
||
660 | 658 | * |
661 | 659 | * @return boolean |
662 | 660 | */ |
663 | - public function isTimeout( $responseContent ) { |
|
664 | - $timeoutRegex = implode( '|', array_map( |
|
665 | - static function ( $fqn ) { |
|
666 | - return preg_quote( $fqn, '/' ); |
|
661 | + public function isTimeout($responseContent) { |
|
662 | + $timeoutRegex = implode('|', array_map( |
|
663 | + static function($fqn) { |
|
664 | + return preg_quote($fqn, '/'); |
|
667 | 665 | }, |
668 | 666 | $this->timeoutExceptionClasses |
669 | - ) ); |
|
670 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
667 | + )); |
|
668 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
671 | 669 | } |
672 | 670 | |
673 | 671 | /** |
@@ -679,17 +677,17 @@ discard block |
||
679 | 677 | * @return int|boolean the max-age (in seconds) |
680 | 678 | * or a plain boolean if no max-age can be determined |
681 | 679 | */ |
682 | - public function getCacheMaxAge( $responseHeaders ) { |
|
680 | + public function getCacheMaxAge($responseHeaders) { |
|
683 | 681 | if ( |
684 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
685 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
682 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
683 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
686 | 684 | ) { |
687 | 685 | $maxage = []; |
688 | 686 | if ( |
689 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
690 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
687 | + array_key_exists('cache-control', $responseHeaders) && |
|
688 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
691 | 689 | ) { |
692 | - return intval( $maxage[1] ); |
|
690 | + return intval($maxage[1]); |
|
693 | 691 | } else { |
694 | 692 | return true; |
695 | 693 | } |
@@ -710,34 +708,34 @@ discard block |
||
710 | 708 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
711 | 709 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
712 | 710 | */ |
713 | - public function getThrottling( MWHttpRequest $request ) { |
|
714 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
715 | - if ( $retryAfterValue === null ) { |
|
711 | + public function getThrottling(MWHttpRequest $request) { |
|
712 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
713 | + if ($retryAfterValue === null) { |
|
716 | 714 | return self::NO_RETRY_AFTER; |
717 | 715 | } |
718 | 716 | |
719 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
720 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
717 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
718 | + if (empty($trimmedRetryAfterValue)) { |
|
721 | 719 | return self::EMPTY_RETRY_AFTER; |
722 | 720 | } |
723 | 721 | |
724 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
725 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
726 | - if ( $delaySeconds >= 0 ) { |
|
727 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
722 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
723 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
724 | + if ($delaySeconds >= 0) { |
|
725 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
728 | 726 | } |
729 | 727 | } else { |
730 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
731 | - if ( !empty( $return ) ) { |
|
732 | - return new ConvertibleTimestamp( $return ); |
|
728 | + $return = strtotime($trimmedRetryAfterValue); |
|
729 | + if (!empty($return)) { |
|
730 | + return new ConvertibleTimestamp($return); |
|
733 | 731 | } |
734 | 732 | } |
735 | 733 | return self::INVALID_RETRY_AFTER; |
736 | 734 | } |
737 | 735 | |
738 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
736 | + private function getTimestampInFuture(DateInterval $delta) { |
|
739 | 737 | $now = new ConvertibleTimestamp(); |
740 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
738 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
741 | 739 | } |
742 | 740 | |
743 | 741 | /** |
@@ -751,65 +749,64 @@ discard block |
||
751 | 749 | * |
752 | 750 | * @throws SparqlHelperException if the query times out or some other error occurs |
753 | 751 | */ |
754 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
752 | + public function runQuery($query, $needsPrefixes = true) { |
|
755 | 753 | |
756 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
757 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
754 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
755 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
758 | 756 | throw new TooManySparqlRequestsException(); |
759 | 757 | } |
760 | 758 | |
761 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
759 | + if ($this->sparqlHasWikibaseSupport) { |
|
762 | 760 | $needsPrefixes = false; |
763 | 761 | } |
764 | 762 | |
765 | - if ( $needsPrefixes ) { |
|
766 | - $query = $this->prefixes . $query; |
|
763 | + if ($needsPrefixes) { |
|
764 | + $query = $this->prefixes.$query; |
|
767 | 765 | } |
768 | - $query = "#wbqc\n" . $query; |
|
766 | + $query = "#wbqc\n".$query; |
|
769 | 767 | |
770 | - $url = $this->endpoint . '?' . http_build_query( |
|
768 | + $url = $this->endpoint.'?'.http_build_query( |
|
771 | 769 | [ |
772 | 770 | 'query' => $query, |
773 | 771 | 'format' => 'json', |
774 | 772 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
775 | 773 | ], |
776 | - null, ini_get( 'arg_separator.output' ), |
|
774 | + null, ini_get('arg_separator.output'), |
|
777 | 775 | // encode spaces with %20, not + |
778 | 776 | PHP_QUERY_RFC3986 |
779 | 777 | ); |
780 | 778 | |
781 | 779 | $options = [ |
782 | 780 | 'method' => 'GET', |
783 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
781 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
784 | 782 | 'connectTimeout' => 'default', |
785 | 783 | 'userAgent' => $this->defaultUserAgent, |
786 | 784 | ]; |
787 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
788 | - $startTime = microtime( true ); |
|
785 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
786 | + $startTime = microtime(true); |
|
789 | 787 | $requestStatus = $request->execute(); |
790 | - $endTime = microtime( true ); |
|
788 | + $endTime = microtime(true); |
|
791 | 789 | $this->dataFactory->timing( |
792 | 790 | 'wikibase.quality.constraints.sparql.timing', |
793 | - ( $endTime - $startTime ) * 1000 |
|
791 | + ($endTime - $startTime) * 1000 |
|
794 | 792 | ); |
795 | 793 | |
796 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
794 | + $this->guardAgainstTooManyRequestsError($request); |
|
797 | 795 | |
798 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
799 | - if ( $maxAge ) { |
|
800 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
796 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
797 | + if ($maxAge) { |
|
798 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
801 | 799 | } |
802 | 800 | |
803 | - if ( $requestStatus->isOK() ) { |
|
801 | + if ($requestStatus->isOK()) { |
|
804 | 802 | $json = $request->getContent(); |
805 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
806 | - if ( $jsonStatus->isOK() ) { |
|
803 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
804 | + if ($jsonStatus->isOK()) { |
|
807 | 805 | return new CachedQueryResults( |
808 | 806 | $jsonStatus->getValue(), |
809 | 807 | Metadata::ofCachingMetadata( |
810 | 808 | $maxAge ? |
811 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
812 | - CachingMetadata::fresh() |
|
809 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
813 | 810 | ) |
814 | 811 | ); |
815 | 812 | } else { |
@@ -826,9 +823,9 @@ discard block |
||
826 | 823 | // fall through to general error handling |
827 | 824 | } |
828 | 825 | |
829 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
826 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
830 | 827 | |
831 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
828 | + if ($this->isTimeout($request->getContent())) { |
|
832 | 829 | $this->dataFactory->increment( |
833 | 830 | 'wikibase.quality.constraints.sparql.error.timeout' |
834 | 831 | ); |
@@ -843,29 +840,29 @@ discard block |
||
843 | 840 | * @param MWHttpRequest $request |
844 | 841 | * @throws TooManySparqlRequestsException |
845 | 842 | */ |
846 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
847 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
843 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
844 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
848 | 845 | return; |
849 | 846 | } |
850 | 847 | |
851 | 848 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
852 | 849 | |
853 | - if ( $fallbackBlockDuration < 0 ) { |
|
854 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
855 | - $fallbackBlockDuration ); |
|
850 | + if ($fallbackBlockDuration < 0) { |
|
851 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
852 | + $fallbackBlockDuration); |
|
856 | 853 | } |
857 | 854 | |
858 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
859 | - $throttlingUntil = $this->getThrottling( $request ); |
|
860 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
861 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
855 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
856 | + $throttlingUntil = $this->getThrottling($request); |
|
857 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
858 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
862 | 859 | $this->throttlingLock->lock( |
863 | 860 | self::EXPIRY_LOCK_ID, |
864 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
861 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
865 | 862 | ); |
866 | 863 | } else { |
867 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
868 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
864 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
865 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
869 | 866 | } |
870 | 867 | throw new TooManySparqlRequestsException(); |
871 | 868 | } |
@@ -20,13 +20,13 @@ |
||
20 | 20 | * @param PropertyId $propertyId |
21 | 21 | * @return int |
22 | 22 | */ |
23 | - public function getPropertyCount( array $snaks, PropertyId $propertyId ) { |
|
24 | - return count( array_filter( |
|
23 | + public function getPropertyCount(array $snaks, PropertyId $propertyId) { |
|
24 | + return count(array_filter( |
|
25 | 25 | $snaks, |
26 | - static function ( Snak $snak ) use ( $propertyId ) { |
|
27 | - return $snak->getPropertyId()->equals( $propertyId ); |
|
26 | + static function(Snak $snak) use ($propertyId) { |
|
27 | + return $snak->getPropertyId()->equals($propertyId); |
|
28 | 28 | } |
29 | - ) ); |
|
29 | + )); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | } |
@@ -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', |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | $value = $argument['value']; |
139 | 139 | $role = $argument['role']; |
140 | 140 | |
141 | - if ( array_key_exists( $type, $methods ) ) { |
|
141 | + if (array_key_exists($type, $methods)) { |
|
142 | 142 | $method = $methods[$type]; |
143 | - $params = $this->$method( $value, $role ); |
|
143 | + $params = $this->$method($value, $role); |
|
144 | 144 | } else { |
145 | 145 | throw new InvalidArgumentException( |
146 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
146 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
147 | 147 | ); |
148 | 148 | } |
149 | 149 | |
@@ -157,46 +157,46 @@ discard block |
||
157 | 157 | * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ]) |
158 | 158 | * @return array[] list of parameters as accepted by Message::params() |
159 | 159 | */ |
160 | - private function renderList( array $list, $role, callable $render ) { |
|
161 | - if ( $list === [] ) { |
|
160 | + private function renderList(array $list, $role, callable $render) { |
|
161 | + if ($list === []) { |
|
162 | 162 | return [ |
163 | - Message::numParam( 0 ), |
|
164 | - Message::rawParam( '<ul></ul>' ), |
|
163 | + Message::numParam(0), |
|
164 | + Message::rawParam('<ul></ul>'), |
|
165 | 165 | ]; |
166 | 166 | } |
167 | 167 | |
168 | - if ( count( $list ) > $this->maxListLength ) { |
|
169 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
168 | + if (count($list) > $this->maxListLength) { |
|
169 | + $list = array_slice($list, 0, $this->maxListLength); |
|
170 | 170 | $truncated = true; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $renderedParamsLists = array_map( |
174 | 174 | $render, |
175 | 175 | $list, |
176 | - array_fill( 0, count( $list ), $role ) |
|
176 | + array_fill(0, count($list), $role) |
|
177 | 177 | ); |
178 | 178 | $renderedParams = array_map( |
179 | - static function ( $params ) { |
|
179 | + static function($params) { |
|
180 | 180 | return $params[0]; |
181 | 181 | }, |
182 | 182 | $renderedParamsLists |
183 | 183 | ); |
184 | 184 | $renderedElements = array_map( |
185 | - static function ( $param ) { |
|
185 | + static function($param) { |
|
186 | 186 | return $param['raw']; |
187 | 187 | }, |
188 | 188 | $renderedParams |
189 | 189 | ); |
190 | - if ( isset( $truncated ) ) { |
|
191 | - $renderedElements[] = $this->msgEscaped( 'ellipsis' ); |
|
190 | + if (isset($truncated)) { |
|
191 | + $renderedElements[] = $this->msgEscaped('ellipsis'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | return array_merge( |
195 | 195 | [ |
196 | - Message::numParam( count( $list ) ), |
|
196 | + Message::numParam(count($list)), |
|
197 | 197 | Message::rawParam( |
198 | - '<ul><li>' . |
|
199 | - implode( '</li><li>', $renderedElements ) . |
|
198 | + '<ul><li>'. |
|
199 | + implode('</li><li>', $renderedElements). |
|
200 | 200 | '</li></ul>' |
201 | 201 | ), |
202 | 202 | ], |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | * @param string|null $role one of the Role::* constants |
210 | 210 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
211 | 211 | */ |
212 | - private function renderEntityId( EntityId $entityId, $role ) { |
|
213 | - return [ Message::rawParam( $this->addRole( |
|
214 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
212 | + private function renderEntityId(EntityId $entityId, $role) { |
|
213 | + return [Message::rawParam($this->addRole( |
|
214 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
215 | 215 | $role |
216 | - ) ) ]; |
|
216 | + ))]; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * @param string|null $role one of the Role::* constants |
222 | 222 | * @return array[] list of parameters as accepted by Message::params() |
223 | 223 | */ |
224 | - private function renderEntityIdList( array $entityIdList, $role ) { |
|
225 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
224 | + private function renderEntityIdList(array $entityIdList, $role) { |
|
225 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -230,24 +230,24 @@ discard block |
||
230 | 230 | * @param string|null $role one of the Role::* constants |
231 | 231 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
232 | 232 | */ |
233 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) { |
|
234 | - switch ( true ) { |
|
233 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) { |
|
234 | + switch (true) { |
|
235 | 235 | case $value->isValue(): |
236 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
236 | + return $this->renderEntityId($value->getItemId(), $role); |
|
237 | 237 | case $value->isSomeValue(): |
238 | - return [ Message::rawParam( $this->addRole( |
|
239 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
240 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) . |
|
238 | + return [Message::rawParam($this->addRole( |
|
239 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
240 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue'). |
|
241 | 241 | '</span>', |
242 | 242 | $role |
243 | - ) ) ]; |
|
243 | + ))]; |
|
244 | 244 | case $value->isNoValue(): |
245 | - return [ Message::rawParam( $this->addRole( |
|
246 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
247 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) . |
|
245 | + return [Message::rawParam($this->addRole( |
|
246 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
247 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-novalue'). |
|
248 | 248 | '</span>', |
249 | 249 | $role |
250 | - ) ) ]; |
|
250 | + ))]; |
|
251 | 251 | default: |
252 | 252 | // @codeCoverageIgnoreStart |
253 | 253 | throw new LogicException( |
@@ -262,8 +262,8 @@ 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 renderItemIdSnakValueList( array $valueList, $role ) { |
|
266 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
265 | + private function renderItemIdSnakValueList(array $valueList, $role) { |
|
266 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | * @param string|null $role one of the Role::* constants |
272 | 272 | * @return array[] list of parameters as accepted by Message::params() |
273 | 273 | */ |
274 | - private function renderDataValue( DataValue $dataValue, $role ) { |
|
275 | - return [ Message::rawParam( $this->addRole( |
|
276 | - $this->dataValueFormatter->format( $dataValue ), |
|
274 | + private function renderDataValue(DataValue $dataValue, $role) { |
|
275 | + return [Message::rawParam($this->addRole( |
|
276 | + $this->dataValueFormatter->format($dataValue), |
|
277 | 277 | $role |
278 | - ) ) ]; |
|
278 | + ))]; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string|null $role one of the Role::* constants |
284 | 284 | * @return array[] list of parameters as accepted by Message::params() |
285 | 285 | */ |
286 | - private function renderDataValueType( $dataValueType, $role ) { |
|
286 | + private function renderDataValueType($dataValueType, $role) { |
|
287 | 287 | $messageKeys = [ |
288 | 288 | 'string' => 'datatypes-type-string', |
289 | 289 | 'monolingualtext' => 'datatypes-type-monolingualtext', |
@@ -292,15 +292,15 @@ discard block |
||
292 | 292 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
293 | 293 | ]; |
294 | 294 | |
295 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
296 | - return [ Message::rawParam( $this->addRole( |
|
297 | - $this->msgEscaped( $messageKeys[$dataValueType] ), |
|
295 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
296 | + return [Message::rawParam($this->addRole( |
|
297 | + $this->msgEscaped($messageKeys[$dataValueType]), |
|
298 | 298 | $role |
299 | - ) ) ]; |
|
299 | + ))]; |
|
300 | 300 | } else { |
301 | 301 | // @codeCoverageIgnoreStart |
302 | 302 | throw new LogicException( |
303 | - 'Unknown data value type ' . $dataValueType |
|
303 | + 'Unknown data value type '.$dataValueType |
|
304 | 304 | ); |
305 | 305 | // @codeCoverageIgnoreEnd |
306 | 306 | } |
@@ -311,11 +311,11 @@ discard block |
||
311 | 311 | * @param string|null $role one of the Role::* constants |
312 | 312 | * @return array[] list of parameters as accepted by Message::params() |
313 | 313 | */ |
314 | - private function renderInlineCode( $code, $role ) { |
|
315 | - return [ Message::rawParam( $this->addRole( |
|
316 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
314 | + private function renderInlineCode($code, $role) { |
|
315 | + return [Message::rawParam($this->addRole( |
|
316 | + '<code>'.htmlspecialchars($code).'</code>', |
|
317 | 317 | $role |
318 | - ) ) ]; |
|
318 | + ))]; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param string|null $role one of the Role::* constants |
324 | 324 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
325 | 325 | */ |
326 | - private function renderConstraintScope( $scope, $role ) { |
|
327 | - switch ( $scope ) { |
|
326 | + private function renderConstraintScope($scope, $role) { |
|
327 | + switch ($scope) { |
|
328 | 328 | case Context::TYPE_STATEMENT: |
329 | 329 | $itemId = $this->config->get( |
330 | 330 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -344,10 +344,10 @@ discard block |
||
344 | 344 | // callers should never let this happen, but if it does happen, |
345 | 345 | // showing “unknown value” seems reasonable |
346 | 346 | // @codeCoverageIgnoreStart |
347 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
347 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
348 | 348 | // @codeCoverageIgnoreEnd |
349 | 349 | } |
350 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
350 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -355,8 +355,8 @@ discard block |
||
355 | 355 | * @param string|null $role one of the Role::* constants |
356 | 356 | * @return array[] list of parameters as accepted by Message::params() |
357 | 357 | */ |
358 | - private function renderConstraintScopeList( array $scopeList, $role ) { |
|
359 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
358 | + private function renderConstraintScopeList(array $scopeList, $role) { |
|
359 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -364,25 +364,25 @@ discard block |
||
364 | 364 | * @param string|null $role one of the Role::* constants |
365 | 365 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
366 | 366 | */ |
367 | - private function renderPropertyScope( $scope, $role ) { |
|
368 | - switch ( $scope ) { |
|
367 | + private function renderPropertyScope($scope, $role) { |
|
368 | + switch ($scope) { |
|
369 | 369 | case Context::TYPE_STATEMENT: |
370 | - $itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
370 | + $itemId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
371 | 371 | break; |
372 | 372 | case Context::TYPE_QUALIFIER: |
373 | - $itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
373 | + $itemId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
374 | 374 | break; |
375 | 375 | case Context::TYPE_REFERENCE: |
376 | - $itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
376 | + $itemId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
377 | 377 | break; |
378 | 378 | default: |
379 | 379 | // callers should never let this happen, but if it does happen, |
380 | 380 | // showing “unknown value” seems reasonable |
381 | 381 | // @codeCoverageIgnoreStart |
382 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
382 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
383 | 383 | // @codeCoverageIgnoreEnd |
384 | 384 | } |
385 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
385 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -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 renderPropertyScopeList( array $scopeList, $role ) { |
|
394 | - return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] ); |
|
393 | + private function renderPropertyScopeList(array $scopeList, $role) { |
|
394 | + return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -399,10 +399,10 @@ discard block |
||
399 | 399 | * @param string|null $role one of the Role::* constants |
400 | 400 | * @return array[] list of parameters as accepted by Message::params() |
401 | 401 | */ |
402 | - private function renderLanguage( $languageCode, $role ) { |
|
402 | + private function renderLanguage($languageCode, $role) { |
|
403 | 403 | return [ |
404 | - Message::plaintextParam( Language::fetchLanguageName( $languageCode ) ), |
|
405 | - Message::plaintextParam( $languageCode ), |
|
404 | + Message::plaintextParam(Language::fetchLanguageName($languageCode)), |
|
405 | + Message::plaintextParam($languageCode), |
|
406 | 406 | ]; |
407 | 407 | } |
408 | 408 |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | * @param CheckResult $checkResult |
77 | 77 | * @return array |
78 | 78 | */ |
79 | - public function serialize( CheckResult $checkResult ) { |
|
79 | + public function serialize(CheckResult $checkResult) { |
|
80 | 80 | $contextCursor = $checkResult->getContextCursor(); |
81 | 81 | |
82 | 82 | $serialization = [ |
83 | - self::KEY_CONTEXT_CURSOR => $this->contextCursorSerializer->serialize( $contextCursor ), |
|
83 | + self::KEY_CONTEXT_CURSOR => $this->contextCursorSerializer->serialize($contextCursor), |
|
84 | 84 | ]; |
85 | 85 | |
86 | - if ( $checkResult instanceof NullResult ) { |
|
86 | + if ($checkResult instanceof NullResult) { |
|
87 | 87 | $serialization[self::KEY_NULL_RESULT] = 1; |
88 | 88 | } else { |
89 | 89 | $constraint = $checkResult->getConstraint(); |
@@ -91,21 +91,21 @@ discard block |
||
91 | 91 | $violationMessage = $checkResult->getMessage(); |
92 | 92 | |
93 | 93 | $serialization[self::KEY_CONSTRAINT] = |
94 | - $this->constraintSerializer->serialize( $constraint ); |
|
94 | + $this->constraintSerializer->serialize($constraint); |
|
95 | 95 | $serialization[self::KEY_CHECK_RESULT_STATUS] = |
96 | 96 | $checkResult->getStatus(); |
97 | 97 | $serialization[self::KEY_CACHING_METADATA] = |
98 | - $this->serializeCachingMetadata( $cachingMetadata ); |
|
98 | + $this->serializeCachingMetadata($cachingMetadata); |
|
99 | 99 | |
100 | - if ( $violationMessage !== null ) { |
|
100 | + if ($violationMessage !== null) { |
|
101 | 101 | $serialization[self::KEY_VIOLATION_MESSAGE] = |
102 | - $this->violationMessageSerializer->serialize( $violationMessage ); |
|
102 | + $this->violationMessageSerializer->serialize($violationMessage); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - if ( $this->serializeDependencyMetadata ) { |
|
106 | + if ($this->serializeDependencyMetadata) { |
|
107 | 107 | $serialization[self::KEY_DEPENDENCY_METADATA] = |
108 | - $this->serializeDependencyMetadata( $checkResult ); |
|
108 | + $this->serializeDependencyMetadata($checkResult); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | return $serialization; |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | * @param CachingMetadata $cachingMetadata |
116 | 116 | * @return array |
117 | 117 | */ |
118 | - private function serializeCachingMetadata( CachingMetadata $cachingMetadata ) { |
|
118 | + private function serializeCachingMetadata(CachingMetadata $cachingMetadata) { |
|
119 | 119 | $maximumAge = $cachingMetadata->getMaximumAgeInSeconds(); |
120 | 120 | |
121 | 121 | $serialization = []; |
122 | 122 | |
123 | - if ( $maximumAge > 0 ) { |
|
123 | + if ($maximumAge > 0) { |
|
124 | 124 | $serialization[self::KEY_CACHING_METADATA_MAX_AGE] = $maximumAge; |
125 | 125 | } |
126 | 126 | |
@@ -131,21 +131,21 @@ discard block |
||
131 | 131 | * @param CheckResult $checkResult |
132 | 132 | * @return array |
133 | 133 | */ |
134 | - private function serializeDependencyMetadata( CheckResult $checkResult ) { |
|
134 | + private function serializeDependencyMetadata(CheckResult $checkResult) { |
|
135 | 135 | $dependencyMetadata = $checkResult->getMetadata()->getDependencyMetadata(); |
136 | 136 | $entityIds = $dependencyMetadata->getEntityIds(); |
137 | 137 | $futureTime = $dependencyMetadata->getFutureTime(); |
138 | 138 | |
139 | 139 | $serialization = [ |
140 | 140 | self::KEY_DEPENDENCY_METADATA_ENTITY_IDS => array_map( |
141 | - static function ( EntityId $entityId ) { |
|
141 | + static function(EntityId $entityId) { |
|
142 | 142 | return $entityId->getSerialization(); |
143 | 143 | }, |
144 | 144 | $entityIds |
145 | 145 | ), |
146 | 146 | ]; |
147 | 147 | |
148 | - if ( $futureTime !== null ) { |
|
148 | + if ($futureTime !== null) { |
|
149 | 149 | $serialization[self::KEY_DEPENDENCY_METADATA_FUTURE_TIME] = |
150 | 150 | $futureTime->getArrayValue(); |
151 | 151 | } |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
76 | 76 | * @return CheckResult |
77 | 77 | */ |
78 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
79 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
80 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
78 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
79 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
80 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
81 | 81 | } |
82 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
83 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE ); |
|
82 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
83 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $parameters = []; |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | $constraintTypeItemId |
93 | 93 | ); |
94 | 94 | $parameters['class'] = array_map( |
95 | - static function ( $id ) { |
|
96 | - return new ItemId( $id ); |
|
95 | + static function($id) { |
|
96 | + return new ItemId($id); |
|
97 | 97 | }, |
98 | 98 | $classes |
99 | 99 | ); |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | $constraintTypeItemId |
104 | 104 | ); |
105 | 105 | $relationIds = []; |
106 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
107 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
106 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
107 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
108 | 108 | } |
109 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
110 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
109 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
110 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
111 | 111 | } |
112 | - $parameters['relation'] = [ $relation ]; |
|
112 | + $parameters['relation'] = [$relation]; |
|
113 | 113 | |
114 | 114 | $result = $this->typeCheckerHelper->hasClassInRelation( |
115 | 115 | $context->getEntity()->getStatements(), |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $classes |
118 | 118 | ); |
119 | 119 | |
120 | - if ( $result->getBool() ) { |
|
120 | + if ($result->getBool()) { |
|
121 | 121 | $message = null; |
122 | 122 | $status = CheckResult::STATUS_COMPLIANCE; |
123 | 123 | } else { |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | $status = CheckResult::STATUS_VIOLATION; |
132 | 132 | } |
133 | 133 | |
134 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
135 | - ->withMetadata( $result->getMetadata() ); |
|
134 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
135 | + ->withMetadata($result->getMetadata()); |
|
136 | 136 | } |
137 | 137 | |
138 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
138 | + public function checkConstraintParameters(Constraint $constraint) { |
|
139 | 139 | $constraintParameters = $constraint->getConstraintParameters(); |
140 | 140 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
141 | 141 | $exceptions = []; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $constraintParameters, |
145 | 145 | $constraintTypeItemId |
146 | 146 | ); |
147 | - } catch ( ConstraintParameterException $e ) { |
|
147 | + } catch (ConstraintParameterException $e) { |
|
148 | 148 | $exceptions[] = $e; |
149 | 149 | } |
150 | 150 | try { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $constraintParameters, |
153 | 153 | $constraintTypeItemId |
154 | 154 | ); |
155 | - } catch ( ConstraintParameterException $e ) { |
|
155 | + } catch (ConstraintParameterException $e) { |
|
156 | 156 | $exceptions[] = $e; |
157 | 157 | } |
158 | 158 | return $exceptions; |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
92 | 92 | * @return CheckResult |
93 | 93 | */ |
94 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
95 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
96 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
94 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
95 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
96 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | $parameters = []; |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | $constraintTypeItemId |
106 | 106 | ); |
107 | 107 | $parameters['class'] = array_map( |
108 | - static function ( $id ) { |
|
109 | - return new ItemId( $id ); |
|
108 | + static function($id) { |
|
109 | + return new ItemId($id); |
|
110 | 110 | }, |
111 | 111 | $classes |
112 | 112 | ); |
@@ -116,19 +116,19 @@ discard block |
||
116 | 116 | $constraintTypeItemId |
117 | 117 | ); |
118 | 118 | $relationIds = []; |
119 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
120 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
119 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
120 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
121 | 121 | } |
122 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
123 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
122 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
123 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
124 | 124 | } |
125 | - $parameters['relation'] = [ $relation ]; |
|
125 | + $parameters['relation'] = [$relation]; |
|
126 | 126 | |
127 | 127 | $snak = $context->getSnak(); |
128 | 128 | |
129 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
129 | + if (!$snak instanceof PropertyValueSnak) { |
|
130 | 130 | // nothing to check |
131 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
131 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | $dataValue = $snak->getDataValue(); |
@@ -137,23 +137,23 @@ discard block |
||
137 | 137 | * error handling: |
138 | 138 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
139 | 139 | */ |
140 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
141 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
142 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
143 | - ->withDataValueType( 'wikibase-entityid' ); |
|
144 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
140 | + if (!$dataValue instanceof EntityIdValue) { |
|
141 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
142 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
143 | + ->withDataValueType('wikibase-entityid'); |
|
144 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | try { |
148 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
149 | - } catch ( UnresolvedEntityRedirectException $e ) { |
|
148 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
149 | + } catch (UnresolvedEntityRedirectException $e) { |
|
150 | 150 | // Edge case (double redirect): Pretend the entity doesn't exist |
151 | 151 | $item = null; |
152 | 152 | } |
153 | 153 | |
154 | - if ( !( $item instanceof StatementListProvidingEntity ) ) { |
|
155 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
156 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
154 | + if (!($item instanceof StatementListProvidingEntity)) { |
|
155 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
156 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | $statements = $item->getStatements(); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $classes |
165 | 165 | ); |
166 | 166 | |
167 | - if ( $result->getBool() ) { |
|
167 | + if ($result->getBool()) { |
|
168 | 168 | $message = null; |
169 | 169 | $status = CheckResult::STATUS_COMPLIANCE; |
170 | 170 | } else { |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | $status = CheckResult::STATUS_VIOLATION; |
179 | 179 | } |
180 | 180 | |
181 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
182 | - ->withMetadata( $result->getMetadata() ); |
|
181 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
182 | + ->withMetadata($result->getMetadata()); |
|
183 | 183 | } |
184 | 184 | |
185 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
185 | + public function checkConstraintParameters(Constraint $constraint) { |
|
186 | 186 | $constraintParameters = $constraint->getConstraintParameters(); |
187 | 187 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
188 | 188 | $exceptions = []; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $constraintParameters, |
192 | 192 | $constraintTypeItemId |
193 | 193 | ); |
194 | - } catch ( ConstraintParameterException $e ) { |
|
194 | + } catch (ConstraintParameterException $e) { |
|
195 | 195 | $exceptions[] = $e; |
196 | 196 | } |
197 | 197 | try { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $constraintParameters, |
200 | 200 | $constraintTypeItemId |
201 | 201 | ); |
202 | - } catch ( ConstraintParameterException $e ) { |
|
202 | + } catch (ConstraintParameterException $e) { |
|
203 | 203 | $exceptions[] = $e; |
204 | 204 | } |
205 | 205 | return $exceptions; |
@@ -8,20 +8,20 @@ |
||
8 | 8 | use Wikibase\Repo\WikibaseRepo; |
9 | 9 | |
10 | 10 | return [ |
11 | - WikibaseServices::ENTITY_LOOKUP => static function ( MediaWikiServices $services ) { |
|
11 | + WikibaseServices::ENTITY_LOOKUP => static function(MediaWikiServices $services) { |
|
12 | 12 | return new ExceptionIgnoringEntityLookup( |
13 | - WikibaseRepo::getEntityLookup( $services ) |
|
13 | + WikibaseRepo::getEntityLookup($services) |
|
14 | 14 | ); |
15 | 15 | }, |
16 | 16 | |
17 | - WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function ( MediaWikiServices $services ) { |
|
17 | + WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function(MediaWikiServices $services) { |
|
18 | 18 | return new ExceptionIgnoringEntityLookup( |
19 | - WikibaseRepo::getStore( $services ) |
|
20 | - ->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY ) |
|
19 | + WikibaseRepo::getStore($services) |
|
20 | + ->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY) |
|
21 | 21 | ); |
22 | 22 | }, |
23 | 23 | |
24 | - WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function ( MediaWikiServices $services ) { |
|
25 | - return WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
24 | + WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function(MediaWikiServices $services) { |
|
25 | + return WikibaseRepo::getPropertyDataTypeLookup($services); |
|
26 | 26 | }, |
27 | 27 | ]; |