@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @throws InvalidArgumentException |
43 | 43 | */ |
44 | - public function __construct( $content, $isSortable = false, $isRawContent = false ) { |
|
45 | - Assert::parameterType( 'string', $content, '$content' ); |
|
46 | - Assert::parameterType( 'boolean', $isSortable, '$isSortable' ); |
|
47 | - Assert::parameterType( 'boolean', $isRawContent, '$isRawContent' ); |
|
44 | + public function __construct($content, $isSortable = false, $isRawContent = false) { |
|
45 | + Assert::parameterType('string', $content, '$content'); |
|
46 | + Assert::parameterType('boolean', $isSortable, '$isSortable'); |
|
47 | + Assert::parameterType('boolean', $isRawContent, '$isRawContent'); |
|
48 | 48 | |
49 | 49 | $this->content = $content; |
50 | 50 | $this->isSortable = $isSortable; |
@@ -71,20 +71,20 @@ discard block |
||
71 | 71 | * @return string HTML |
72 | 72 | */ |
73 | 73 | public function toHtml() { |
74 | - $attributes = [ 'role' => 'columnheader button' ]; |
|
74 | + $attributes = ['role' => 'columnheader button']; |
|
75 | 75 | |
76 | - if ( !$this->isSortable ) { |
|
76 | + if (!$this->isSortable) { |
|
77 | 77 | $attributes['class'] = 'unsortable'; |
78 | 78 | } |
79 | 79 | |
80 | - if ( !$this->isRawContent ) { |
|
80 | + if (!$this->isRawContent) { |
|
81 | 81 | // @phan-suppress-next-line SecurityCheck-DoubleEscaped |
82 | - $content = htmlspecialchars( $this->content ); |
|
82 | + $content = htmlspecialchars($this->content); |
|
83 | 83 | } else { |
84 | 84 | $content = $this->content; |
85 | 85 | } |
86 | 86 | |
87 | - return Html::rawElement( 'th', $attributes, $content ); |
|
87 | + return Html::rawElement('th', $attributes, $content); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | Config $config, |
137 | 137 | IBufferingStatsdDataFactory $dataFactory |
138 | 138 | ) { |
139 | - parent::__construct( 'ConstraintReport' ); |
|
139 | + parent::__construct('ConstraintReport'); |
|
140 | 140 | |
141 | 141 | $this->entityLookup = $entityLookup; |
142 | 142 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $language = $this->getLanguage(); |
146 | 146 | |
147 | 147 | $formatterOptions = new FormatterOptions(); |
148 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
148 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
149 | 149 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
150 | 150 | SnakFormatter::FORMAT_HTML, |
151 | 151 | $formatterOptions |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @return string |
206 | 206 | */ |
207 | 207 | public function getDescription() { |
208 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
208 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -217,43 +217,43 @@ discard block |
||
217 | 217 | * @throws EntityIdParsingException |
218 | 218 | * @throws UnexpectedValueException |
219 | 219 | */ |
220 | - public function execute( $subPage ) { |
|
220 | + public function execute($subPage) { |
|
221 | 221 | $out = $this->getOutput(); |
222 | 222 | |
223 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
224 | - if ( $postRequest ) { |
|
225 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
223 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
224 | + if ($postRequest) { |
|
225 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
226 | 226 | return; |
227 | 227 | } |
228 | 228 | |
229 | 229 | $out->enableOOUI(); |
230 | - $out->addModules( $this->getModules() ); |
|
230 | + $out->addModules($this->getModules()); |
|
231 | 231 | |
232 | 232 | $this->setHeaders(); |
233 | 233 | |
234 | - $out->addHTML( $this->getExplanationText() ); |
|
234 | + $out->addHTML($this->getExplanationText()); |
|
235 | 235 | $this->buildEntityIdForm(); |
236 | 236 | |
237 | - if ( !$subPage ) { |
|
237 | + if (!$subPage) { |
|
238 | 238 | return; |
239 | 239 | } |
240 | 240 | |
241 | - if ( !is_string( $subPage ) ) { |
|
242 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
241 | + if (!is_string($subPage)) { |
|
242 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | try { |
246 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
247 | - } catch ( EntityIdParsingException $e ) { |
|
246 | + $entityId = $this->entityIdParser->parse($subPage); |
|
247 | + } catch (EntityIdParsingException $e) { |
|
248 | 248 | $out->addHTML( |
249 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
249 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
250 | 250 | ); |
251 | 251 | return; |
252 | 252 | } |
253 | 253 | |
254 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
254 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
255 | 255 | $out->addHTML( |
256 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
256 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
257 | 257 | ); |
258 | 258 | return; |
259 | 259 | } |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | $this->dataFactory->increment( |
262 | 262 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
263 | 263 | ); |
264 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
264 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
265 | 265 | |
266 | - if ( $results !== [] ) { |
|
266 | + if ($results !== []) { |
|
267 | 267 | $out->addHTML( |
268 | - $this->buildResultHeader( $entityId ) |
|
269 | - . $this->buildSummary( $results ) |
|
270 | - . $this->buildResultTable( $entityId, $results ) |
|
268 | + $this->buildResultHeader($entityId) |
|
269 | + . $this->buildSummary($results) |
|
270 | + . $this->buildResultTable($entityId, $results) |
|
271 | 271 | ); |
272 | 272 | } else { |
273 | 273 | $out->addHTML( |
274 | - $this->buildResultHeader( $entityId ) |
|
275 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
274 | + $this->buildResultHeader($entityId) |
|
275 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
276 | 276 | ); |
277 | 277 | } |
278 | 278 | } |
@@ -288,15 +288,15 @@ discard block |
||
288 | 288 | 'name' => 'entityid', |
289 | 289 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
290 | 290 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
291 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
291 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
292 | 292 | ] |
293 | 293 | ]; |
294 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
295 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
296 | - $htmlForm->setSubmitCallback( function() { |
|
294 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
295 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
296 | + $htmlForm->setSubmitCallback(function() { |
|
297 | 297 | return false; |
298 | 298 | } ); |
299 | - $htmlForm->setMethod( 'post' ); |
|
299 | + $htmlForm->setMethod('post'); |
|
300 | 300 | $htmlForm->show(); |
301 | 301 | } |
302 | 302 | |
@@ -310,16 +310,16 @@ discard block |
||
310 | 310 | * |
311 | 311 | * @return string HTML |
312 | 312 | */ |
313 | - private function buildNotice( $messageKey, $error = false ) { |
|
314 | - if ( !is_string( $messageKey ) ) { |
|
315 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
313 | + private function buildNotice($messageKey, $error = false) { |
|
314 | + if (!is_string($messageKey)) { |
|
315 | + throw new InvalidArgumentException('$message must be string.'); |
|
316 | 316 | } |
317 | - if ( !is_bool( $error ) ) { |
|
318 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
317 | + if (!is_bool($error)) { |
|
318 | + throw new InvalidArgumentException('$error must be bool.'); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | $cssClasses = 'wbqc-constraintreport-notice'; |
322 | - if ( $error ) { |
|
322 | + if ($error) { |
|
323 | 323 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
324 | 324 | } |
325 | 325 | |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | [ |
329 | 329 | 'class' => $cssClasses |
330 | 330 | ], |
331 | - $this->msg( $messageKey )->escaped() |
|
331 | + $this->msg($messageKey)->escaped() |
|
332 | 332 | ); |
333 | 333 | } |
334 | 334 | |
@@ -338,16 +338,16 @@ discard block |
||
338 | 338 | private function getExplanationText() { |
339 | 339 | return Html::rawElement( |
340 | 340 | 'div', |
341 | - [ 'class' => 'wbqc-explanation' ], |
|
341 | + ['class' => 'wbqc-explanation'], |
|
342 | 342 | Html::rawElement( |
343 | 343 | 'p', |
344 | 344 | [], |
345 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
345 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
346 | 346 | ) |
347 | 347 | . Html::rawElement( |
348 | 348 | 'p', |
349 | 349 | [], |
350 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
350 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
351 | 351 | ) |
352 | 352 | ); |
353 | 353 | } |
@@ -359,72 +359,72 @@ discard block |
||
359 | 359 | * @return string HTML |
360 | 360 | * @suppress SecurityCheck-DoubleEscaped |
361 | 361 | */ |
362 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
362 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
363 | 363 | // Set table headers |
364 | 364 | $table = new HtmlTableBuilder( |
365 | 365 | [ |
366 | 366 | new HtmlTableHeaderBuilder( |
367 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
367 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
368 | 368 | true |
369 | 369 | ), |
370 | 370 | new HtmlTableHeaderBuilder( |
371 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(), |
|
371 | + $this->msg('wbqc-constraintreport-result-table-header-property')->escaped(), |
|
372 | 372 | true |
373 | 373 | ), |
374 | 374 | new HtmlTableHeaderBuilder( |
375 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(), |
|
375 | + $this->msg('wbqc-constraintreport-result-table-header-message')->escaped(), |
|
376 | 376 | true |
377 | 377 | ), |
378 | 378 | new HtmlTableHeaderBuilder( |
379 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
379 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
380 | 380 | true |
381 | 381 | ) |
382 | 382 | ] |
383 | 383 | ); |
384 | 384 | |
385 | - foreach ( $results as $result ) { |
|
386 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
385 | + foreach ($results as $result) { |
|
386 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | return $table->toHtml(); |
390 | 390 | } |
391 | 391 | |
392 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
392 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
393 | 393 | $message = $result->getMessage(); |
394 | - if ( $message === null ) { |
|
394 | + if ($message === null) { |
|
395 | 395 | // no row for this result |
396 | 396 | return $table; |
397 | 397 | } |
398 | 398 | |
399 | 399 | // Status column |
400 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
400 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
401 | 401 | |
402 | 402 | // Property column |
403 | - $propertyId = new PropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
403 | + $propertyId = new PropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
404 | 404 | $propertyColumn = $this->getClaimLink( |
405 | 405 | $entityId, |
406 | 406 | $propertyId, |
407 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
407 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
408 | 408 | ); |
409 | 409 | |
410 | 410 | // Message column |
411 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
411 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
412 | 412 | |
413 | 413 | // Constraint column |
414 | 414 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
415 | 415 | try { |
416 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
417 | - } catch ( InvalidArgumentException $e ) { |
|
418 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
416 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
417 | + } catch (InvalidArgumentException $e) { |
|
418 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
419 | 419 | } |
420 | 420 | $constraintLink = $this->getClaimLink( |
421 | 421 | $propertyId, |
422 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
422 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
423 | 423 | $constraintTypeLabel |
424 | 424 | ); |
425 | 425 | $constraintColumn = $this->buildExpandableElement( |
426 | 426 | $constraintLink, |
427 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
427 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
428 | 428 | '[...]' |
429 | 429 | ); |
430 | 430 | |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | * |
465 | 465 | * @return string HTML |
466 | 466 | */ |
467 | - protected function buildResultHeader( EntityId $entityId ) { |
|
468 | - $entityLink = sprintf( '%s (%s)', |
|
469 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
470 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
467 | + protected function buildResultHeader(EntityId $entityId) { |
|
468 | + $entityLink = sprintf('%s (%s)', |
|
469 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
470 | + htmlspecialchars($entityId->getSerialization())); |
|
471 | 471 | |
472 | 472 | return Html::rawElement( |
473 | 473 | 'h3', |
474 | 474 | [], |
475 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
475 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
476 | 476 | ); |
477 | 477 | } |
478 | 478 | |
@@ -483,24 +483,24 @@ discard block |
||
483 | 483 | * |
484 | 484 | * @return string HTML |
485 | 485 | */ |
486 | - protected function buildSummary( array $results ) { |
|
486 | + protected function buildSummary(array $results) { |
|
487 | 487 | $statuses = []; |
488 | - foreach ( $results as $result ) { |
|
489 | - $status = strtolower( $result->getStatus() ); |
|
490 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
488 | + foreach ($results as $result) { |
|
489 | + $status = strtolower($result->getStatus()); |
|
490 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | $statusElements = []; |
494 | - foreach ( $statuses as $status => $count ) { |
|
495 | - if ( $count > 0 ) { |
|
494 | + foreach ($statuses as $status => $count) { |
|
495 | + if ($count > 0) { |
|
496 | 496 | $statusElements[] = |
497 | - $this->formatStatus( $status ) |
|
497 | + $this->formatStatus($status) |
|
498 | 498 | . ': ' |
499 | 499 | . $count; |
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
503 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
503 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
@@ -515,15 +515,15 @@ discard block |
||
515 | 515 | * |
516 | 516 | * @return string HTML |
517 | 517 | */ |
518 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
519 | - if ( !is_string( $content ) ) { |
|
520 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
518 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
519 | + if (!is_string($content)) { |
|
520 | + throw new InvalidArgumentException('$content has to be string.'); |
|
521 | 521 | } |
522 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
523 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
522 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
523 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
524 | 524 | } |
525 | 525 | |
526 | - if ( empty( $expandableContent ) ) { |
|
526 | + if (empty($expandableContent)) { |
|
527 | 527 | return $content; |
528 | 528 | } |
529 | 529 | |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | $expandableContent |
544 | 544 | ); |
545 | 545 | |
546 | - return sprintf( '%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent ); |
|
546 | + return sprintf('%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -555,8 +555,8 @@ discard block |
||
555 | 555 | * |
556 | 556 | * @return string HTML |
557 | 557 | */ |
558 | - private function formatStatus( $status ) { |
|
559 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
558 | + private function formatStatus($status) { |
|
559 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
560 | 560 | $statusIcons = [ |
561 | 561 | CheckResult::STATUS_SUGGESTION => [ |
562 | 562 | 'icon' => 'suggestion-constraint-violation', |
@@ -573,25 +573,25 @@ discard block |
||
573 | 573 | ], |
574 | 574 | ]; |
575 | 575 | |
576 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
577 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
578 | - $iconHtml = $iconWidget->toString() . ' '; |
|
576 | + if (array_key_exists($status, $statusIcons)) { |
|
577 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
578 | + $iconHtml = $iconWidget->toString().' '; |
|
579 | 579 | } else { |
580 | 580 | $iconHtml = ''; |
581 | 581 | } |
582 | 582 | |
583 | - $labelWidget = new LabelWidget( [ |
|
584 | - 'label' => $this->msg( $messageName )->text(), |
|
585 | - ] ); |
|
583 | + $labelWidget = new LabelWidget([ |
|
584 | + 'label' => $this->msg($messageName)->text(), |
|
585 | + ]); |
|
586 | 586 | $labelHtml = $labelWidget->toString(); |
587 | 587 | |
588 | 588 | $formattedStatus = |
589 | 589 | Html::rawElement( |
590 | 590 | 'span', |
591 | 591 | [ |
592 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
592 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
593 | 593 | ], |
594 | - $iconHtml . $labelHtml |
|
594 | + $iconHtml.$labelHtml |
|
595 | 595 | ); |
596 | 596 | |
597 | 597 | return $formattedStatus; |
@@ -607,26 +607,26 @@ discard block |
||
607 | 607 | * |
608 | 608 | * @return string HTML |
609 | 609 | */ |
610 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
611 | - if ( $dataValues instanceof DataValue ) { |
|
612 | - $dataValues = [ $dataValues ]; |
|
613 | - } elseif ( !is_array( $dataValues ) ) { |
|
614 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
610 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
611 | + if ($dataValues instanceof DataValue) { |
|
612 | + $dataValues = [$dataValues]; |
|
613 | + } elseif (!is_array($dataValues)) { |
|
614 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | $formattedDataValues = []; |
618 | - foreach ( $dataValues as $dataValue ) { |
|
619 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
620 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
618 | + foreach ($dataValues as $dataValue) { |
|
619 | + if (!($dataValue instanceof DataValue)) { |
|
620 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
621 | 621 | } |
622 | - if ( $dataValue instanceof EntityIdValue ) { |
|
623 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
622 | + if ($dataValue instanceof EntityIdValue) { |
|
623 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
624 | 624 | } else { |
625 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
625 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
626 | 626 | } |
627 | 627 | } |
628 | 628 | |
629 | - return implode( $separator, $formattedDataValues ); |
|
629 | + return implode($separator, $formattedDataValues); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | /** |
@@ -638,11 +638,11 @@ discard block |
||
638 | 638 | * |
639 | 639 | * @return string HTML |
640 | 640 | */ |
641 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
641 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
642 | 642 | return Html::rawElement( |
643 | 643 | 'a', |
644 | 644 | [ |
645 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
645 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
646 | 646 | 'target' => '_blank' |
647 | 647 | ], |
648 | 648 | $text |
@@ -657,9 +657,9 @@ discard block |
||
657 | 657 | * |
658 | 658 | * @return string |
659 | 659 | */ |
660 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
661 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
662 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
660 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
661 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
662 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
663 | 663 | |
664 | 664 | return $entityUrl; |
665 | 665 | } |
@@ -36,193 +36,193 @@ |
||
36 | 36 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
37 | 37 | |
38 | 38 | return [ |
39 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function( MediaWikiServices $services ) { |
|
39 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function(MediaWikiServices $services) { |
|
40 | 40 | return new ConflictsWithChecker( |
41 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
42 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
41 | + ConstraintsServices::getConstraintParameterParser($services), |
|
42 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
43 | 43 | ); |
44 | 44 | }, |
45 | 45 | |
46 | - ConstraintCheckerServices::ITEM_CHECKER => function( MediaWikiServices $services ) { |
|
46 | + ConstraintCheckerServices::ITEM_CHECKER => function(MediaWikiServices $services) { |
|
47 | 47 | return new ItemChecker( |
48 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
49 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
48 | + ConstraintsServices::getConstraintParameterParser($services), |
|
49 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
50 | 50 | ); |
51 | 51 | }, |
52 | 52 | |
53 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function( MediaWikiServices $services ) { |
|
53 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function(MediaWikiServices $services) { |
|
54 | 54 | return new TargetRequiredClaimChecker( |
55 | - WikibaseServices::getEntityLookup( $services ), |
|
56 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
57 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
55 | + WikibaseServices::getEntityLookup($services), |
|
56 | + ConstraintsServices::getConstraintParameterParser($services), |
|
57 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
58 | 58 | ); |
59 | 59 | }, |
60 | 60 | |
61 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => function( MediaWikiServices $services ) { |
|
61 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => function(MediaWikiServices $services) { |
|
62 | 62 | return new SymmetricChecker( |
63 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
64 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
63 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
64 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
65 | 65 | ); |
66 | 66 | }, |
67 | 67 | |
68 | - ConstraintCheckerServices::INVERSE_CHECKER => function( MediaWikiServices $services ) { |
|
68 | + ConstraintCheckerServices::INVERSE_CHECKER => function(MediaWikiServices $services) { |
|
69 | 69 | return new InverseChecker( |
70 | - WikibaseServices::getEntityLookup( $services ), |
|
71 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
72 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
70 | + WikibaseServices::getEntityLookup($services), |
|
71 | + ConstraintsServices::getConstraintParameterParser($services), |
|
72 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
73 | 73 | ); |
74 | 74 | }, |
75 | 75 | |
76 | - ConstraintCheckerServices::QUALIFIER_CHECKER => function( MediaWikiServices $services ) { |
|
76 | + ConstraintCheckerServices::QUALIFIER_CHECKER => function(MediaWikiServices $services) { |
|
77 | 77 | return new QualifierChecker(); |
78 | 78 | }, |
79 | 79 | |
80 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => function( MediaWikiServices $services ) { |
|
80 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
81 | 81 | return new QualifiersChecker( |
82 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
82 | + ConstraintsServices::getConstraintParameterParser($services) |
|
83 | 83 | ); |
84 | 84 | }, |
85 | 85 | |
86 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function( MediaWikiServices $services ) { |
|
86 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
87 | 87 | return new MandatoryQualifiersChecker( |
88 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
88 | + ConstraintsServices::getConstraintParameterParser($services) |
|
89 | 89 | ); |
90 | 90 | }, |
91 | 91 | |
92 | - ConstraintCheckerServices::RANGE_CHECKER => function( MediaWikiServices $services ) { |
|
92 | + ConstraintCheckerServices::RANGE_CHECKER => function(MediaWikiServices $services) { |
|
93 | 93 | return new RangeChecker( |
94 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
95 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
96 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
94 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
95 | + ConstraintsServices::getConstraintParameterParser($services), |
|
96 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
97 | 97 | ); |
98 | 98 | }, |
99 | 99 | |
100 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function( MediaWikiServices $services ) { |
|
100 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function(MediaWikiServices $services) { |
|
101 | 101 | return new DiffWithinRangeChecker( |
102 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
103 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
102 | + ConstraintsServices::getConstraintParameterParser($services), |
|
103 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
104 | 104 | $services->getMainConfig() |
105 | 105 | ); |
106 | 106 | }, |
107 | 107 | |
108 | - ConstraintCheckerServices::TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
108 | + ConstraintCheckerServices::TYPE_CHECKER => function(MediaWikiServices $services) { |
|
109 | 109 | return new TypeChecker( |
110 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
111 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
110 | + ConstraintsServices::getConstraintParameterParser($services), |
|
111 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
112 | 112 | $services->getMainConfig() |
113 | 113 | ); |
114 | 114 | }, |
115 | 115 | |
116 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
116 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
117 | 117 | return new ValueTypeChecker( |
118 | - WikibaseServices::getEntityLookup( $services ), |
|
119 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
120 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
118 | + WikibaseServices::getEntityLookup($services), |
|
119 | + ConstraintsServices::getConstraintParameterParser($services), |
|
120 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
121 | 121 | $services->getMainConfig() |
122 | 122 | ); |
123 | 123 | }, |
124 | 124 | |
125 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
125 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
126 | 126 | return new SingleValueChecker( |
127 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
127 | + ConstraintsServices::getConstraintParameterParser($services) |
|
128 | 128 | ); |
129 | 129 | }, |
130 | 130 | |
131 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
131 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
132 | 132 | return new MultiValueChecker( |
133 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
133 | + ConstraintsServices::getConstraintParameterParser($services) |
|
134 | 134 | ); |
135 | 135 | }, |
136 | 136 | |
137 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
137 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
138 | 138 | // TODO return a different, dummy implementation if SPARQL is not available |
139 | 139 | return new UniqueValueChecker( |
140 | - ConstraintsServices::getSparqlHelper( $services ) |
|
140 | + ConstraintsServices::getSparqlHelper($services) |
|
141 | 141 | ); |
142 | 142 | }, |
143 | 143 | |
144 | - ConstraintCheckerServices::FORMAT_CHECKER => function( MediaWikiServices $services ) { |
|
144 | + ConstraintCheckerServices::FORMAT_CHECKER => function(MediaWikiServices $services) { |
|
145 | 145 | // TODO return a different, dummy implementation if SPARQL is not available |
146 | 146 | return new FormatChecker( |
147 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
147 | + ConstraintsServices::getConstraintParameterParser($services), |
|
148 | 148 | $services->getMainConfig(), |
149 | - ConstraintsServices::getSparqlHelper( $services ) |
|
149 | + ConstraintsServices::getSparqlHelper($services) |
|
150 | 150 | ); |
151 | 151 | }, |
152 | 152 | |
153 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => function( MediaWikiServices $services ) { |
|
153 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => function(MediaWikiServices $services) { |
|
154 | 154 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
155 | 155 | return new CommonsLinkChecker( |
156 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
156 | + ConstraintsServices::getConstraintParameterParser($services), |
|
157 | 157 | $pageNameNormalizer |
158 | 158 | ); |
159 | 159 | }, |
160 | 160 | |
161 | - ConstraintCheckerServices::ONE_OF_CHECKER => function( MediaWikiServices $services ) { |
|
161 | + ConstraintCheckerServices::ONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
162 | 162 | return new OneOfChecker( |
163 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
163 | + ConstraintsServices::getConstraintParameterParser($services) |
|
164 | 164 | ); |
165 | 165 | }, |
166 | 166 | |
167 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => function( MediaWikiServices $services ) { |
|
167 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => function(MediaWikiServices $services) { |
|
168 | 168 | return new ValueOnlyChecker(); |
169 | 169 | }, |
170 | 170 | |
171 | - ConstraintCheckerServices::REFERENCE_CHECKER => function( MediaWikiServices $services ) { |
|
171 | + ConstraintCheckerServices::REFERENCE_CHECKER => function(MediaWikiServices $services) { |
|
172 | 172 | return new ReferenceChecker(); |
173 | 173 | }, |
174 | 174 | |
175 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => function( MediaWikiServices $services ) { |
|
175 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => function(MediaWikiServices $services) { |
|
176 | 176 | return new NoBoundsChecker(); |
177 | 177 | }, |
178 | 178 | |
179 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function( MediaWikiServices $services ) { |
|
179 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function(MediaWikiServices $services) { |
|
180 | 180 | // TODO in the future, get UnitConverter from $services? |
181 | 181 | $repo = WikibaseRepo::getDefaultInstance(); |
182 | 182 | $unitConverter = $repo->getUnitConverter(); |
183 | 183 | |
184 | 184 | return new AllowedUnitsChecker( |
185 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
185 | + ConstraintsServices::getConstraintParameterParser($services), |
|
186 | 186 | $unitConverter |
187 | 187 | ); |
188 | 188 | }, |
189 | 189 | |
190 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
190 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
191 | 191 | return new SingleBestValueChecker( |
192 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
192 | + ConstraintsServices::getConstraintParameterParser($services) |
|
193 | 193 | ); |
194 | 194 | }, |
195 | 195 | |
196 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
196 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
197 | 197 | return new EntityTypeChecker( |
198 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
198 | + ConstraintsServices::getConstraintParameterParser($services) |
|
199 | 199 | ); |
200 | 200 | }, |
201 | 201 | |
202 | - ConstraintCheckerServices::NONE_OF_CHECKER => function( MediaWikiServices $services ) { |
|
202 | + ConstraintCheckerServices::NONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
203 | 203 | return new NoneOfChecker( |
204 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
204 | + ConstraintsServices::getConstraintParameterParser($services) |
|
205 | 205 | ); |
206 | 206 | }, |
207 | 207 | |
208 | - ConstraintCheckerServices::INTEGER_CHECKER => function( MediaWikiServices $services ) { |
|
208 | + ConstraintCheckerServices::INTEGER_CHECKER => function(MediaWikiServices $services) { |
|
209 | 209 | return new IntegerChecker(); |
210 | 210 | }, |
211 | 211 | |
212 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function( MediaWikiServices $services ) { |
|
212 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function(MediaWikiServices $services) { |
|
213 | 213 | return new CitationNeededChecker(); |
214 | 214 | }, |
215 | 215 | |
216 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function( MediaWikiServices $services ) { |
|
216 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function(MediaWikiServices $services) { |
|
217 | 217 | return new PropertyScopeChecker( |
218 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
218 | + ConstraintsServices::getConstraintParameterParser($services) |
|
219 | 219 | ); |
220 | 220 | }, |
221 | 221 | |
222 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => function( MediaWikiServices $services ) { |
|
222 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => function(MediaWikiServices $services) { |
|
223 | 223 | return new ContemporaryChecker( |
224 | - WikibaseServices::getEntityLookup( $services ), |
|
225 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
224 | + WikibaseServices::getEntityLookup($services), |
|
225 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
226 | 226 | $services->getMainConfig() |
227 | 227 | ); |
228 | 228 | }, |
@@ -20,35 +20,35 @@ |
||
20 | 20 | const PROPERTY_DATA_TYPE_LOOKUP = 'WBQC_PropertyDataTypeLookup'; |
21 | 21 | const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
22 | 22 | |
23 | - private static function getService( MediaWikiServices $services = null, $name ) { |
|
24 | - if ( $services === null ) { |
|
23 | + private static function getService(MediaWikiServices $services = null, $name) { |
|
24 | + if ($services === null) { |
|
25 | 25 | $services = MediaWikiServices::getInstance(); |
26 | 26 | } |
27 | - return $services->getService( $name ); |
|
27 | + return $services->getService($name); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param MediaWikiServices|null $services |
32 | 32 | * @return EntityLookup |
33 | 33 | */ |
34 | - public static function getEntityLookup( MediaWikiServices $services = null ) { |
|
35 | - return self::getService( $services, self::ENTITY_LOOKUP ); |
|
34 | + public static function getEntityLookup(MediaWikiServices $services = null) { |
|
35 | + return self::getService($services, self::ENTITY_LOOKUP); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @param MediaWikiServices|null $services |
40 | 40 | * @return PropertyDataTypeLookup |
41 | 41 | */ |
42 | - public static function getPropertyDataTypeLookup( MediaWikiServices $services = null ) { |
|
43 | - return self::getService( $services, self::PROPERTY_DATA_TYPE_LOOKUP ); |
|
42 | + public static function getPropertyDataTypeLookup(MediaWikiServices $services = null) { |
|
43 | + return self::getService($services, self::PROPERTY_DATA_TYPE_LOOKUP); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param MediaWikiServices|null $services |
48 | 48 | * @return EntityLookup |
49 | 49 | */ |
50 | - public static function getEntityLookupWithoutCache( MediaWikiServices $services = null ) { |
|
51 | - return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
|
50 | + public static function getEntityLookupWithoutCache(MediaWikiServices $services = null) { |
|
51 | + return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -8,19 +8,19 @@ |
||
8 | 8 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ExceptionIgnoringEntityLookup; |
9 | 9 | |
10 | 10 | return [ |
11 | - WikibaseServices::ENTITY_LOOKUP => function( MediaWikiServices $services ) { |
|
11 | + WikibaseServices::ENTITY_LOOKUP => function(MediaWikiServices $services) { |
|
12 | 12 | return new ExceptionIgnoringEntityLookup( |
13 | 13 | WikibaseRepo::getDefaultInstance()->getEntityLookup() |
14 | 14 | ); |
15 | 15 | }, |
16 | 16 | |
17 | - WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => function( MediaWikiServices $services ) { |
|
17 | + WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => function(MediaWikiServices $services) { |
|
18 | 18 | return new ExceptionIgnoringEntityLookup( |
19 | - WikibaseRepo::getDefaultInstance()->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY ) |
|
19 | + WikibaseRepo::getDefaultInstance()->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY) |
|
20 | 20 | ); |
21 | 21 | }, |
22 | 22 | |
23 | - WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => function( MediaWikiServices $services ) { |
|
23 | + WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => function(MediaWikiServices $services) { |
|
24 | 24 | return WikibaseRepo::getDefaultInstance()->getPropertyDataTypeLookup(); |
25 | 25 | }, |
26 | 26 | ]; |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | use Wikibase\Repo\WikibaseRepo; |
16 | 16 | |
17 | 17 | // @codeCoverageIgnoreStart |
18 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
19 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
18 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
19 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
20 | 20 | |
21 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
21 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
22 | 22 | // @codeCoverageIgnoreEnd |
23 | 23 | |
24 | 24 | /** |
@@ -52,20 +52,20 @@ discard block |
||
52 | 52 | parent::__construct(); |
53 | 53 | |
54 | 54 | $this->addDescription( |
55 | - 'Import entities needed for constraint checks ' . |
|
55 | + 'Import entities needed for constraint checks '. |
|
56 | 56 | 'from Wikidata into the local repository.' |
57 | 57 | ); |
58 | 58 | $this->addOption( |
59 | 59 | 'config-format', |
60 | - 'The format in which the resulting configuration will be omitted: ' . |
|
61 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
60 | + 'The format in which the resulting configuration will be omitted: '. |
|
61 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
62 | 62 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
63 | 63 | ); |
64 | 64 | $this->addOption( |
65 | 65 | 'dry-run', |
66 | 66 | 'Don’t actually import entities, just print which ones would be imported.' |
67 | 67 | ); |
68 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
68 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | $this->entitySerializer = $repo->getAllTypesEntitySerializer(); |
77 | 77 | $this->entityDeserializer = $repo->getInternalFormatEntityDeserializer(); |
78 | 78 | $this->entityStore = $repo->getEntityStore(); |
79 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
80 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
79 | + if (!$this->getOption('dry-run', false)) { |
|
80 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
@@ -86,20 +86,20 @@ discard block |
||
86 | 86 | |
87 | 87 | $configUpdates = []; |
88 | 88 | |
89 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
90 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
91 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
92 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
89 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
90 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
91 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
92 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
93 | 93 | |
94 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
95 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
94 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
95 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
96 | 96 | $configUpdates[$key] = [ |
97 | 97 | 'wikidata' => $wikidataEntityId, |
98 | 98 | 'local' => $localEntityId, |
99 | 99 | ]; |
100 | 100 | } |
101 | 101 | |
102 | - $this->outputConfigUpdates( $configUpdates ); |
|
102 | + $this->outputConfigUpdates($configUpdates); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,18 +107,18 @@ discard block |
||
107 | 107 | * @param Config $wikiConfig |
108 | 108 | * @return string[] |
109 | 109 | */ |
110 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
110 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
111 | 111 | $wikidataEntityIds = []; |
112 | 112 | |
113 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
114 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
113 | + foreach ($extensionJsonConfig as $key => $value) { |
|
114 | + if (!preg_match('/Id$/', $key)) { |
|
115 | 115 | continue; |
116 | 116 | } |
117 | 117 | |
118 | 118 | $wikidataEntityId = $value['value']; |
119 | - $localEntityId = $wikiConfig->get( $key ); |
|
119 | + $localEntityId = $wikiConfig->get($key); |
|
120 | 120 | |
121 | - if ( $localEntityId === $wikidataEntityId ) { |
|
121 | + if ($localEntityId === $wikidataEntityId) { |
|
122 | 122 | $wikidataEntityIds[$key] = $wikidataEntityId; |
123 | 123 | } |
124 | 124 | } |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | * @param string $wikidataEntityId |
131 | 131 | * @return string local entity ID |
132 | 132 | */ |
133 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
133 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
134 | 134 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
135 | - $wikidataEntitiesJson = file_get_contents( $wikidataEntityUrl ); |
|
136 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
135 | + $wikidataEntitiesJson = file_get_contents($wikidataEntityUrl); |
|
136 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -141,23 +141,23 @@ discard block |
||
141 | 141 | * @param string $wikidataEntitiesJson |
142 | 142 | * @return string local entity ID |
143 | 143 | */ |
144 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
145 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
146 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
144 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
145 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
146 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
147 | 147 | |
148 | - $wikidataEntity->setId( null ); |
|
148 | + $wikidataEntity->setId(null); |
|
149 | 149 | |
150 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
150 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
151 | 151 | $wikidataEntity->getStatements()->clear(); |
152 | 152 | } |
153 | 153 | |
154 | - if ( $wikidataEntity instanceof Item ) { |
|
155 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
154 | + if ($wikidataEntity instanceof Item) { |
|
155 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
156 | 156 | } |
157 | 157 | |
158 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
159 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
160 | - $this->output( $wikidataEntityJson . "\n" ); |
|
158 | + if ($this->getOption('dry-run', false)) { |
|
159 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
160 | + $this->output($wikidataEntityJson."\n"); |
|
161 | 161 | return "-$wikidataEntityId"; |
162 | 162 | } |
163 | 163 | |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | )->getEntity(); |
171 | 171 | |
172 | 172 | return $localEntity->getId()->getSerialization(); |
173 | - } catch ( StorageException $storageException ) { |
|
174 | - return $this->storageExceptionToEntityId( $storageException ); |
|
173 | + } catch (StorageException $storageException) { |
|
174 | + return $this->storageExceptionToEntityId($storageException); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
178 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
179 | 179 | $message = $storageException->getMessage(); |
180 | 180 | // example messages: |
181 | 181 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -185,42 +185,42 @@ discard block |
||
185 | 185 | // * Property [[Property:P694|P694]] already has label "instance of" |
186 | 186 | // associated with language code en. |
187 | 187 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
188 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
188 | + if (preg_match($pattern, $message, $matches)) { |
|
189 | 189 | return $matches[1]; |
190 | 190 | } else { |
191 | 191 | throw $storageException; |
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - private function outputConfigUpdates( array $configUpdates ) { |
|
196 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
197 | - switch ( $configFormat ) { |
|
195 | + private function outputConfigUpdates(array $configUpdates) { |
|
196 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
197 | + switch ($configFormat) { |
|
198 | 198 | case 'globals': |
199 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
199 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
200 | 200 | break; |
201 | 201 | case 'wgConf': |
202 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
202 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
203 | 203 | break; |
204 | 204 | default: |
205 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
206 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
205 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
206 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
207 | 207 | break; |
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
212 | - foreach ( $configUpdates as $key => $value ) { |
|
213 | - $localValueCode = var_export( $value['local'], true ); |
|
214 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
211 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
212 | + foreach ($configUpdates as $key => $value) { |
|
213 | + $localValueCode = var_export($value['local'], true); |
|
214 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
219 | - foreach ( $configUpdates as $key => $value ) { |
|
220 | - $keyCode = var_export( "wg$key", true ); |
|
221 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
222 | - $localValueCode = var_export( $value['local'], true ); |
|
223 | - $wikiIdCode = var_export( wfWikiID(), true ); |
|
218 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
219 | + foreach ($configUpdates as $key => $value) { |
|
220 | + $keyCode = var_export("wg$key", true); |
|
221 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
222 | + $localValueCode = var_export($value['local'], true); |
|
223 | + $wikiIdCode = var_export(wfWikiID(), true); |
|
224 | 224 | $block = <<< EOF |
225 | 225 | $keyCode => [ |
226 | 226 | 'default' => $wikidataValueCode, |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | |
230 | 230 | |
231 | 231 | EOF; |
232 | - $this->output( $block ); |
|
232 | + $this->output($block); |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 |
@@ -163,58 +163,58 @@ discard block |
||
163 | 163 | $this->defaultUserAgent = $defaultUserAgent; |
164 | 164 | $this->requestFactory = $requestFactory; |
165 | 165 | $this->entityPrefixes = []; |
166 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
167 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
166 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
167 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
168 | 168 | } |
169 | 169 | |
170 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
170 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
171 | 171 | } |
172 | 172 | |
173 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
173 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
174 | 174 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
175 | 175 | $prefixes = ''; |
176 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
176 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
177 | 177 | $prefixes .= <<<END |
178 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
178 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
179 | 179 | END; |
180 | 180 | } |
181 | 181 | $prefixes .= <<<END |
182 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
183 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
182 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
183 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
184 | 184 | END; |
185 | 185 | |
186 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
186 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
187 | 187 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
188 | 188 | $prefixes .= <<<END |
189 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
189 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
190 | 190 | END; |
191 | 191 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
192 | 192 | $prefixes .= <<<END |
193 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
193 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
194 | 194 | END; |
195 | 195 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
196 | 196 | $prefixes .= <<<END |
197 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
197 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
198 | 198 | END; |
199 | 199 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
200 | 200 | $prefixes .= <<<END |
201 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
201 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
202 | 202 | END; |
203 | 203 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
204 | 204 | $prefixes .= <<<END |
205 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
205 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
206 | 206 | END; |
207 | 207 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
208 | 208 | $prefixes .= <<<END |
209 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
209 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
210 | 210 | END; |
211 | 211 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
212 | 212 | $prefixes .= <<<END |
213 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
213 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
214 | 214 | END; |
215 | 215 | } |
216 | 216 | $prefixes .= <<<END |
217 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
217 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
218 | 218 | END; |
219 | 219 | return $prefixes; |
220 | 220 | } |
@@ -226,22 +226,21 @@ discard block |
||
226 | 226 | * @return CachedBool |
227 | 227 | * @throws SparqlHelperException if the query times out or some other error occurs |
228 | 228 | */ |
229 | - public function hasType( $id, array $classes ) { |
|
230 | - $subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
229 | + public function hasType($id, array $classes) { |
|
230 | + $subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
231 | 231 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
232 | - $gearingHint = $this->config->get( 'WBQualityConstraintsSparqlHasWikibaseSupport' ) ? |
|
233 | - ' hint:Prior hint:gearing "forward".' : |
|
234 | - ''; |
|
232 | + $gearingHint = $this->config->get('WBQualityConstraintsSparqlHasWikibaseSupport') ? |
|
233 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
235 | 234 | |
236 | 235 | $metadatas = []; |
237 | 236 | |
238 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
239 | - $classesValues = implode( ' ', array_map( |
|
240 | - function( $class ) { |
|
241 | - return 'wd:' . $class; |
|
237 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
238 | + $classesValues = implode(' ', array_map( |
|
239 | + function($class) { |
|
240 | + return 'wd:'.$class; |
|
242 | 241 | }, |
243 | 242 | $classesChunk |
244 | - ) ); |
|
243 | + )); |
|
245 | 244 | |
246 | 245 | $query = <<<EOF |
247 | 246 | ASK { |
@@ -251,19 +250,19 @@ discard block |
||
251 | 250 | } |
252 | 251 | EOF; |
253 | 252 | |
254 | - $result = $this->runQuery( $query ); |
|
253 | + $result = $this->runQuery($query); |
|
255 | 254 | $metadatas[] = $result->getMetadata(); |
256 | - if ( $result->getArray()['boolean'] ) { |
|
255 | + if ($result->getArray()['boolean']) { |
|
257 | 256 | return new CachedBool( |
258 | 257 | true, |
259 | - Metadata::merge( $metadatas ) |
|
258 | + Metadata::merge($metadatas) |
|
260 | 259 | ); |
261 | 260 | } |
262 | 261 | } |
263 | 262 | |
264 | 263 | return new CachedBool( |
265 | 264 | false, |
266 | - Metadata::merge( $metadatas ) |
|
265 | + Metadata::merge($metadatas) |
|
267 | 266 | ); |
268 | 267 | } |
269 | 268 | |
@@ -279,10 +278,10 @@ discard block |
||
279 | 278 | $ignoreDeprecatedStatements |
280 | 279 | ) { |
281 | 280 | $pid = $statement->getPropertyId()->serialize(); |
282 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
281 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
283 | 282 | |
284 | 283 | $deprecatedFilter = ''; |
285 | - if ( $ignoreDeprecatedStatements ) { |
|
284 | + if ($ignoreDeprecatedStatements) { |
|
286 | 285 | $deprecatedFilter = 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
287 | 286 | } |
288 | 287 | |
@@ -301,9 +300,9 @@ discard block |
||
301 | 300 | LIMIT 10 |
302 | 301 | EOF; |
303 | 302 | |
304 | - $result = $this->runQuery( $query ); |
|
303 | + $result = $this->runQuery($query); |
|
305 | 304 | |
306 | - return $this->getOtherEntities( $result ); |
|
305 | + return $this->getOtherEntities($result); |
|
307 | 306 | } |
308 | 307 | |
309 | 308 | /** |
@@ -328,16 +327,15 @@ discard block |
||
328 | 327 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
329 | 328 | $snak->getPropertyId() |
330 | 329 | ); |
331 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
332 | - if ( $isFullValue ) { |
|
330 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
331 | + if ($isFullValue) { |
|
333 | 332 | $prefix .= 'v'; |
334 | 333 | } |
335 | 334 | $path = $type === Context::TYPE_QUALIFIER ? |
336 | - "$prefix:$pid" : |
|
337 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
335 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
338 | 336 | |
339 | 337 | $deprecatedFilter = ''; |
340 | - if ( $ignoreDeprecatedStatements ) { |
|
338 | + if ($ignoreDeprecatedStatements) { |
|
341 | 339 | $deprecatedFilter = <<< EOF |
342 | 340 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
343 | 341 | EOF; |
@@ -357,9 +355,9 @@ discard block |
||
357 | 355 | LIMIT 10 |
358 | 356 | EOF; |
359 | 357 | |
360 | - $result = $this->runQuery( $query ); |
|
358 | + $result = $this->runQuery($query); |
|
361 | 359 | |
362 | - return $this->getOtherEntities( $result ); |
|
360 | + return $this->getOtherEntities($result); |
|
363 | 361 | } |
364 | 362 | |
365 | 363 | /** |
@@ -369,8 +367,8 @@ discard block |
||
369 | 367 | * |
370 | 368 | * @return string |
371 | 369 | */ |
372 | - private function stringLiteral( $text ) { |
|
373 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
370 | + private function stringLiteral($text) { |
|
371 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
374 | 372 | } |
375 | 373 | |
376 | 374 | /** |
@@ -380,18 +378,18 @@ discard block |
||
380 | 378 | * |
381 | 379 | * @return CachedEntityIds |
382 | 380 | */ |
383 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
384 | - return new CachedEntityIds( array_map( |
|
385 | - function ( $resultBindings ) { |
|
381 | + private function getOtherEntities(CachedQueryResults $results) { |
|
382 | + return new CachedEntityIds(array_map( |
|
383 | + function($resultBindings) { |
|
386 | 384 | $entityIRI = $resultBindings['otherEntity']['value']; |
387 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
388 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
389 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
385 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
386 | + $entityPrefixLength = strlen($entityPrefix); |
|
387 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
390 | 388 | try { |
391 | 389 | return $this->entityIdParser->parse( |
392 | - substr( $entityIRI, $entityPrefixLength ) |
|
390 | + substr($entityIRI, $entityPrefixLength) |
|
393 | 391 | ); |
394 | - } catch ( EntityIdParsingException $e ) { |
|
392 | + } catch (EntityIdParsingException $e) { |
|
395 | 393 | // fall through |
396 | 394 | } |
397 | 395 | } |
@@ -402,7 +400,7 @@ discard block |
||
402 | 400 | return null; |
403 | 401 | }, |
404 | 402 | $results->getArray()['results']['bindings'] |
405 | - ), $results->getMetadata() ); |
|
403 | + ), $results->getMetadata()); |
|
406 | 404 | } |
407 | 405 | |
408 | 406 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -415,47 +413,47 @@ discard block |
||
415 | 413 | * @return array the literal or IRI as a string in SPARQL syntax, |
416 | 414 | * and a boolean indicating whether it refers to a full value node or not |
417 | 415 | */ |
418 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
419 | - switch ( $dataType ) { |
|
416 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
417 | + switch ($dataType) { |
|
420 | 418 | case 'string': |
421 | 419 | case 'external-id': |
422 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
420 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
423 | 421 | case 'commonsMedia': |
424 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
425 | - return [ '<' . $url . '>', false ]; |
|
422 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
423 | + return ['<'.$url.'>', false]; |
|
426 | 424 | case 'geo-shape': |
427 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
428 | - return [ '<' . $url . '>', false ]; |
|
425 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
426 | + return ['<'.$url.'>', false]; |
|
429 | 427 | case 'tabular-data': |
430 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
431 | - return [ '<' . $url . '>', false ]; |
|
428 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
429 | + return ['<'.$url.'>', false]; |
|
432 | 430 | case 'url': |
433 | 431 | $url = $dataValue->getValue(); |
434 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
432 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
435 | 433 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
436 | 434 | // such an URL should never reach us, so just throw |
437 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
435 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
438 | 436 | } |
439 | - return [ '<' . $url . '>', false ]; |
|
437 | + return ['<'.$url.'>', false]; |
|
440 | 438 | case 'wikibase-item': |
441 | 439 | case 'wikibase-property': |
442 | 440 | /** @var EntityIdValue $dataValue */ |
443 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
441 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
444 | 442 | case 'monolingualtext': |
445 | 443 | /** @var MonolingualTextValue $dataValue */ |
446 | 444 | $lang = $dataValue->getLanguageCode(); |
447 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
445 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
448 | 446 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
449 | 447 | // such a language tag should never reach us, so just throw |
450 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
448 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
451 | 449 | } |
452 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
450 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
453 | 451 | case 'globe-coordinate': |
454 | 452 | case 'quantity': |
455 | 453 | case 'time': |
456 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
454 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
457 | 455 | default: |
458 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
456 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
459 | 457 | } |
460 | 458 | } |
461 | 459 | // @codingStandardsIgnoreEnd |
@@ -468,44 +466,44 @@ discard block |
||
468 | 466 | * @throws SparqlHelperException if the query times out or some other error occurs |
469 | 467 | * @throws ConstraintParameterException if the $regex is invalid |
470 | 468 | */ |
471 | - public function matchesRegularExpression( $text, $regex ) { |
|
469 | + public function matchesRegularExpression($text, $regex) { |
|
472 | 470 | // caching wrapper around matchesRegularExpressionWithSparql |
473 | 471 | |
474 | - $textHash = hash( 'sha256', $text ); |
|
472 | + $textHash = hash('sha256', $text); |
|
475 | 473 | $cacheKey = $this->cache->makeKey( |
476 | 474 | 'WikibaseQualityConstraints', // extension |
477 | 475 | 'regex', // action |
478 | 476 | 'WDQS-Java', // regex flavor |
479 | - hash( 'sha256', $regex ) |
|
477 | + hash('sha256', $regex) |
|
480 | 478 | ); |
481 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
479 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
482 | 480 | |
483 | 481 | $cacheMapArray = $this->cache->getWithSetCallback( |
484 | 482 | $cacheKey, |
485 | 483 | WANObjectCache::TTL_DAY, |
486 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
484 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
487 | 485 | // Initialize the cache map if not set |
488 | - if ( $cacheMapArray === false ) { |
|
486 | + if ($cacheMapArray === false) { |
|
489 | 487 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
490 | - $this->dataFactory->increment( $key ); |
|
488 | + $this->dataFactory->increment($key); |
|
491 | 489 | return []; |
492 | 490 | } |
493 | 491 | |
494 | 492 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
495 | - $this->dataFactory->increment( $key ); |
|
496 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
497 | - if ( $cacheMap->has( $textHash ) ) { |
|
493 | + $this->dataFactory->increment($key); |
|
494 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
495 | + if ($cacheMap->has($textHash)) { |
|
498 | 496 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
499 | - $this->dataFactory->increment( $key ); |
|
500 | - $cacheMap->get( $textHash ); // ping cache |
|
497 | + $this->dataFactory->increment($key); |
|
498 | + $cacheMap->get($textHash); // ping cache |
|
501 | 499 | } else { |
502 | 500 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
503 | - $this->dataFactory->increment( $key ); |
|
501 | + $this->dataFactory->increment($key); |
|
504 | 502 | try { |
505 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
506 | - } catch ( ConstraintParameterException $e ) { |
|
507 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
508 | - } catch ( SparqlHelperException $e ) { |
|
503 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
504 | + } catch (ConstraintParameterException $e) { |
|
505 | + $matches = $this->serializeConstraintParameterException($e); |
|
506 | + } catch (SparqlHelperException $e) { |
|
509 | 507 | // don’t cache this |
510 | 508 | return $cacheMap->toArray(); |
511 | 509 | } |
@@ -529,42 +527,42 @@ discard block |
||
529 | 527 | ] |
530 | 528 | ); |
531 | 529 | |
532 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
530 | + if (isset($cacheMapArray[$textHash])) { |
|
533 | 531 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
534 | - $this->dataFactory->increment( $key ); |
|
532 | + $this->dataFactory->increment($key); |
|
535 | 533 | $matches = $cacheMapArray[$textHash]; |
536 | - if ( is_bool( $matches ) ) { |
|
534 | + if (is_bool($matches)) { |
|
537 | 535 | return $matches; |
538 | - } elseif ( is_array( $matches ) && |
|
539 | - $matches['type'] == ConstraintParameterException::class ) { |
|
540 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
536 | + } elseif (is_array($matches) && |
|
537 | + $matches['type'] == ConstraintParameterException::class) { |
|
538 | + throw $this->deserializeConstraintParameterException($matches); |
|
541 | 539 | } else { |
542 | 540 | throw new MWException( |
543 | - 'Value of unknown type in object cache (' . |
|
544 | - 'cache key: ' . $cacheKey . ', ' . |
|
545 | - 'cache map key: ' . $textHash . ', ' . |
|
546 | - 'value type: ' . gettype( $matches ) . ')' |
|
541 | + 'Value of unknown type in object cache ('. |
|
542 | + 'cache key: '.$cacheKey.', '. |
|
543 | + 'cache map key: '.$textHash.', '. |
|
544 | + 'value type: '.gettype($matches).')' |
|
547 | 545 | ); |
548 | 546 | } |
549 | 547 | } else { |
550 | 548 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
551 | - $this->dataFactory->increment( $key ); |
|
552 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
549 | + $this->dataFactory->increment($key); |
|
550 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
553 | 551 | } |
554 | 552 | } |
555 | 553 | |
556 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
554 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
557 | 555 | return [ |
558 | 556 | 'type' => ConstraintParameterException::class, |
559 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
557 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
560 | 558 | ]; |
561 | 559 | } |
562 | 560 | |
563 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
561 | + private function deserializeConstraintParameterException(array $serialization) { |
|
564 | 562 | $message = $this->violationMessageDeserializer->deserialize( |
565 | 563 | $serialization['violationMessage'] |
566 | 564 | ); |
567 | - return new ConstraintParameterException( $message ); |
|
565 | + return new ConstraintParameterException($message); |
|
568 | 566 | } |
569 | 567 | |
570 | 568 | /** |
@@ -578,25 +576,25 @@ discard block |
||
578 | 576 | * @throws SparqlHelperException if the query times out or some other error occurs |
579 | 577 | * @throws ConstraintParameterException if the $regex is invalid |
580 | 578 | */ |
581 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
582 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
583 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
579 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
580 | + $textStringLiteral = $this->stringLiteral($text); |
|
581 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
584 | 582 | |
585 | 583 | $query = <<<EOF |
586 | 584 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
587 | 585 | EOF; |
588 | 586 | |
589 | - $result = $this->runQuery( $query, false ); |
|
587 | + $result = $this->runQuery($query, false); |
|
590 | 588 | |
591 | 589 | $vars = $result->getArray()['results']['bindings'][0]; |
592 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
590 | + if (array_key_exists('matches', $vars)) { |
|
593 | 591 | // true or false ⇒ regex okay, text matches or not |
594 | 592 | return $vars['matches']['value'] === 'true'; |
595 | 593 | } else { |
596 | 594 | // empty result: regex broken |
597 | 595 | throw new ConstraintParameterException( |
598 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
599 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
596 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
597 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
600 | 598 | ); |
601 | 599 | } |
602 | 600 | } |
@@ -608,14 +606,14 @@ discard block |
||
608 | 606 | * |
609 | 607 | * @return boolean |
610 | 608 | */ |
611 | - public function isTimeout( $responseContent ) { |
|
612 | - $timeoutRegex = implode( '|', array_map( |
|
613 | - function ( $fqn ) { |
|
614 | - return preg_quote( $fqn, '/' ); |
|
609 | + public function isTimeout($responseContent) { |
|
610 | + $timeoutRegex = implode('|', array_map( |
|
611 | + function($fqn) { |
|
612 | + return preg_quote($fqn, '/'); |
|
615 | 613 | }, |
616 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
617 | - ) ); |
|
618 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
614 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
615 | + )); |
|
616 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
619 | 617 | } |
620 | 618 | |
621 | 619 | /** |
@@ -627,17 +625,17 @@ discard block |
||
627 | 625 | * @return int|boolean the max-age (in seconds) |
628 | 626 | * or a plain boolean if no max-age can be determined |
629 | 627 | */ |
630 | - public function getCacheMaxAge( $responseHeaders ) { |
|
628 | + public function getCacheMaxAge($responseHeaders) { |
|
631 | 629 | if ( |
632 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
633 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
630 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
631 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
634 | 632 | ) { |
635 | 633 | $maxage = []; |
636 | 634 | if ( |
637 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
638 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
635 | + array_key_exists('cache-control', $responseHeaders) && |
|
636 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
639 | 637 | ) { |
640 | - return intval( $maxage[1] ); |
|
638 | + return intval($maxage[1]); |
|
641 | 639 | } else { |
642 | 640 | return true; |
643 | 641 | } |
@@ -658,34 +656,34 @@ discard block |
||
658 | 656 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
659 | 657 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
660 | 658 | */ |
661 | - public function getThrottling( MWHttpRequest $request ) { |
|
662 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
663 | - if ( $retryAfterValue === null ) { |
|
659 | + public function getThrottling(MWHttpRequest $request) { |
|
660 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
661 | + if ($retryAfterValue === null) { |
|
664 | 662 | return self::NO_RETRY_AFTER; |
665 | 663 | } |
666 | 664 | |
667 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
668 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
665 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
666 | + if (empty($trimmedRetryAfterValue)) { |
|
669 | 667 | return self::EMPTY_RETRY_AFTER; |
670 | 668 | } |
671 | 669 | |
672 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
673 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
674 | - if ( $delaySeconds >= 0 ) { |
|
675 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
670 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
671 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
672 | + if ($delaySeconds >= 0) { |
|
673 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
676 | 674 | } |
677 | 675 | } else { |
678 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
679 | - if ( !empty( $return ) ) { |
|
680 | - return new ConvertibleTimestamp( $return ); |
|
676 | + $return = strtotime($trimmedRetryAfterValue); |
|
677 | + if (!empty($return)) { |
|
678 | + return new ConvertibleTimestamp($return); |
|
681 | 679 | } |
682 | 680 | } |
683 | 681 | return self::INVALID_RETRY_AFTER; |
684 | 682 | } |
685 | 683 | |
686 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
684 | + private function getTimestampInFuture(DateInterval $delta) { |
|
687 | 685 | $now = new ConvertibleTimestamp(); |
688 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
686 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
689 | 687 | } |
690 | 688 | |
691 | 689 | /** |
@@ -699,97 +697,96 @@ discard block |
||
699 | 697 | * |
700 | 698 | * @throws SparqlHelperException if the query times out or some other error occurs |
701 | 699 | */ |
702 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
700 | + public function runQuery($query, $needsPrefixes = true) { |
|
703 | 701 | |
704 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
705 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
702 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
703 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
706 | 704 | throw new TooManySparqlRequestsException(); |
707 | 705 | } |
708 | 706 | |
709 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
710 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
711 | - $fallbackBlockDuration = (int)$this->config->get( 'WBQualityConstraintsSparqlThrottlingFallbackDuration' ); |
|
707 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
708 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
709 | + $fallbackBlockDuration = (int) $this->config->get('WBQualityConstraintsSparqlThrottlingFallbackDuration'); |
|
712 | 710 | |
713 | - if ( $fallbackBlockDuration < 0 ) { |
|
714 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: '. |
|
715 | - $fallbackBlockDuration ); |
|
711 | + if ($fallbackBlockDuration < 0) { |
|
712 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
713 | + $fallbackBlockDuration); |
|
716 | 714 | } |
717 | 715 | |
718 | - if ( $this->config->get( 'WBQualityConstraintsSparqlHasWikibaseSupport' ) ) { |
|
716 | + if ($this->config->get('WBQualityConstraintsSparqlHasWikibaseSupport')) { |
|
719 | 717 | $needsPrefixes = false; |
720 | 718 | } |
721 | 719 | |
722 | - if ( $needsPrefixes ) { |
|
723 | - $query = $this->prefixes . $query; |
|
720 | + if ($needsPrefixes) { |
|
721 | + $query = $this->prefixes.$query; |
|
724 | 722 | } |
725 | - $query = "#wbqc\n" . $query; |
|
723 | + $query = "#wbqc\n".$query; |
|
726 | 724 | |
727 | - $url = $endpoint . '?' . http_build_query( |
|
725 | + $url = $endpoint.'?'.http_build_query( |
|
728 | 726 | [ |
729 | 727 | 'query' => $query, |
730 | 728 | 'format' => 'json', |
731 | 729 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
732 | 730 | ], |
733 | - null, ini_get( 'arg_separator.output' ), |
|
731 | + null, ini_get('arg_separator.output'), |
|
734 | 732 | // encode spaces with %20, not + |
735 | 733 | PHP_QUERY_RFC3986 |
736 | 734 | ); |
737 | 735 | |
738 | 736 | $options = [ |
739 | 737 | 'method' => 'GET', |
740 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
738 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
741 | 739 | 'connectTimeout' => 'default', |
742 | 740 | 'userAgent' => $this->defaultUserAgent, |
743 | 741 | ]; |
744 | - $request = $this->requestFactory->create( $url, $options ); |
|
745 | - $startTime = microtime( true ); |
|
742 | + $request = $this->requestFactory->create($url, $options); |
|
743 | + $startTime = microtime(true); |
|
746 | 744 | $status = $request->execute(); |
747 | - $endTime = microtime( true ); |
|
745 | + $endTime = microtime(true); |
|
748 | 746 | $this->dataFactory->timing( |
749 | 747 | 'wikibase.quality.constraints.sparql.timing', |
750 | - ( $endTime - $startTime ) * 1000 |
|
748 | + ($endTime - $startTime) * 1000 |
|
751 | 749 | ); |
752 | 750 | |
753 | - if ( $request->getStatus() === self::HTTP_TOO_MANY_REQUESTS ) { |
|
754 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
755 | - $throttlingUntil = $this->getThrottling( $request ); |
|
756 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
757 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
751 | + if ($request->getStatus() === self::HTTP_TOO_MANY_REQUESTS) { |
|
752 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
753 | + $throttlingUntil = $this->getThrottling($request); |
|
754 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
755 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
758 | 756 | $this->throttlingLock->lock( |
759 | 757 | self::EXPIRY_LOCK_ID, |
760 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
758 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
761 | 759 | ); |
762 | 760 | } else { |
763 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
764 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
761 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
762 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
765 | 763 | } |
766 | 764 | throw new TooManySparqlRequestsException(); |
767 | 765 | } |
768 | 766 | |
769 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
770 | - if ( $maxAge ) { |
|
771 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
767 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
768 | + if ($maxAge) { |
|
769 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
772 | 770 | } |
773 | 771 | |
774 | - if ( $status->isOK() ) { |
|
772 | + if ($status->isOK()) { |
|
775 | 773 | $json = $request->getContent(); |
776 | - $arr = json_decode( $json, true ); |
|
774 | + $arr = json_decode($json, true); |
|
777 | 775 | return new CachedQueryResults( |
778 | 776 | $arr, |
779 | 777 | Metadata::ofCachingMetadata( |
780 | 778 | $maxAge ? |
781 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
782 | - CachingMetadata::fresh() |
|
779 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
783 | 780 | ) |
784 | 781 | ); |
785 | 782 | } else { |
786 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
783 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
787 | 784 | |
788 | 785 | $this->dataFactory->increment( |
789 | 786 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
790 | 787 | ); |
791 | 788 | |
792 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
789 | + if ($this->isTimeout($request->getContent())) { |
|
793 | 790 | $this->dataFactory->increment( |
794 | 791 | 'wikibase.quality.constraints.sparql.error.timeout' |
795 | 792 | ); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $this->config = $config; |
54 | 54 | $this->timeParser = new IsoTimestampParser(); |
55 | 55 | $this->timeCalculator = new TimeValueCalculator(); |
56 | - $this->timeValueComparer = new TimeValueComparer( $this->timeCalculator ); |
|
56 | + $this->timeValueComparer = new TimeValueComparer($this->timeCalculator); |
|
57 | 57 | $this->unitConverter = $unitConverter; |
58 | 58 | } |
59 | 59 | |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @param UnboundedQuantityValue $value |
62 | 62 | * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value. |
63 | 63 | */ |
64 | - private function standardize( UnboundedQuantityValue $value ) { |
|
65 | - if ( $this->unitConverter !== null ) { |
|
66 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
67 | - if ( $standard !== null ) { |
|
64 | + private function standardize(UnboundedQuantityValue $value) { |
|
65 | + if ($this->unitConverter !== null) { |
|
66 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
67 | + if ($standard !== null) { |
|
68 | 68 | return $standard; |
69 | 69 | } else { |
70 | 70 | return $value; |
@@ -86,29 +86,29 @@ discard block |
||
86 | 86 | * when $lhs is respectively less than, equal to, or greater than $rhs. |
87 | 87 | * (In other words, just like the “spaceship” operator <=>.) |
88 | 88 | */ |
89 | - public function getComparison( DataValue $lhs = null, DataValue $rhs = null ) { |
|
90 | - if ( $lhs === null || $rhs === null ) { |
|
89 | + public function getComparison(DataValue $lhs = null, DataValue $rhs = null) { |
|
90 | + if ($lhs === null || $rhs === null) { |
|
91 | 91 | return 0; |
92 | 92 | } |
93 | 93 | |
94 | - if ( $lhs->getType() !== $rhs->getType() ) { |
|
95 | - throw new InvalidArgumentException( 'Different data value types' ); |
|
94 | + if ($lhs->getType() !== $rhs->getType()) { |
|
95 | + throw new InvalidArgumentException('Different data value types'); |
|
96 | 96 | } |
97 | 97 | |
98 | - switch ( $lhs->getType() ) { |
|
98 | + switch ($lhs->getType()) { |
|
99 | 99 | case 'time': |
100 | 100 | /** @var TimeValue $lhs */ |
101 | 101 | /** @var TimeValue $rhs */ |
102 | - return $this->timeValueComparer->getComparison( $lhs, $rhs ); |
|
102 | + return $this->timeValueComparer->getComparison($lhs, $rhs); |
|
103 | 103 | case 'quantity': |
104 | 104 | /** @var QuantityValue|UnboundedQuantityValue $lhs */ |
105 | 105 | /** @var QuantityValue|UnboundedQuantityValue $rhs */ |
106 | - $lhsStandard = $this->standardize( $lhs ); |
|
107 | - $rhsStandard = $this->standardize( $rhs ); |
|
108 | - return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() ); |
|
106 | + $lhsStandard = $this->standardize($lhs); |
|
107 | + $rhsStandard = $this->standardize($rhs); |
|
108 | + return $lhsStandard->getAmount()->compare($rhsStandard->getAmount()); |
|
109 | 109 | } |
110 | 110 | |
111 | - throw new InvalidArgumentException( 'Unsupported data value type' ); |
|
111 | + throw new InvalidArgumentException('Unsupported data value type'); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -123,71 +123,71 @@ discard block |
||
123 | 123 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
124 | 124 | * @return UnboundedQuantityValue |
125 | 125 | */ |
126 | - public function getDifference( DataValue $minuend, DataValue $subtrahend ) { |
|
127 | - if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) { |
|
128 | - $minuendSeconds = $this->timeCalculator->getTimestamp( $minuend ); |
|
129 | - $subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend ); |
|
126 | + public function getDifference(DataValue $minuend, DataValue $subtrahend) { |
|
127 | + if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') { |
|
128 | + $minuendSeconds = $this->timeCalculator->getTimestamp($minuend); |
|
129 | + $subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend); |
|
130 | 130 | return UnboundedQuantityValue::newFromNumber( |
131 | 131 | $minuendSeconds - $subtrahendSeconds, |
132 | - $this->config->get( 'WBQualityConstraintsSecondUnit' ) |
|
132 | + $this->config->get('WBQualityConstraintsSecondUnit') |
|
133 | 133 | ); |
134 | 134 | } |
135 | - if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) { |
|
136 | - $minuendStandard = $this->standardize( $minuend ); |
|
137 | - $subtrahendStandard = $this->standardize( $subtrahend ); |
|
135 | + if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') { |
|
136 | + $minuendStandard = $this->standardize($minuend); |
|
137 | + $subtrahendStandard = $this->standardize($subtrahend); |
|
138 | 138 | $minuendValue = $minuendStandard->getAmount()->getValueFloat(); |
139 | 139 | $subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat(); |
140 | 140 | $diff = $minuendValue - $subtrahendValue; |
141 | 141 | // we don’t check whether both quantities have the same standard unit – |
142 | 142 | // that’s the job of a different constraint type, Units (T164372) |
143 | - return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() ); |
|
143 | + return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit()); |
|
144 | 144 | } |
145 | 145 | |
146 | - throw new InvalidArgumentException( 'Unsupported or different data value types' ); |
|
146 | + throw new InvalidArgumentException('Unsupported or different data value types'); |
|
147 | 147 | } |
148 | 148 | |
149 | - public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ) { |
|
150 | - if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) || |
|
151 | - !preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches ) |
|
149 | + public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend) { |
|
150 | + if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) || |
|
151 | + !preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches) |
|
152 | 152 | ) { |
153 | - throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' ); |
|
153 | + throw new InvalidArgumentException('TimeValue::getTime() did not match expected format'); |
|
154 | 154 | } |
155 | - $minuendYear = (float)$minuendMatches[1]; |
|
156 | - $subtrahendYear = (float)$subtrahendMatches[1]; |
|
155 | + $minuendYear = (float) $minuendMatches[1]; |
|
156 | + $subtrahendYear = (float) $subtrahendMatches[1]; |
|
157 | 157 | $minuendRest = $minuendMatches[2]; |
158 | 158 | $subtrahendRest = $subtrahendMatches[2]; |
159 | 159 | |
160 | 160 | // calculate difference of years |
161 | 161 | $diff = $minuendYear - $subtrahendYear; |
162 | - if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) { |
|
162 | + if ($minuendYear > 0.0 && $subtrahendYear < 0.0) { |
|
163 | 163 | $diff -= 1.0; // there is no year 0, remove it from difference |
164 | - } elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) { |
|
164 | + } elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) { |
|
165 | 165 | $diff -= -1.0; // there is no year 0, remove it from negative difference |
166 | 166 | } |
167 | 167 | |
168 | 168 | // adjust for date within year by parsing the month-day part within the same year |
169 | - $minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest ); |
|
170 | - $subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest ); |
|
171 | - $minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue ); |
|
172 | - $subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue ); |
|
173 | - if ( $minuendDateSeconds < $subtrahendDateSeconds ) { |
|
169 | + $minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest); |
|
170 | + $subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest); |
|
171 | + $minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue); |
|
172 | + $subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue); |
|
173 | + if ($minuendDateSeconds < $subtrahendDateSeconds) { |
|
174 | 174 | // difference in the last year is actually less than one full year |
175 | 175 | // e. g. 1975-03-01 - 1974-09-01 is just six months |
176 | 176 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
177 | 177 | $diff -= 0.5; |
178 | - } elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) { |
|
178 | + } elseif ($minuendDateSeconds > $subtrahendDateSeconds) { |
|
179 | 179 | // difference in the last year is actually more than one full year |
180 | 180 | // e. g. 1975-09-01 - 1974-03-01 is 18 months |
181 | 181 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
182 | 182 | $diff += 0.5; |
183 | 183 | } |
184 | 184 | |
185 | - $unit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
186 | - return UnboundedQuantityValue::newFromNumber( $diff, $unit ); |
|
185 | + $unit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
186 | + return UnboundedQuantityValue::newFromNumber($diff, $unit); |
|
187 | 187 | } |
188 | 188 | |
189 | - public function isFutureTime( TimeValue $timeValue ) { |
|
190 | - return $this->timeValueComparer->isFutureTime( $timeValue ); |
|
189 | + public function isFutureTime(TimeValue $timeValue) { |
|
190 | + return $this->timeValueComparer->isFutureTime($timeValue); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | } |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | ]; |
52 | 52 | } |
53 | 53 | |
54 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
55 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
56 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
54 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
55 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
56 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | 'item' => $entityTypes->getEntityTypes(), |
66 | 66 | ]; |
67 | 67 | |
68 | - if ( !in_array( $context->getEntity()->getType(), $entityTypes->getEntityTypes() ) ) { |
|
69 | - $message = ( new ViolationMessage( 'wbqc-violation-message-entityType' ) ) |
|
70 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
71 | - ->withEntityIdList( $entityTypes->getEntityTypeItemIds(), Role::CONSTRAINT_PARAMETER_VALUE ); |
|
68 | + if (!in_array($context->getEntity()->getType(), $entityTypes->getEntityTypes())) { |
|
69 | + $message = (new ViolationMessage('wbqc-violation-message-entityType')) |
|
70 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
71 | + ->withEntityIdList($entityTypes->getEntityTypeItemIds(), Role::CONSTRAINT_PARAMETER_VALUE); |
|
72 | 72 | |
73 | 73 | return new CheckResult( |
74 | 74 | $context, |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | ); |
80 | 80 | } |
81 | 81 | |
82 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
82 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
83 | 83 | } |
84 | 84 | |
85 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
85 | + public function checkConstraintParameters(Constraint $constraint) { |
|
86 | 86 | $constraintParameters = $constraint->getConstraintParameters(); |
87 | 87 | $exceptions = []; |
88 | 88 | try { |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $constraintParameters, |
91 | 91 | $constraint->getConstraintTypeItemId() |
92 | 92 | ); |
93 | - } catch ( ConstraintParameterException $e ) { |
|
93 | + } catch (ConstraintParameterException $e) { |
|
94 | 94 | $exceptions[] = $e; |
95 | 95 | } |
96 | 96 | return $exceptions; |