@@ -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. |
@@ -367,10 +366,10 @@ discard block |
||
367 | 366 | array $separators |
368 | 367 | ) { |
369 | 368 | $pid = $statement->getPropertyId()->serialize(); |
370 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
369 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
371 | 370 | |
372 | - $separatorFilters = array_map( [ $this, 'nestedSeparatorFilter' ], $separators ); |
|
373 | - $finalSeparatorFilter = implode( "\n", $separatorFilters ); |
|
371 | + $separatorFilters = array_map([$this, 'nestedSeparatorFilter'], $separators); |
|
372 | + $finalSeparatorFilter = implode("\n", $separatorFilters); |
|
374 | 373 | |
375 | 374 | $query = <<<EOF |
376 | 375 | SELECT DISTINCT ?otherEntity WHERE { |
@@ -388,9 +387,9 @@ discard block |
||
388 | 387 | LIMIT 10 |
389 | 388 | EOF; |
390 | 389 | |
391 | - $result = $this->runQuery( $query ); |
|
390 | + $result = $this->runQuery($query); |
|
392 | 391 | |
393 | - return $this->getOtherEntities( $result ); |
|
392 | + return $this->getOtherEntities($result); |
|
394 | 393 | } |
395 | 394 | |
396 | 395 | /** |
@@ -415,16 +414,15 @@ discard block |
||
415 | 414 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
416 | 415 | $snak->getPropertyId() |
417 | 416 | ); |
418 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
419 | - if ( $isFullValue ) { |
|
417 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
418 | + if ($isFullValue) { |
|
420 | 419 | $prefix .= 'v'; |
421 | 420 | } |
422 | 421 | $path = $type === Context::TYPE_QUALIFIER ? |
423 | - "$prefix:$pid" : |
|
424 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
422 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
425 | 423 | |
426 | 424 | $deprecatedFilter = ''; |
427 | - if ( $ignoreDeprecatedStatements ) { |
|
425 | + if ($ignoreDeprecatedStatements) { |
|
428 | 426 | $deprecatedFilter = <<< EOF |
429 | 427 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
430 | 428 | EOF; |
@@ -444,9 +442,9 @@ discard block |
||
444 | 442 | LIMIT 10 |
445 | 443 | EOF; |
446 | 444 | |
447 | - $result = $this->runQuery( $query ); |
|
445 | + $result = $this->runQuery($query); |
|
448 | 446 | |
449 | - return $this->getOtherEntities( $result ); |
|
447 | + return $this->getOtherEntities($result); |
|
450 | 448 | } |
451 | 449 | |
452 | 450 | /** |
@@ -456,8 +454,8 @@ discard block |
||
456 | 454 | * |
457 | 455 | * @return string |
458 | 456 | */ |
459 | - private function stringLiteral( $text ) { |
|
460 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
457 | + private function stringLiteral($text) { |
|
458 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
461 | 459 | } |
462 | 460 | |
463 | 461 | /** |
@@ -467,18 +465,18 @@ discard block |
||
467 | 465 | * |
468 | 466 | * @return CachedEntityIds |
469 | 467 | */ |
470 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
471 | - return new CachedEntityIds( array_map( |
|
472 | - function ( $resultBindings ) { |
|
468 | + private function getOtherEntities(CachedQueryResults $results) { |
|
469 | + return new CachedEntityIds(array_map( |
|
470 | + function($resultBindings) { |
|
473 | 471 | $entityIRI = $resultBindings['otherEntity']['value']; |
474 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
475 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
476 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
472 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
473 | + $entityPrefixLength = strlen($entityPrefix); |
|
474 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
477 | 475 | try { |
478 | 476 | return $this->entityIdParser->parse( |
479 | - substr( $entityIRI, $entityPrefixLength ) |
|
477 | + substr($entityIRI, $entityPrefixLength) |
|
480 | 478 | ); |
481 | - } catch ( EntityIdParsingException $e ) { |
|
479 | + } catch (EntityIdParsingException $e) { |
|
482 | 480 | // fall through |
483 | 481 | } |
484 | 482 | } |
@@ -489,7 +487,7 @@ discard block |
||
489 | 487 | return null; |
490 | 488 | }, |
491 | 489 | $results->getArray()['results']['bindings'] |
492 | - ), $results->getMetadata() ); |
|
490 | + ), $results->getMetadata()); |
|
493 | 491 | } |
494 | 492 | |
495 | 493 | // phpcs:disable Generic.Metrics.CyclomaticComplexity,Squiz.WhiteSpace.FunctionSpacing |
@@ -502,50 +500,50 @@ discard block |
||
502 | 500 | * @return array the literal or IRI as a string in SPARQL syntax, |
503 | 501 | * and a boolean indicating whether it refers to a full value node or not |
504 | 502 | */ |
505 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
506 | - switch ( $dataType ) { |
|
503 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
504 | + switch ($dataType) { |
|
507 | 505 | case 'string': |
508 | 506 | case 'external-id': |
509 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
507 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
510 | 508 | case 'commonsMedia': |
511 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
512 | - return [ '<' . $url . '>', false ]; |
|
509 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
510 | + return ['<'.$url.'>', false]; |
|
513 | 511 | case 'geo-shape': |
514 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
515 | - return [ '<' . $url . '>', false ]; |
|
512 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
513 | + return ['<'.$url.'>', false]; |
|
516 | 514 | case 'tabular-data': |
517 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
518 | - return [ '<' . $url . '>', false ]; |
|
515 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
516 | + return ['<'.$url.'>', false]; |
|
519 | 517 | case 'url': |
520 | 518 | $url = $dataValue->getValue(); |
521 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
519 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
522 | 520 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
523 | 521 | // such an URL should never reach us, so just throw |
524 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
522 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
525 | 523 | } |
526 | - return [ '<' . $url . '>', false ]; |
|
524 | + return ['<'.$url.'>', false]; |
|
527 | 525 | case 'wikibase-item': |
528 | 526 | case 'wikibase-property': |
529 | 527 | /** @var EntityIdValue $dataValue */ |
530 | 528 | '@phan-var EntityIdValue $dataValue'; |
531 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
529 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
532 | 530 | case 'monolingualtext': |
533 | 531 | /** @var MonolingualTextValue $dataValue */ |
534 | 532 | '@phan-var MonolingualTextValue $dataValue'; |
535 | 533 | $lang = $dataValue->getLanguageCode(); |
536 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
534 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
537 | 535 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
538 | 536 | // such a language tag should never reach us, so just throw |
539 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
537 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
540 | 538 | } |
541 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
539 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
542 | 540 | case 'globe-coordinate': |
543 | 541 | case 'quantity': |
544 | 542 | case 'time': |
545 | 543 | // @phan-suppress-next-line PhanUndeclaredMethod |
546 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
544 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
547 | 545 | default: |
548 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
546 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
549 | 547 | } |
550 | 548 | } |
551 | 549 | // phpcs:enable |
@@ -558,43 +556,43 @@ discard block |
||
558 | 556 | * @throws SparqlHelperException if the query times out or some other error occurs |
559 | 557 | * @throws ConstraintParameterException if the $regex is invalid |
560 | 558 | */ |
561 | - public function matchesRegularExpression( $text, $regex ) { |
|
559 | + public function matchesRegularExpression($text, $regex) { |
|
562 | 560 | // caching wrapper around matchesRegularExpressionWithSparql |
563 | 561 | |
564 | - $textHash = hash( 'sha256', $text ); |
|
562 | + $textHash = hash('sha256', $text); |
|
565 | 563 | $cacheKey = $this->cache->makeKey( |
566 | 564 | 'WikibaseQualityConstraints', // extension |
567 | 565 | 'regex', // action |
568 | 566 | 'WDQS-Java', // regex flavor |
569 | - hash( 'sha256', $regex ) |
|
567 | + hash('sha256', $regex) |
|
570 | 568 | ); |
571 | 569 | |
572 | 570 | $cacheMapArray = $this->cache->getWithSetCallback( |
573 | 571 | $cacheKey, |
574 | 572 | WANObjectCache::TTL_DAY, |
575 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
573 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
576 | 574 | // Initialize the cache map if not set |
577 | - if ( $cacheMapArray === false ) { |
|
575 | + if ($cacheMapArray === false) { |
|
578 | 576 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
579 | - $this->dataFactory->increment( $key ); |
|
577 | + $this->dataFactory->increment($key); |
|
580 | 578 | return []; |
581 | 579 | } |
582 | 580 | |
583 | 581 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
584 | - $this->dataFactory->increment( $key ); |
|
585 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
586 | - if ( $cacheMap->has( $textHash ) ) { |
|
582 | + $this->dataFactory->increment($key); |
|
583 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
584 | + if ($cacheMap->has($textHash)) { |
|
587 | 585 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
588 | - $this->dataFactory->increment( $key ); |
|
589 | - $cacheMap->get( $textHash ); // ping cache |
|
586 | + $this->dataFactory->increment($key); |
|
587 | + $cacheMap->get($textHash); // ping cache |
|
590 | 588 | } else { |
591 | 589 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
592 | - $this->dataFactory->increment( $key ); |
|
590 | + $this->dataFactory->increment($key); |
|
593 | 591 | try { |
594 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
595 | - } catch ( ConstraintParameterException $e ) { |
|
596 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
597 | - } catch ( SparqlHelperException $e ) { |
|
592 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
593 | + } catch (ConstraintParameterException $e) { |
|
594 | + $matches = $this->serializeConstraintParameterException($e); |
|
595 | + } catch (SparqlHelperException $e) { |
|
598 | 596 | // don’t cache this |
599 | 597 | return $cacheMap->toArray(); |
600 | 598 | } |
@@ -618,42 +616,42 @@ discard block |
||
618 | 616 | ] |
619 | 617 | ); |
620 | 618 | |
621 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
619 | + if (isset($cacheMapArray[$textHash])) { |
|
622 | 620 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
623 | - $this->dataFactory->increment( $key ); |
|
621 | + $this->dataFactory->increment($key); |
|
624 | 622 | $matches = $cacheMapArray[$textHash]; |
625 | - if ( is_bool( $matches ) ) { |
|
623 | + if (is_bool($matches)) { |
|
626 | 624 | return $matches; |
627 | - } elseif ( is_array( $matches ) && |
|
628 | - $matches['type'] == ConstraintParameterException::class ) { |
|
629 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
625 | + } elseif (is_array($matches) && |
|
626 | + $matches['type'] == ConstraintParameterException::class) { |
|
627 | + throw $this->deserializeConstraintParameterException($matches); |
|
630 | 628 | } else { |
631 | 629 | throw new MWException( |
632 | - 'Value of unknown type in object cache (' . |
|
633 | - 'cache key: ' . $cacheKey . ', ' . |
|
634 | - 'cache map key: ' . $textHash . ', ' . |
|
635 | - 'value type: ' . gettype( $matches ) . ')' |
|
630 | + 'Value of unknown type in object cache ('. |
|
631 | + 'cache key: '.$cacheKey.', '. |
|
632 | + 'cache map key: '.$textHash.', '. |
|
633 | + 'value type: '.gettype($matches).')' |
|
636 | 634 | ); |
637 | 635 | } |
638 | 636 | } else { |
639 | 637 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
640 | - $this->dataFactory->increment( $key ); |
|
641 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
638 | + $this->dataFactory->increment($key); |
|
639 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
642 | 640 | } |
643 | 641 | } |
644 | 642 | |
645 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
643 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
646 | 644 | return [ |
647 | 645 | 'type' => ConstraintParameterException::class, |
648 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
646 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
649 | 647 | ]; |
650 | 648 | } |
651 | 649 | |
652 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
650 | + private function deserializeConstraintParameterException(array $serialization) { |
|
653 | 651 | $message = $this->violationMessageDeserializer->deserialize( |
654 | 652 | $serialization['violationMessage'] |
655 | 653 | ); |
656 | - return new ConstraintParameterException( $message ); |
|
654 | + return new ConstraintParameterException($message); |
|
657 | 655 | } |
658 | 656 | |
659 | 657 | /** |
@@ -667,25 +665,25 @@ discard block |
||
667 | 665 | * @throws SparqlHelperException if the query times out or some other error occurs |
668 | 666 | * @throws ConstraintParameterException if the $regex is invalid |
669 | 667 | */ |
670 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
671 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
672 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
668 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
669 | + $textStringLiteral = $this->stringLiteral($text); |
|
670 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
673 | 671 | |
674 | 672 | $query = <<<EOF |
675 | 673 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
676 | 674 | EOF; |
677 | 675 | |
678 | - $result = $this->runQuery( $query, false ); |
|
676 | + $result = $this->runQuery($query, false); |
|
679 | 677 | |
680 | 678 | $vars = $result->getArray()['results']['bindings'][0]; |
681 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
679 | + if (array_key_exists('matches', $vars)) { |
|
682 | 680 | // true or false ⇒ regex okay, text matches or not |
683 | 681 | return $vars['matches']['value'] === 'true'; |
684 | 682 | } else { |
685 | 683 | // empty result: regex broken |
686 | 684 | throw new ConstraintParameterException( |
687 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
688 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
685 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
686 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
689 | 687 | ); |
690 | 688 | } |
691 | 689 | } |
@@ -697,14 +695,14 @@ discard block |
||
697 | 695 | * |
698 | 696 | * @return boolean |
699 | 697 | */ |
700 | - public function isTimeout( $responseContent ) { |
|
701 | - $timeoutRegex = implode( '|', array_map( |
|
702 | - static function ( $fqn ) { |
|
703 | - return preg_quote( $fqn, '/' ); |
|
698 | + public function isTimeout($responseContent) { |
|
699 | + $timeoutRegex = implode('|', array_map( |
|
700 | + static function($fqn) { |
|
701 | + return preg_quote($fqn, '/'); |
|
704 | 702 | }, |
705 | 703 | $this->timeoutExceptionClasses |
706 | - ) ); |
|
707 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
704 | + )); |
|
705 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
708 | 706 | } |
709 | 707 | |
710 | 708 | /** |
@@ -716,17 +714,17 @@ discard block |
||
716 | 714 | * @return int|boolean the max-age (in seconds) |
717 | 715 | * or a plain boolean if no max-age can be determined |
718 | 716 | */ |
719 | - public function getCacheMaxAge( $responseHeaders ) { |
|
717 | + public function getCacheMaxAge($responseHeaders) { |
|
720 | 718 | if ( |
721 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
722 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
719 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
720 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
723 | 721 | ) { |
724 | 722 | $maxage = []; |
725 | 723 | if ( |
726 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
727 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
724 | + array_key_exists('cache-control', $responseHeaders) && |
|
725 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
728 | 726 | ) { |
729 | - return intval( $maxage[1] ); |
|
727 | + return intval($maxage[1]); |
|
730 | 728 | } else { |
731 | 729 | return true; |
732 | 730 | } |
@@ -747,34 +745,34 @@ discard block |
||
747 | 745 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
748 | 746 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
749 | 747 | */ |
750 | - public function getThrottling( MWHttpRequest $request ) { |
|
751 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
752 | - if ( $retryAfterValue === null ) { |
|
748 | + public function getThrottling(MWHttpRequest $request) { |
|
749 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
750 | + if ($retryAfterValue === null) { |
|
753 | 751 | return self::NO_RETRY_AFTER; |
754 | 752 | } |
755 | 753 | |
756 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
757 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
754 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
755 | + if (empty($trimmedRetryAfterValue)) { |
|
758 | 756 | return self::EMPTY_RETRY_AFTER; |
759 | 757 | } |
760 | 758 | |
761 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
762 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
763 | - if ( $delaySeconds >= 0 ) { |
|
764 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
759 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
760 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
761 | + if ($delaySeconds >= 0) { |
|
762 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
765 | 763 | } |
766 | 764 | } else { |
767 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
768 | - if ( !empty( $return ) ) { |
|
769 | - return new ConvertibleTimestamp( $return ); |
|
765 | + $return = strtotime($trimmedRetryAfterValue); |
|
766 | + if (!empty($return)) { |
|
767 | + return new ConvertibleTimestamp($return); |
|
770 | 768 | } |
771 | 769 | } |
772 | 770 | return self::INVALID_RETRY_AFTER; |
773 | 771 | } |
774 | 772 | |
775 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
773 | + private function getTimestampInFuture(DateInterval $delta) { |
|
776 | 774 | $now = new ConvertibleTimestamp(); |
777 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
775 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
778 | 776 | } |
779 | 777 | |
780 | 778 | /** |
@@ -788,65 +786,64 @@ discard block |
||
788 | 786 | * |
789 | 787 | * @throws SparqlHelperException if the query times out or some other error occurs |
790 | 788 | */ |
791 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
789 | + public function runQuery($query, $needsPrefixes = true) { |
|
792 | 790 | |
793 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
794 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
791 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
792 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
795 | 793 | throw new TooManySparqlRequestsException(); |
796 | 794 | } |
797 | 795 | |
798 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
796 | + if ($this->sparqlHasWikibaseSupport) { |
|
799 | 797 | $needsPrefixes = false; |
800 | 798 | } |
801 | 799 | |
802 | - if ( $needsPrefixes ) { |
|
803 | - $query = $this->prefixes . $query; |
|
800 | + if ($needsPrefixes) { |
|
801 | + $query = $this->prefixes.$query; |
|
804 | 802 | } |
805 | - $query = "#wbqc\n" . $query; |
|
803 | + $query = "#wbqc\n".$query; |
|
806 | 804 | |
807 | - $url = $this->endpoint . '?' . http_build_query( |
|
805 | + $url = $this->endpoint.'?'.http_build_query( |
|
808 | 806 | [ |
809 | 807 | 'query' => $query, |
810 | 808 | 'format' => 'json', |
811 | 809 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
812 | 810 | ], |
813 | - null, ini_get( 'arg_separator.output' ), |
|
811 | + null, ini_get('arg_separator.output'), |
|
814 | 812 | // encode spaces with %20, not + |
815 | 813 | PHP_QUERY_RFC3986 |
816 | 814 | ); |
817 | 815 | |
818 | 816 | $options = [ |
819 | 817 | 'method' => 'GET', |
820 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
818 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
821 | 819 | 'connectTimeout' => 'default', |
822 | 820 | 'userAgent' => $this->defaultUserAgent, |
823 | 821 | ]; |
824 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
825 | - $startTime = microtime( true ); |
|
822 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
823 | + $startTime = microtime(true); |
|
826 | 824 | $requestStatus = $request->execute(); |
827 | - $endTime = microtime( true ); |
|
825 | + $endTime = microtime(true); |
|
828 | 826 | $this->dataFactory->timing( |
829 | 827 | 'wikibase.quality.constraints.sparql.timing', |
830 | - ( $endTime - $startTime ) * 1000 |
|
828 | + ($endTime - $startTime) * 1000 |
|
831 | 829 | ); |
832 | 830 | |
833 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
831 | + $this->guardAgainstTooManyRequestsError($request); |
|
834 | 832 | |
835 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
836 | - if ( $maxAge ) { |
|
837 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
833 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
834 | + if ($maxAge) { |
|
835 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
838 | 836 | } |
839 | 837 | |
840 | - if ( $requestStatus->isOK() ) { |
|
838 | + if ($requestStatus->isOK()) { |
|
841 | 839 | $json = $request->getContent(); |
842 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
843 | - if ( $jsonStatus->isOK() ) { |
|
840 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
841 | + if ($jsonStatus->isOK()) { |
|
844 | 842 | return new CachedQueryResults( |
845 | 843 | $jsonStatus->getValue(), |
846 | 844 | Metadata::ofCachingMetadata( |
847 | 845 | $maxAge ? |
848 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
849 | - CachingMetadata::fresh() |
|
846 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
850 | 847 | ) |
851 | 848 | ); |
852 | 849 | } else { |
@@ -863,9 +860,9 @@ discard block |
||
863 | 860 | // fall through to general error handling |
864 | 861 | } |
865 | 862 | |
866 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
863 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
867 | 864 | |
868 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
865 | + if ($this->isTimeout($request->getContent())) { |
|
869 | 866 | $this->dataFactory->increment( |
870 | 867 | 'wikibase.quality.constraints.sparql.error.timeout' |
871 | 868 | ); |
@@ -880,29 +877,29 @@ discard block |
||
880 | 877 | * @param MWHttpRequest $request |
881 | 878 | * @throws TooManySparqlRequestsException |
882 | 879 | */ |
883 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
884 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
880 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
881 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
885 | 882 | return; |
886 | 883 | } |
887 | 884 | |
888 | 885 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
889 | 886 | |
890 | - if ( $fallbackBlockDuration < 0 ) { |
|
891 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
892 | - $fallbackBlockDuration ); |
|
887 | + if ($fallbackBlockDuration < 0) { |
|
888 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
889 | + $fallbackBlockDuration); |
|
893 | 890 | } |
894 | 891 | |
895 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
896 | - $throttlingUntil = $this->getThrottling( $request ); |
|
897 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
898 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
892 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
893 | + $throttlingUntil = $this->getThrottling($request); |
|
894 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
895 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
899 | 896 | $this->throttlingLock->lock( |
900 | 897 | self::EXPIRY_LOCK_ID, |
901 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
898 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
902 | 899 | ); |
903 | 900 | } else { |
904 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
905 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
901 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
902 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
906 | 903 | } |
907 | 904 | throw new TooManySparqlRequestsException(); |
908 | 905 | } |
@@ -23,15 +23,15 @@ 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( |
31 | 31 | Statement $statement, |
32 | 32 | array $separators |
33 | 33 | ) { |
34 | - throw new LogicException( 'methods of this class should never be called' ); |
|
34 | + throw new LogicException('methods of this class should never be called'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function findEntitiesWithSameQualifierOrReference( |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | $type, |
41 | 41 | $ignoreDeprecatedStatements |
42 | 42 | ) { |
43 | - throw new LogicException( 'methods of this class should never be called' ); |
|
43 | + throw new LogicException('methods of this class should never be called'); |
|
44 | 44 | } |
45 | 45 | |
46 | - public function matchesRegularExpression( $text, $regex ) { |
|
47 | - throw new LogicException( 'methods of this class should never be called' ); |
|
46 | + public function matchesRegularExpression($text, $regex) { |
|
47 | + throw new LogicException('methods of this class should never be called'); |
|
48 | 48 | } |
49 | 49 | |
50 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
51 | - throw new LogicException( 'methods of this class should never be called' ); |
|
50 | + public function runQuery($query, $needsPrefixes = true) { |
|
51 | + throw new LogicException('methods of this class should never be called'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -76,29 +76,29 @@ 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 | $separators |
96 | 96 | ); |
97 | 97 | } else { |
98 | 98 | $snak = $context->getSnak(); |
99 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
99 | + if (!$snak instanceof PropertyValueSnak) { |
|
100 | 100 | // nothing to check |
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
102 | 102 | } |
103 | 103 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
104 | 104 | $context->getEntity()->getId(), |
@@ -111,32 +111,32 @@ discard block |
||
111 | 111 | $otherEntities = $result->getArray(); |
112 | 112 | $metadata = $result->getMetadata(); |
113 | 113 | |
114 | - if ( $otherEntities === [] ) { |
|
114 | + if ($otherEntities === []) { |
|
115 | 115 | $status = CheckResult::STATUS_COMPLIANCE; |
116 | 116 | $message = null; |
117 | 117 | } else { |
118 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
118 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
119 | 119 | $status = CheckResult::STATUS_VIOLATION; |
120 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
121 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
120 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
121 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
122 | 122 | } |
123 | 123 | } else { |
124 | 124 | $status = CheckResult::STATUS_TODO; |
125 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
126 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
125 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
126 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
127 | 127 | $metadata = Metadata::blank(); |
128 | 128 | } |
129 | 129 | |
130 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
131 | - ->withMetadata( $metadata ); |
|
130 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
131 | + ->withMetadata($metadata); |
|
132 | 132 | } |
133 | 133 | |
134 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
134 | + public function checkConstraintParameters(Constraint $constraint) { |
|
135 | 135 | $constraintParameters = $constraint->getConstraintParameters(); |
136 | 136 | $exceptions = []; |
137 | 137 | try { |
138 | - $this->constraintParameterParser->parseSeparatorsParameter( $constraintParameters ); |
|
139 | - } catch ( ConstraintParameterException $e ) { |
|
138 | + $this->constraintParameterParser->parseSeparatorsParameter($constraintParameters); |
|
139 | + } catch (ConstraintParameterException $e) { |
|
140 | 140 | $exceptions[] = $e; |
141 | 141 | } |
142 | 142 | return $exceptions; |