@@ -200,73 +200,73 @@ discard block |
||
200 | 200 | $this->defaultUserAgent = $defaultUserAgent; |
201 | 201 | $this->requestFactory = $requestFactory; |
202 | 202 | $this->entityPrefixes = []; |
203 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
204 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
203 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
204 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
205 | 205 | } |
206 | 206 | |
207 | - $this->endpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
208 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
209 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
210 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
211 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
207 | + $this->endpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
208 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
209 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
210 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
211 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
212 | 212 | $this->timeoutExceptionClasses = $config->get( |
213 | 213 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
214 | 214 | ); |
215 | 215 | $this->sparqlHasWikibaseSupport = $config->get( |
216 | 216 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
217 | 217 | ); |
218 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
218 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
219 | 219 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
220 | 220 | ); |
221 | 221 | |
222 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
222 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
223 | 223 | } |
224 | 224 | |
225 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
225 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
226 | 226 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
227 | 227 | $prefixes = ''; |
228 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
228 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
229 | 229 | $prefixes .= <<<END |
230 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
230 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
231 | 231 | END; |
232 | 232 | } |
233 | 233 | $prefixes .= <<<END |
234 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
235 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
234 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
235 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
236 | 236 | END; |
237 | 237 | |
238 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
238 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
239 | 239 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
240 | 240 | $prefixes .= <<<END |
241 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
241 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
242 | 242 | END; |
243 | 243 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
244 | 244 | $prefixes .= <<<END |
245 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
245 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
246 | 246 | END; |
247 | 247 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
248 | 248 | $prefixes .= <<<END |
249 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
249 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
250 | 250 | END; |
251 | 251 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
252 | 252 | $prefixes .= <<<END |
253 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
253 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
254 | 254 | END; |
255 | 255 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
256 | 256 | $prefixes .= <<<END |
257 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
257 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
258 | 258 | END; |
259 | 259 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
260 | 260 | $prefixes .= <<<END |
261 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
261 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
262 | 262 | END; |
263 | 263 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
264 | 264 | $prefixes .= <<<END |
265 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
265 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
266 | 266 | END; |
267 | 267 | } |
268 | 268 | $prefixes .= <<<END |
269 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
269 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
270 | 270 | END; |
271 | 271 | return $prefixes; |
272 | 272 | } |
@@ -278,21 +278,20 @@ discard block |
||
278 | 278 | * @return CachedBool |
279 | 279 | * @throws SparqlHelperException if the query times out or some other error occurs |
280 | 280 | */ |
281 | - public function hasType( $id, array $classes ) { |
|
281 | + public function hasType($id, array $classes) { |
|
282 | 282 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
283 | 283 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
284 | - ' hint:Prior hint:gearing "forward".' : |
|
285 | - ''; |
|
284 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
286 | 285 | |
287 | 286 | $metadatas = []; |
288 | 287 | |
289 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
290 | - $classesValues = implode( ' ', array_map( |
|
291 | - static function ( $class ) { |
|
292 | - return 'wd:' . $class; |
|
288 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
289 | + $classesValues = implode(' ', array_map( |
|
290 | + static function($class) { |
|
291 | + return 'wd:'.$class; |
|
293 | 292 | }, |
294 | 293 | $classesChunk |
295 | - ) ); |
|
294 | + )); |
|
296 | 295 | |
297 | 296 | $query = <<<EOF |
298 | 297 | ASK { |
@@ -302,19 +301,19 @@ discard block |
||
302 | 301 | } |
303 | 302 | EOF; |
304 | 303 | |
305 | - $result = $this->runQuery( $query ); |
|
304 | + $result = $this->runQuery($query); |
|
306 | 305 | $metadatas[] = $result->getMetadata(); |
307 | - if ( $result->getArray()['boolean'] ) { |
|
306 | + if ($result->getArray()['boolean']) { |
|
308 | 307 | return new CachedBool( |
309 | 308 | true, |
310 | - Metadata::merge( $metadatas ) |
|
309 | + Metadata::merge($metadatas) |
|
311 | 310 | ); |
312 | 311 | } |
313 | 312 | } |
314 | 313 | |
315 | 314 | return new CachedBool( |
316 | 315 | false, |
317 | - Metadata::merge( $metadatas ) |
|
316 | + Metadata::merge($metadatas) |
|
318 | 317 | ); |
319 | 318 | } |
320 | 319 | |
@@ -325,7 +324,7 @@ discard block |
||
325 | 324 | * @param PropertyId $separator |
326 | 325 | * @return string |
327 | 326 | */ |
328 | - private function nestedSeparatorFilter( PropertyId $separator ) { |
|
327 | + private function nestedSeparatorFilter(PropertyId $separator) { |
|
329 | 328 | $filter = <<<EOF |
330 | 329 | MINUS { |
331 | 330 | ?statement pq:$separator ?qualifier. |
@@ -369,15 +368,15 @@ discard block |
||
369 | 368 | array $separators |
370 | 369 | ) { |
371 | 370 | $pid = $statement->getPropertyId()->serialize(); |
372 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
371 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
373 | 372 | |
374 | 373 | $deprecatedFilter = ''; |
375 | - if ( $ignoreDeprecatedStatements ) { |
|
374 | + if ($ignoreDeprecatedStatements) { |
|
376 | 375 | $deprecatedFilter = 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
377 | 376 | } |
378 | 377 | |
379 | - $separatorFilters = array_map( [ $this, 'nestedSeparatorFilter' ], $separators ); |
|
380 | - $finalSeparatorFilter = implode( "\n", $separatorFilters ); |
|
378 | + $separatorFilters = array_map([$this, 'nestedSeparatorFilter'], $separators); |
|
379 | + $finalSeparatorFilter = implode("\n", $separatorFilters); |
|
381 | 380 | |
382 | 381 | $query = <<<EOF |
383 | 382 | SELECT DISTINCT ?otherEntity WHERE { |
@@ -395,9 +394,9 @@ discard block |
||
395 | 394 | LIMIT 10 |
396 | 395 | EOF; |
397 | 396 | |
398 | - $result = $this->runQuery( $query ); |
|
397 | + $result = $this->runQuery($query); |
|
399 | 398 | |
400 | - return $this->getOtherEntities( $result ); |
|
399 | + return $this->getOtherEntities($result); |
|
401 | 400 | } |
402 | 401 | |
403 | 402 | /** |
@@ -422,16 +421,15 @@ discard block |
||
422 | 421 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
423 | 422 | $snak->getPropertyId() |
424 | 423 | ); |
425 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
426 | - if ( $isFullValue ) { |
|
424 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
425 | + if ($isFullValue) { |
|
427 | 426 | $prefix .= 'v'; |
428 | 427 | } |
429 | 428 | $path = $type === Context::TYPE_QUALIFIER ? |
430 | - "$prefix:$pid" : |
|
431 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
429 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
432 | 430 | |
433 | 431 | $deprecatedFilter = ''; |
434 | - if ( $ignoreDeprecatedStatements ) { |
|
432 | + if ($ignoreDeprecatedStatements) { |
|
435 | 433 | $deprecatedFilter = <<< EOF |
436 | 434 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
437 | 435 | EOF; |
@@ -451,9 +449,9 @@ discard block |
||
451 | 449 | LIMIT 10 |
452 | 450 | EOF; |
453 | 451 | |
454 | - $result = $this->runQuery( $query ); |
|
452 | + $result = $this->runQuery($query); |
|
455 | 453 | |
456 | - return $this->getOtherEntities( $result ); |
|
454 | + return $this->getOtherEntities($result); |
|
457 | 455 | } |
458 | 456 | |
459 | 457 | /** |
@@ -463,8 +461,8 @@ discard block |
||
463 | 461 | * |
464 | 462 | * @return string |
465 | 463 | */ |
466 | - private function stringLiteral( $text ) { |
|
467 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
464 | + private function stringLiteral($text) { |
|
465 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
468 | 466 | } |
469 | 467 | |
470 | 468 | /** |
@@ -474,18 +472,18 @@ discard block |
||
474 | 472 | * |
475 | 473 | * @return CachedEntityIds |
476 | 474 | */ |
477 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
478 | - return new CachedEntityIds( array_map( |
|
479 | - function ( $resultBindings ) { |
|
475 | + private function getOtherEntities(CachedQueryResults $results) { |
|
476 | + return new CachedEntityIds(array_map( |
|
477 | + function($resultBindings) { |
|
480 | 478 | $entityIRI = $resultBindings['otherEntity']['value']; |
481 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
482 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
483 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
479 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
480 | + $entityPrefixLength = strlen($entityPrefix); |
|
481 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
484 | 482 | try { |
485 | 483 | return $this->entityIdParser->parse( |
486 | - substr( $entityIRI, $entityPrefixLength ) |
|
484 | + substr($entityIRI, $entityPrefixLength) |
|
487 | 485 | ); |
488 | - } catch ( EntityIdParsingException $e ) { |
|
486 | + } catch (EntityIdParsingException $e) { |
|
489 | 487 | // fall through |
490 | 488 | } |
491 | 489 | } |
@@ -496,7 +494,7 @@ discard block |
||
496 | 494 | return null; |
497 | 495 | }, |
498 | 496 | $results->getArray()['results']['bindings'] |
499 | - ), $results->getMetadata() ); |
|
497 | + ), $results->getMetadata()); |
|
500 | 498 | } |
501 | 499 | |
502 | 500 | // phpcs:disable Generic.Metrics.CyclomaticComplexity,Squiz.WhiteSpace.FunctionSpacing |
@@ -509,50 +507,50 @@ discard block |
||
509 | 507 | * @return array the literal or IRI as a string in SPARQL syntax, |
510 | 508 | * and a boolean indicating whether it refers to a full value node or not |
511 | 509 | */ |
512 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
513 | - switch ( $dataType ) { |
|
510 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
511 | + switch ($dataType) { |
|
514 | 512 | case 'string': |
515 | 513 | case 'external-id': |
516 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
514 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
517 | 515 | case 'commonsMedia': |
518 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
519 | - return [ '<' . $url . '>', false ]; |
|
516 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
517 | + return ['<'.$url.'>', false]; |
|
520 | 518 | case 'geo-shape': |
521 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
522 | - return [ '<' . $url . '>', false ]; |
|
519 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
520 | + return ['<'.$url.'>', false]; |
|
523 | 521 | case 'tabular-data': |
524 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
525 | - return [ '<' . $url . '>', false ]; |
|
522 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
523 | + return ['<'.$url.'>', false]; |
|
526 | 524 | case 'url': |
527 | 525 | $url = $dataValue->getValue(); |
528 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
526 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
529 | 527 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
530 | 528 | // such an URL should never reach us, so just throw |
531 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
529 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
532 | 530 | } |
533 | - return [ '<' . $url . '>', false ]; |
|
531 | + return ['<'.$url.'>', false]; |
|
534 | 532 | case 'wikibase-item': |
535 | 533 | case 'wikibase-property': |
536 | 534 | /** @var EntityIdValue $dataValue */ |
537 | 535 | '@phan-var EntityIdValue $dataValue'; |
538 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
536 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
539 | 537 | case 'monolingualtext': |
540 | 538 | /** @var MonolingualTextValue $dataValue */ |
541 | 539 | '@phan-var MonolingualTextValue $dataValue'; |
542 | 540 | $lang = $dataValue->getLanguageCode(); |
543 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
541 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
544 | 542 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
545 | 543 | // such a language tag should never reach us, so just throw |
546 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
544 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
547 | 545 | } |
548 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
546 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
549 | 547 | case 'globe-coordinate': |
550 | 548 | case 'quantity': |
551 | 549 | case 'time': |
552 | 550 | // @phan-suppress-next-line PhanUndeclaredMethod |
553 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
551 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
554 | 552 | default: |
555 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
553 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
556 | 554 | } |
557 | 555 | } |
558 | 556 | // phpcs:enable |
@@ -565,43 +563,43 @@ discard block |
||
565 | 563 | * @throws SparqlHelperException if the query times out or some other error occurs |
566 | 564 | * @throws ConstraintParameterException if the $regex is invalid |
567 | 565 | */ |
568 | - public function matchesRegularExpression( $text, $regex ) { |
|
566 | + public function matchesRegularExpression($text, $regex) { |
|
569 | 567 | // caching wrapper around matchesRegularExpressionWithSparql |
570 | 568 | |
571 | - $textHash = hash( 'sha256', $text ); |
|
569 | + $textHash = hash('sha256', $text); |
|
572 | 570 | $cacheKey = $this->cache->makeKey( |
573 | 571 | 'WikibaseQualityConstraints', // extension |
574 | 572 | 'regex', // action |
575 | 573 | 'WDQS-Java', // regex flavor |
576 | - hash( 'sha256', $regex ) |
|
574 | + hash('sha256', $regex) |
|
577 | 575 | ); |
578 | 576 | |
579 | 577 | $cacheMapArray = $this->cache->getWithSetCallback( |
580 | 578 | $cacheKey, |
581 | 579 | WANObjectCache::TTL_DAY, |
582 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
580 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
583 | 581 | // Initialize the cache map if not set |
584 | - if ( $cacheMapArray === false ) { |
|
582 | + if ($cacheMapArray === false) { |
|
585 | 583 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
586 | - $this->dataFactory->increment( $key ); |
|
584 | + $this->dataFactory->increment($key); |
|
587 | 585 | return []; |
588 | 586 | } |
589 | 587 | |
590 | 588 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
591 | - $this->dataFactory->increment( $key ); |
|
592 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
593 | - if ( $cacheMap->has( $textHash ) ) { |
|
589 | + $this->dataFactory->increment($key); |
|
590 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
591 | + if ($cacheMap->has($textHash)) { |
|
594 | 592 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
595 | - $this->dataFactory->increment( $key ); |
|
596 | - $cacheMap->get( $textHash ); // ping cache |
|
593 | + $this->dataFactory->increment($key); |
|
594 | + $cacheMap->get($textHash); // ping cache |
|
597 | 595 | } else { |
598 | 596 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
599 | - $this->dataFactory->increment( $key ); |
|
597 | + $this->dataFactory->increment($key); |
|
600 | 598 | try { |
601 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
602 | - } catch ( ConstraintParameterException $e ) { |
|
603 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
604 | - } catch ( SparqlHelperException $e ) { |
|
599 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
600 | + } catch (ConstraintParameterException $e) { |
|
601 | + $matches = $this->serializeConstraintParameterException($e); |
|
602 | + } catch (SparqlHelperException $e) { |
|
605 | 603 | // don’t cache this |
606 | 604 | return $cacheMap->toArray(); |
607 | 605 | } |
@@ -625,42 +623,42 @@ discard block |
||
625 | 623 | ] |
626 | 624 | ); |
627 | 625 | |
628 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
626 | + if (isset($cacheMapArray[$textHash])) { |
|
629 | 627 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
630 | - $this->dataFactory->increment( $key ); |
|
628 | + $this->dataFactory->increment($key); |
|
631 | 629 | $matches = $cacheMapArray[$textHash]; |
632 | - if ( is_bool( $matches ) ) { |
|
630 | + if (is_bool($matches)) { |
|
633 | 631 | return $matches; |
634 | - } elseif ( is_array( $matches ) && |
|
635 | - $matches['type'] == ConstraintParameterException::class ) { |
|
636 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
632 | + } elseif (is_array($matches) && |
|
633 | + $matches['type'] == ConstraintParameterException::class) { |
|
634 | + throw $this->deserializeConstraintParameterException($matches); |
|
637 | 635 | } else { |
638 | 636 | throw new MWException( |
639 | - 'Value of unknown type in object cache (' . |
|
640 | - 'cache key: ' . $cacheKey . ', ' . |
|
641 | - 'cache map key: ' . $textHash . ', ' . |
|
642 | - 'value type: ' . gettype( $matches ) . ')' |
|
637 | + 'Value of unknown type in object cache ('. |
|
638 | + 'cache key: '.$cacheKey.', '. |
|
639 | + 'cache map key: '.$textHash.', '. |
|
640 | + 'value type: '.gettype($matches).')' |
|
643 | 641 | ); |
644 | 642 | } |
645 | 643 | } else { |
646 | 644 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
647 | - $this->dataFactory->increment( $key ); |
|
648 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
645 | + $this->dataFactory->increment($key); |
|
646 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
649 | 647 | } |
650 | 648 | } |
651 | 649 | |
652 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
650 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
653 | 651 | return [ |
654 | 652 | 'type' => ConstraintParameterException::class, |
655 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
653 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
656 | 654 | ]; |
657 | 655 | } |
658 | 656 | |
659 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
657 | + private function deserializeConstraintParameterException(array $serialization) { |
|
660 | 658 | $message = $this->violationMessageDeserializer->deserialize( |
661 | 659 | $serialization['violationMessage'] |
662 | 660 | ); |
663 | - return new ConstraintParameterException( $message ); |
|
661 | + return new ConstraintParameterException($message); |
|
664 | 662 | } |
665 | 663 | |
666 | 664 | /** |
@@ -674,25 +672,25 @@ discard block |
||
674 | 672 | * @throws SparqlHelperException if the query times out or some other error occurs |
675 | 673 | * @throws ConstraintParameterException if the $regex is invalid |
676 | 674 | */ |
677 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
678 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
679 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
675 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
676 | + $textStringLiteral = $this->stringLiteral($text); |
|
677 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
680 | 678 | |
681 | 679 | $query = <<<EOF |
682 | 680 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
683 | 681 | EOF; |
684 | 682 | |
685 | - $result = $this->runQuery( $query, false ); |
|
683 | + $result = $this->runQuery($query, false); |
|
686 | 684 | |
687 | 685 | $vars = $result->getArray()['results']['bindings'][0]; |
688 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
686 | + if (array_key_exists('matches', $vars)) { |
|
689 | 687 | // true or false ⇒ regex okay, text matches or not |
690 | 688 | return $vars['matches']['value'] === 'true'; |
691 | 689 | } else { |
692 | 690 | // empty result: regex broken |
693 | 691 | throw new ConstraintParameterException( |
694 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
695 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
692 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
693 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
696 | 694 | ); |
697 | 695 | } |
698 | 696 | } |
@@ -704,14 +702,14 @@ discard block |
||
704 | 702 | * |
705 | 703 | * @return boolean |
706 | 704 | */ |
707 | - public function isTimeout( $responseContent ) { |
|
708 | - $timeoutRegex = implode( '|', array_map( |
|
709 | - static function ( $fqn ) { |
|
710 | - return preg_quote( $fqn, '/' ); |
|
705 | + public function isTimeout($responseContent) { |
|
706 | + $timeoutRegex = implode('|', array_map( |
|
707 | + static function($fqn) { |
|
708 | + return preg_quote($fqn, '/'); |
|
711 | 709 | }, |
712 | 710 | $this->timeoutExceptionClasses |
713 | - ) ); |
|
714 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
711 | + )); |
|
712 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
715 | 713 | } |
716 | 714 | |
717 | 715 | /** |
@@ -723,17 +721,17 @@ discard block |
||
723 | 721 | * @return int|boolean the max-age (in seconds) |
724 | 722 | * or a plain boolean if no max-age can be determined |
725 | 723 | */ |
726 | - public function getCacheMaxAge( $responseHeaders ) { |
|
724 | + public function getCacheMaxAge($responseHeaders) { |
|
727 | 725 | if ( |
728 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
729 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
726 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
727 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
730 | 728 | ) { |
731 | 729 | $maxage = []; |
732 | 730 | if ( |
733 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
734 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
731 | + array_key_exists('cache-control', $responseHeaders) && |
|
732 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
735 | 733 | ) { |
736 | - return intval( $maxage[1] ); |
|
734 | + return intval($maxage[1]); |
|
737 | 735 | } else { |
738 | 736 | return true; |
739 | 737 | } |
@@ -754,34 +752,34 @@ discard block |
||
754 | 752 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
755 | 753 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
756 | 754 | */ |
757 | - public function getThrottling( MWHttpRequest $request ) { |
|
758 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
759 | - if ( $retryAfterValue === null ) { |
|
755 | + public function getThrottling(MWHttpRequest $request) { |
|
756 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
757 | + if ($retryAfterValue === null) { |
|
760 | 758 | return self::NO_RETRY_AFTER; |
761 | 759 | } |
762 | 760 | |
763 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
764 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
761 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
762 | + if (empty($trimmedRetryAfterValue)) { |
|
765 | 763 | return self::EMPTY_RETRY_AFTER; |
766 | 764 | } |
767 | 765 | |
768 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
769 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
770 | - if ( $delaySeconds >= 0 ) { |
|
771 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
766 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
767 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
768 | + if ($delaySeconds >= 0) { |
|
769 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
772 | 770 | } |
773 | 771 | } else { |
774 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
775 | - if ( !empty( $return ) ) { |
|
776 | - return new ConvertibleTimestamp( $return ); |
|
772 | + $return = strtotime($trimmedRetryAfterValue); |
|
773 | + if (!empty($return)) { |
|
774 | + return new ConvertibleTimestamp($return); |
|
777 | 775 | } |
778 | 776 | } |
779 | 777 | return self::INVALID_RETRY_AFTER; |
780 | 778 | } |
781 | 779 | |
782 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
780 | + private function getTimestampInFuture(DateInterval $delta) { |
|
783 | 781 | $now = new ConvertibleTimestamp(); |
784 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
782 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
785 | 783 | } |
786 | 784 | |
787 | 785 | /** |
@@ -795,65 +793,64 @@ discard block |
||
795 | 793 | * |
796 | 794 | * @throws SparqlHelperException if the query times out or some other error occurs |
797 | 795 | */ |
798 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
796 | + public function runQuery($query, $needsPrefixes = true) { |
|
799 | 797 | |
800 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
801 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
798 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
799 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
802 | 800 | throw new TooManySparqlRequestsException(); |
803 | 801 | } |
804 | 802 | |
805 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
803 | + if ($this->sparqlHasWikibaseSupport) { |
|
806 | 804 | $needsPrefixes = false; |
807 | 805 | } |
808 | 806 | |
809 | - if ( $needsPrefixes ) { |
|
810 | - $query = $this->prefixes . $query; |
|
807 | + if ($needsPrefixes) { |
|
808 | + $query = $this->prefixes.$query; |
|
811 | 809 | } |
812 | - $query = "#wbqc\n" . $query; |
|
810 | + $query = "#wbqc\n".$query; |
|
813 | 811 | |
814 | - $url = $this->endpoint . '?' . http_build_query( |
|
812 | + $url = $this->endpoint.'?'.http_build_query( |
|
815 | 813 | [ |
816 | 814 | 'query' => $query, |
817 | 815 | 'format' => 'json', |
818 | 816 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
819 | 817 | ], |
820 | - null, ini_get( 'arg_separator.output' ), |
|
818 | + null, ini_get('arg_separator.output'), |
|
821 | 819 | // encode spaces with %20, not + |
822 | 820 | PHP_QUERY_RFC3986 |
823 | 821 | ); |
824 | 822 | |
825 | 823 | $options = [ |
826 | 824 | 'method' => 'GET', |
827 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
825 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
828 | 826 | 'connectTimeout' => 'default', |
829 | 827 | 'userAgent' => $this->defaultUserAgent, |
830 | 828 | ]; |
831 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
832 | - $startTime = microtime( true ); |
|
829 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
830 | + $startTime = microtime(true); |
|
833 | 831 | $requestStatus = $request->execute(); |
834 | - $endTime = microtime( true ); |
|
832 | + $endTime = microtime(true); |
|
835 | 833 | $this->dataFactory->timing( |
836 | 834 | 'wikibase.quality.constraints.sparql.timing', |
837 | - ( $endTime - $startTime ) * 1000 |
|
835 | + ($endTime - $startTime) * 1000 |
|
838 | 836 | ); |
839 | 837 | |
840 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
838 | + $this->guardAgainstTooManyRequestsError($request); |
|
841 | 839 | |
842 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
843 | - if ( $maxAge ) { |
|
844 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
840 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
841 | + if ($maxAge) { |
|
842 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
845 | 843 | } |
846 | 844 | |
847 | - if ( $requestStatus->isOK() ) { |
|
845 | + if ($requestStatus->isOK()) { |
|
848 | 846 | $json = $request->getContent(); |
849 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
850 | - if ( $jsonStatus->isOK() ) { |
|
847 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
848 | + if ($jsonStatus->isOK()) { |
|
851 | 849 | return new CachedQueryResults( |
852 | 850 | $jsonStatus->getValue(), |
853 | 851 | Metadata::ofCachingMetadata( |
854 | 852 | $maxAge ? |
855 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
856 | - CachingMetadata::fresh() |
|
853 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
857 | 854 | ) |
858 | 855 | ); |
859 | 856 | } else { |
@@ -870,9 +867,9 @@ discard block |
||
870 | 867 | // fall through to general error handling |
871 | 868 | } |
872 | 869 | |
873 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
870 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
874 | 871 | |
875 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
872 | + if ($this->isTimeout($request->getContent())) { |
|
876 | 873 | $this->dataFactory->increment( |
877 | 874 | 'wikibase.quality.constraints.sparql.error.timeout' |
878 | 875 | ); |
@@ -887,29 +884,29 @@ discard block |
||
887 | 884 | * @param MWHttpRequest $request |
888 | 885 | * @throws TooManySparqlRequestsException |
889 | 886 | */ |
890 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
891 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
887 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
888 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
892 | 889 | return; |
893 | 890 | } |
894 | 891 | |
895 | 892 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
896 | 893 | |
897 | - if ( $fallbackBlockDuration < 0 ) { |
|
898 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
899 | - $fallbackBlockDuration ); |
|
894 | + if ($fallbackBlockDuration < 0) { |
|
895 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
896 | + $fallbackBlockDuration); |
|
900 | 897 | } |
901 | 898 | |
902 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
903 | - $throttlingUntil = $this->getThrottling( $request ); |
|
904 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
905 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
899 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
900 | + $throttlingUntil = $this->getThrottling($request); |
|
901 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
902 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
906 | 903 | $this->throttlingLock->lock( |
907 | 904 | self::EXPIRY_LOCK_ID, |
908 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
905 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
909 | 906 | ); |
910 | 907 | } else { |
911 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
912 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
908 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
909 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
913 | 910 | } |
914 | 911 | throw new TooManySparqlRequestsException(); |
915 | 912 | } |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | // no parent::__construct() call |
24 | 24 | } |
25 | 25 | |
26 | - public function hasType( $id, array $classes ) { |
|
27 | - throw new LogicException( 'methods of this class should never be called' ); |
|
26 | + public function hasType($id, array $classes) { |
|
27 | + throw new LogicException('methods of this class should never be called'); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function findEntitiesWithSameStatement( |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | $ignoreDeprecatedStatements, |
33 | 33 | array $separators |
34 | 34 | ) { |
35 | - throw new LogicException( 'methods of this class should never be called' ); |
|
35 | + throw new LogicException('methods of this class should never be called'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function findEntitiesWithSameQualifierOrReference( |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | $type, |
42 | 42 | $ignoreDeprecatedStatements |
43 | 43 | ) { |
44 | - throw new LogicException( 'methods of this class should never be called' ); |
|
44 | + throw new LogicException('methods of this class should never be called'); |
|
45 | 45 | } |
46 | 46 | |
47 | - public function matchesRegularExpression( $text, $regex ) { |
|
48 | - throw new LogicException( 'methods of this class should never be called' ); |
|
47 | + public function matchesRegularExpression($text, $regex) { |
|
48 | + throw new LogicException('methods of this class should never be called'); |
|
49 | 49 | } |
50 | 50 | |
51 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
52 | - throw new LogicException( 'methods of this class should never be called' ); |
|
51 | + public function runQuery($query, $needsPrefixes = true) { |
|
52 | + throw new LogicException('methods of this class should never be called'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | } |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
77 | 77 | * @return CheckResult |
78 | 78 | */ |
79 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
80 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
81 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
79 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
80 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
81 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
82 | 82 | } |
83 | 83 | $parameters = []; |
84 | 84 | |
85 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
85 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
86 | 86 | |
87 | 87 | $separators = $this->constraintParameterParser->parseSeparatorsParameter( |
88 | 88 | $constraint->getConstraintParameters() |
89 | 89 | ); |
90 | 90 | $parameters['separator'] = $separators; |
91 | 91 | |
92 | - if ( $context->getType() === 'statement' ) { |
|
92 | + if ($context->getType() === 'statement') { |
|
93 | 93 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
94 | 94 | $context->getSnakStatement(), |
95 | 95 | true, // ignore deprecated statements |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | ); |
98 | 98 | } else { |
99 | 99 | $snak = $context->getSnak(); |
100 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
100 | + if (!$snak instanceof PropertyValueSnak) { |
|
101 | 101 | // nothing to check |
102 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
102 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
103 | 103 | } |
104 | 104 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
105 | 105 | $context->getEntity()->getId(), |
@@ -112,32 +112,32 @@ discard block |
||
112 | 112 | $otherEntities = $result->getArray(); |
113 | 113 | $metadata = $result->getMetadata(); |
114 | 114 | |
115 | - if ( $otherEntities === [] ) { |
|
115 | + if ($otherEntities === []) { |
|
116 | 116 | $status = CheckResult::STATUS_COMPLIANCE; |
117 | 117 | $message = null; |
118 | 118 | } else { |
119 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
119 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
120 | 120 | $status = CheckResult::STATUS_VIOLATION; |
121 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
122 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
121 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
122 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
123 | 123 | } |
124 | 124 | } else { |
125 | 125 | $status = CheckResult::STATUS_TODO; |
126 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
127 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
126 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
127 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
128 | 128 | $metadata = Metadata::blank(); |
129 | 129 | } |
130 | 130 | |
131 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
132 | - ->withMetadata( $metadata ); |
|
131 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
132 | + ->withMetadata($metadata); |
|
133 | 133 | } |
134 | 134 | |
135 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
135 | + public function checkConstraintParameters(Constraint $constraint) { |
|
136 | 136 | $constraintParameters = $constraint->getConstraintParameters(); |
137 | 137 | $exceptions = []; |
138 | 138 | try { |
139 | - $this->constraintParameterParser->parseSeparatorsParameter( $constraintParameters ); |
|
140 | - } catch ( ConstraintParameterException $e ) { |
|
139 | + $this->constraintParameterParser->parseSeparatorsParameter($constraintParameters); |
|
140 | + } catch (ConstraintParameterException $e) { |
|
141 | 141 | $exceptions[] = $e; |
142 | 142 | } |
143 | 143 | return $exceptions; |
@@ -38,206 +38,206 @@ |
||
38 | 38 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
39 | 39 | |
40 | 40 | return [ |
41 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function ( MediaWikiServices $services ) { |
|
41 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function(MediaWikiServices $services) { |
|
42 | 42 | return new ConflictsWithChecker( |
43 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
44 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
43 | + ConstraintsServices::getConstraintParameterParser($services), |
|
44 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
45 | 45 | ); |
46 | 46 | }, |
47 | 47 | |
48 | - ConstraintCheckerServices::ITEM_CHECKER => static function ( MediaWikiServices $services ) { |
|
48 | + ConstraintCheckerServices::ITEM_CHECKER => static function(MediaWikiServices $services) { |
|
49 | 49 | return new ItemChecker( |
50 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
51 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
50 | + ConstraintsServices::getConstraintParameterParser($services), |
|
51 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
52 | 52 | ); |
53 | 53 | }, |
54 | 54 | |
55 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function ( MediaWikiServices $services ) { |
|
55 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function(MediaWikiServices $services) { |
|
56 | 56 | return new TargetRequiredClaimChecker( |
57 | - WikibaseServices::getEntityLookup( $services ), |
|
58 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
59 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
57 | + WikibaseServices::getEntityLookup($services), |
|
58 | + ConstraintsServices::getConstraintParameterParser($services), |
|
59 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
60 | 60 | ); |
61 | 61 | }, |
62 | 62 | |
63 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => static function ( MediaWikiServices $services ) { |
|
63 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => static function(MediaWikiServices $services) { |
|
64 | 64 | return new SymmetricChecker( |
65 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
66 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
65 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
66 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
67 | 67 | ); |
68 | 68 | }, |
69 | 69 | |
70 | - ConstraintCheckerServices::INVERSE_CHECKER => static function ( MediaWikiServices $services ) { |
|
70 | + ConstraintCheckerServices::INVERSE_CHECKER => static function(MediaWikiServices $services) { |
|
71 | 71 | return new InverseChecker( |
72 | - WikibaseServices::getEntityLookup( $services ), |
|
73 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
74 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
72 | + WikibaseServices::getEntityLookup($services), |
|
73 | + ConstraintsServices::getConstraintParameterParser($services), |
|
74 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
75 | 75 | ); |
76 | 76 | }, |
77 | 77 | |
78 | - ConstraintCheckerServices::QUALIFIER_CHECKER => static function ( MediaWikiServices $services ) { |
|
78 | + ConstraintCheckerServices::QUALIFIER_CHECKER => static function(MediaWikiServices $services) { |
|
79 | 79 | return new QualifierChecker(); |
80 | 80 | }, |
81 | 81 | |
82 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
82 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
83 | 83 | return new QualifiersChecker( |
84 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
84 | + ConstraintsServices::getConstraintParameterParser($services) |
|
85 | 85 | ); |
86 | 86 | }, |
87 | 87 | |
88 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
88 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
89 | 89 | return new MandatoryQualifiersChecker( |
90 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
90 | + ConstraintsServices::getConstraintParameterParser($services) |
|
91 | 91 | ); |
92 | 92 | }, |
93 | 93 | |
94 | - ConstraintCheckerServices::RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
94 | + ConstraintCheckerServices::RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
95 | 95 | return new RangeChecker( |
96 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
97 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
98 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
96 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
97 | + ConstraintsServices::getConstraintParameterParser($services), |
|
98 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
99 | 99 | ); |
100 | 100 | }, |
101 | 101 | |
102 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
102 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
103 | 103 | return new DiffWithinRangeChecker( |
104 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
105 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
104 | + ConstraintsServices::getConstraintParameterParser($services), |
|
105 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
106 | 106 | $services->getMainConfig() |
107 | 107 | ); |
108 | 108 | }, |
109 | 109 | |
110 | - ConstraintCheckerServices::TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
110 | + ConstraintCheckerServices::TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
111 | 111 | return new TypeChecker( |
112 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
113 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
112 | + ConstraintsServices::getConstraintParameterParser($services), |
|
113 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
114 | 114 | $services->getMainConfig() |
115 | 115 | ); |
116 | 116 | }, |
117 | 117 | |
118 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
118 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
119 | 119 | return new ValueTypeChecker( |
120 | - WikibaseServices::getEntityLookup( $services ), |
|
121 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
122 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
120 | + WikibaseServices::getEntityLookup($services), |
|
121 | + ConstraintsServices::getConstraintParameterParser($services), |
|
122 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
123 | 123 | $services->getMainConfig() |
124 | 124 | ); |
125 | 125 | }, |
126 | 126 | |
127 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
127 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
128 | 128 | return new SingleValueChecker( |
129 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
129 | + ConstraintsServices::getConstraintParameterParser($services) |
|
130 | 130 | ); |
131 | 131 | }, |
132 | 132 | |
133 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
133 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
134 | 134 | return new MultiValueChecker( |
135 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
135 | + ConstraintsServices::getConstraintParameterParser($services) |
|
136 | 136 | ); |
137 | 137 | }, |
138 | 138 | |
139 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
139 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
140 | 140 | // TODO return a different, dummy implementation if SPARQL is not available |
141 | 141 | return new UniqueValueChecker( |
142 | - ConstraintsServices::getSparqlHelper( $services ), |
|
143 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
142 | + ConstraintsServices::getSparqlHelper($services), |
|
143 | + ConstraintsServices::getConstraintParameterParser($services) |
|
144 | 144 | ); |
145 | 145 | }, |
146 | 146 | |
147 | - ConstraintCheckerServices::FORMAT_CHECKER => static function ( MediaWikiServices $services ) { |
|
147 | + ConstraintCheckerServices::FORMAT_CHECKER => static function(MediaWikiServices $services) { |
|
148 | 148 | // TODO return a different, dummy implementation if SPARQL is not available |
149 | 149 | return new FormatChecker( |
150 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
150 | + ConstraintsServices::getConstraintParameterParser($services), |
|
151 | 151 | $services->getMainConfig(), |
152 | - ConstraintsServices::getSparqlHelper( $services ), |
|
152 | + ConstraintsServices::getSparqlHelper($services), |
|
153 | 153 | $services->getShellboxClientFactory() |
154 | 154 | ); |
155 | 155 | }, |
156 | 156 | |
157 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function ( MediaWikiServices $services ) { |
|
157 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function(MediaWikiServices $services) { |
|
158 | 158 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
159 | 159 | return new CommonsLinkChecker( |
160 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
160 | + ConstraintsServices::getConstraintParameterParser($services), |
|
161 | 161 | $pageNameNormalizer, |
162 | - WikibaseRepo::getPropertyDataTypeLookup( $services ) |
|
162 | + WikibaseRepo::getPropertyDataTypeLookup($services) |
|
163 | 163 | ); |
164 | 164 | }, |
165 | 165 | |
166 | - ConstraintCheckerServices::ONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
166 | + ConstraintCheckerServices::ONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
167 | 167 | return new OneOfChecker( |
168 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
168 | + ConstraintsServices::getConstraintParameterParser($services) |
|
169 | 169 | ); |
170 | 170 | }, |
171 | 171 | |
172 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function ( MediaWikiServices $services ) { |
|
172 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function(MediaWikiServices $services) { |
|
173 | 173 | return new ValueOnlyChecker(); |
174 | 174 | }, |
175 | 175 | |
176 | - ConstraintCheckerServices::REFERENCE_CHECKER => static function ( MediaWikiServices $services ) { |
|
176 | + ConstraintCheckerServices::REFERENCE_CHECKER => static function(MediaWikiServices $services) { |
|
177 | 177 | return new ReferenceChecker(); |
178 | 178 | }, |
179 | 179 | |
180 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function ( MediaWikiServices $services ) { |
|
180 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function(MediaWikiServices $services) { |
|
181 | 181 | return new NoBoundsChecker(); |
182 | 182 | }, |
183 | 183 | |
184 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function ( MediaWikiServices $services ) { |
|
184 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function(MediaWikiServices $services) { |
|
185 | 185 | return new AllowedUnitsChecker( |
186 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
187 | - WikibaseRepo::getUnitConverter( $services ) |
|
186 | + ConstraintsServices::getConstraintParameterParser($services), |
|
187 | + WikibaseRepo::getUnitConverter($services) |
|
188 | 188 | ); |
189 | 189 | }, |
190 | 190 | |
191 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
191 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
192 | 192 | return new SingleBestValueChecker( |
193 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
193 | + ConstraintsServices::getConstraintParameterParser($services) |
|
194 | 194 | ); |
195 | 195 | }, |
196 | 196 | |
197 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
197 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
198 | 198 | return new EntityTypeChecker( |
199 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
199 | + ConstraintsServices::getConstraintParameterParser($services) |
|
200 | 200 | ); |
201 | 201 | }, |
202 | 202 | |
203 | - ConstraintCheckerServices::NONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
203 | + ConstraintCheckerServices::NONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
204 | 204 | return new NoneOfChecker( |
205 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
205 | + ConstraintsServices::getConstraintParameterParser($services) |
|
206 | 206 | ); |
207 | 207 | }, |
208 | 208 | |
209 | - ConstraintCheckerServices::INTEGER_CHECKER => static function ( MediaWikiServices $services ) { |
|
209 | + ConstraintCheckerServices::INTEGER_CHECKER => static function(MediaWikiServices $services) { |
|
210 | 210 | return new IntegerChecker(); |
211 | 211 | }, |
212 | 212 | |
213 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function ( MediaWikiServices $services ) { |
|
213 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function(MediaWikiServices $services) { |
|
214 | 214 | return new CitationNeededChecker(); |
215 | 215 | }, |
216 | 216 | |
217 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
217 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function(MediaWikiServices $services) { |
|
218 | 218 | return new PropertyScopeChecker( |
219 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
219 | + ConstraintsServices::getConstraintParameterParser($services) |
|
220 | 220 | ); |
221 | 221 | }, |
222 | 222 | |
223 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function ( MediaWikiServices $services ) { |
|
223 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function(MediaWikiServices $services) { |
|
224 | 224 | return new ContemporaryChecker( |
225 | - WikibaseServices::getEntityLookup( $services ), |
|
226 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
225 | + WikibaseServices::getEntityLookup($services), |
|
226 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
227 | 227 | $services->getMainConfig() |
228 | 228 | ); |
229 | 229 | }, |
230 | 230 | |
231 | - ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
231 | + ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function(MediaWikiServices $services) { |
|
232 | 232 | return new LanguageChecker( |
233 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
234 | - WikibaseServices::getEntityLookup( $services ) |
|
233 | + ConstraintsServices::getConstraintParameterParser($services), |
|
234 | + WikibaseServices::getEntityLookup($services) |
|
235 | 235 | ); |
236 | 236 | }, |
237 | 237 | |
238 | - ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
238 | + ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function(MediaWikiServices $services) { |
|
239 | 239 | return new LabelInLanguageChecker( |
240 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
240 | + ConstraintsServices::getConstraintParameterParser($services) |
|
241 | 241 | ); |
242 | 242 | }, |
243 | 243 | ]; |