@@ -76,18 +76,18 @@ 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 | |
84 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
84 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
85 | 85 | |
86 | 86 | $separators = $this->constraintParameterParser->parseSeparatorsParameter( |
87 | 87 | $constraint->getConstraintParameters() |
88 | 88 | ); |
89 | 89 | |
90 | - if ( $context->getType() === 'statement' ) { |
|
90 | + if ($context->getType() === 'statement') { |
|
91 | 91 | $statement = $context->getSnakStatement(); |
92 | 92 | '@phan-var Statement $statement'; |
93 | 93 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
@@ -96,9 +96,9 @@ discard block |
||
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,31 +111,31 @@ 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 | 118 | $status = CheckResult::STATUS_VIOLATION; |
119 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
120 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
119 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
120 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
121 | 121 | } |
122 | 122 | } else { |
123 | 123 | $status = CheckResult::STATUS_TODO; |
124 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
125 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
124 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
125 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
126 | 126 | $metadata = Metadata::blank(); |
127 | 127 | } |
128 | 128 | |
129 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
130 | - ->withMetadata( $metadata ); |
|
129 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
130 | + ->withMetadata($metadata); |
|
131 | 131 | } |
132 | 132 | |
133 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
133 | + public function checkConstraintParameters(Constraint $constraint) { |
|
134 | 134 | $constraintParameters = $constraint->getConstraintParameters(); |
135 | 135 | $exceptions = []; |
136 | 136 | try { |
137 | - $this->constraintParameterParser->parseSeparatorsParameter( $constraintParameters ); |
|
138 | - } catch ( ConstraintParameterException $e ) { |
|
137 | + $this->constraintParameterParser->parseSeparatorsParameter($constraintParameters); |
|
138 | + } catch (ConstraintParameterException $e) { |
|
139 | 139 | $exceptions[] = $e; |
140 | 140 | } |
141 | 141 | return $exceptions; |
@@ -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, $endpoint, $needsPrefixes = true ) { |
|
51 | - throw new LogicException( 'methods of this class should never be called' ); |
|
50 | + public function runQuery($query, $endpoint, $needsPrefixes = true) { |
|
51 | + throw new LogicException('methods of this class should never be called'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -205,74 +205,74 @@ discard block |
||
205 | 205 | $this->defaultUserAgent = $defaultUserAgent; |
206 | 206 | $this->requestFactory = $requestFactory; |
207 | 207 | $this->entityPrefixes = []; |
208 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
209 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
208 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
209 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
210 | 210 | } |
211 | 211 | |
212 | - $this->primaryEndpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
213 | - $this->additionalEndpoints = $config->get( 'WBQualityConstraintsAdditionalSparqlEndpoints' ) ?: []; |
|
214 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
215 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
216 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
217 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
212 | + $this->primaryEndpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
213 | + $this->additionalEndpoints = $config->get('WBQualityConstraintsAdditionalSparqlEndpoints') ?: []; |
|
214 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
215 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
216 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
217 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
218 | 218 | $this->timeoutExceptionClasses = $config->get( |
219 | 219 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
220 | 220 | ); |
221 | 221 | $this->sparqlHasWikibaseSupport = $config->get( |
222 | 222 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
223 | 223 | ); |
224 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
224 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
225 | 225 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
226 | 226 | ); |
227 | 227 | |
228 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
228 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
229 | 229 | } |
230 | 230 | |
231 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
231 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
232 | 232 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
233 | 233 | $prefixes = ''; |
234 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
234 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
235 | 235 | $prefixes .= <<<END |
236 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
236 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
237 | 237 | END; |
238 | 238 | } |
239 | 239 | $prefixes .= <<<END |
240 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
241 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
240 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
241 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
242 | 242 | END; |
243 | 243 | |
244 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
244 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
245 | 245 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
246 | 246 | $prefixes .= <<<END |
247 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
247 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
248 | 248 | END; |
249 | 249 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
250 | 250 | $prefixes .= <<<END |
251 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
251 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
252 | 252 | END; |
253 | 253 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
254 | 254 | $prefixes .= <<<END |
255 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
255 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
256 | 256 | END; |
257 | 257 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
258 | 258 | $prefixes .= <<<END |
259 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
259 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
260 | 260 | END; |
261 | 261 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
262 | 262 | $prefixes .= <<<END |
263 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
263 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
264 | 264 | END; |
265 | 265 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
266 | 266 | $prefixes .= <<<END |
267 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
267 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
268 | 268 | END; |
269 | 269 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
270 | 270 | $prefixes .= <<<END |
271 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
271 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
272 | 272 | END; |
273 | 273 | } |
274 | 274 | $prefixes .= <<<END |
275 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
275 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
276 | 276 | END; |
277 | 277 | return $prefixes; |
278 | 278 | } |
@@ -284,21 +284,20 @@ discard block |
||
284 | 284 | * @return CachedBool |
285 | 285 | * @throws SparqlHelperException if the query times out or some other error occurs |
286 | 286 | */ |
287 | - public function hasType( $id, array $classes ) { |
|
287 | + public function hasType($id, array $classes) { |
|
288 | 288 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
289 | 289 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
290 | - ' hint:Prior hint:gearing "forward".' : |
|
291 | - ''; |
|
290 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
292 | 291 | |
293 | 292 | $metadatas = []; |
294 | 293 | |
295 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
296 | - $classesValues = implode( ' ', array_map( |
|
297 | - static function ( $class ) { |
|
298 | - return 'wd:' . $class; |
|
294 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
295 | + $classesValues = implode(' ', array_map( |
|
296 | + static function($class) { |
|
297 | + return 'wd:'.$class; |
|
299 | 298 | }, |
300 | 299 | $classesChunk |
301 | - ) ); |
|
300 | + )); |
|
302 | 301 | |
303 | 302 | $query = <<<EOF |
304 | 303 | ASK { |
@@ -308,19 +307,19 @@ discard block |
||
308 | 307 | } |
309 | 308 | EOF; |
310 | 309 | |
311 | - $result = $this->runQuery( $query, $this->primaryEndpoint ); |
|
310 | + $result = $this->runQuery($query, $this->primaryEndpoint); |
|
312 | 311 | $metadatas[] = $result->getMetadata(); |
313 | - if ( $result->getArray()['boolean'] ) { |
|
312 | + if ($result->getArray()['boolean']) { |
|
314 | 313 | return new CachedBool( |
315 | 314 | true, |
316 | - Metadata::merge( $metadatas ) |
|
315 | + Metadata::merge($metadatas) |
|
317 | 316 | ); |
318 | 317 | } |
319 | 318 | } |
320 | 319 | |
321 | 320 | return new CachedBool( |
322 | 321 | false, |
323 | - Metadata::merge( $metadatas ) |
|
322 | + Metadata::merge($metadatas) |
|
324 | 323 | ); |
325 | 324 | } |
326 | 325 | |
@@ -331,7 +330,7 @@ discard block |
||
331 | 330 | * @param PropertyId $separator |
332 | 331 | * @return string |
333 | 332 | */ |
334 | - private function nestedSeparatorFilter( PropertyId $separator ) { |
|
333 | + private function nestedSeparatorFilter(PropertyId $separator) { |
|
335 | 334 | $filter = <<<EOF |
336 | 335 | MINUS { |
337 | 336 | ?statement pq:$separator ?qualifier. |
@@ -375,10 +374,10 @@ discard block |
||
375 | 374 | $pid = $statement->getPropertyId()->getSerialization(); |
376 | 375 | $guid = $statement->getGuid(); |
377 | 376 | '@phan-var string $guid'; // statement must have a non-null GUID |
378 | - $guidForRdf = str_replace( '$', '-', $guid ); |
|
377 | + $guidForRdf = str_replace('$', '-', $guid); |
|
379 | 378 | |
380 | - $separatorFilters = array_map( [ $this, 'nestedSeparatorFilter' ], $separators ); |
|
381 | - $finalSeparatorFilter = implode( "\n", $separatorFilters ); |
|
379 | + $separatorFilters = array_map([$this, 'nestedSeparatorFilter'], $separators); |
|
380 | + $finalSeparatorFilter = implode("\n", $separatorFilters); |
|
382 | 381 | |
383 | 382 | $query = <<<EOF |
384 | 383 | SELECT DISTINCT ?otherEntity WHERE { |
@@ -396,12 +395,12 @@ discard block |
||
396 | 395 | LIMIT 10 |
397 | 396 | EOF; |
398 | 397 | |
399 | - $results = [ $this->runQuery( $query, $this->primaryEndpoint ) ]; |
|
400 | - foreach ( $this->additionalEndpoints as $endpoint ) { |
|
401 | - $results[] = $this->runQuery( $query, $endpoint ); |
|
398 | + $results = [$this->runQuery($query, $this->primaryEndpoint)]; |
|
399 | + foreach ($this->additionalEndpoints as $endpoint) { |
|
400 | + $results[] = $this->runQuery($query, $endpoint); |
|
402 | 401 | } |
403 | 402 | |
404 | - return $this->getOtherEntities( $results ); |
|
403 | + return $this->getOtherEntities($results); |
|
405 | 404 | } |
406 | 405 | |
407 | 406 | /** |
@@ -426,16 +425,15 @@ discard block |
||
426 | 425 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
427 | 426 | $snak->getPropertyId() |
428 | 427 | ); |
429 | - [ $value, $isFullValue ] = $this->getRdfLiteral( $dataType, $dataValue ); |
|
430 | - if ( $isFullValue ) { |
|
428 | + [$value, $isFullValue] = $this->getRdfLiteral($dataType, $dataValue); |
|
429 | + if ($isFullValue) { |
|
431 | 430 | $prefix .= 'v'; |
432 | 431 | } |
433 | 432 | $path = $type === Context::TYPE_QUALIFIER ? |
434 | - "$prefix:$pid" : |
|
435 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
433 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
436 | 434 | |
437 | 435 | $deprecatedFilter = ''; |
438 | - if ( $ignoreDeprecatedStatements ) { |
|
436 | + if ($ignoreDeprecatedStatements) { |
|
439 | 437 | $deprecatedFilter = <<< EOF |
440 | 438 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
441 | 439 | EOF; |
@@ -455,12 +453,12 @@ discard block |
||
455 | 453 | LIMIT 10 |
456 | 454 | EOF; |
457 | 455 | |
458 | - $results = [ $this->runQuery( $query, $this->primaryEndpoint ) ]; |
|
459 | - foreach ( $this->additionalEndpoints as $endpoint ) { |
|
460 | - $results[] = $this->runQuery( $query, $endpoint ); |
|
456 | + $results = [$this->runQuery($query, $this->primaryEndpoint)]; |
|
457 | + foreach ($this->additionalEndpoints as $endpoint) { |
|
458 | + $results[] = $this->runQuery($query, $endpoint); |
|
461 | 459 | } |
462 | 460 | |
463 | - return $this->getOtherEntities( $results ); |
|
461 | + return $this->getOtherEntities($results); |
|
464 | 462 | } |
465 | 463 | |
466 | 464 | /** |
@@ -470,8 +468,8 @@ discard block |
||
470 | 468 | * |
471 | 469 | * @return string |
472 | 470 | */ |
473 | - private function stringLiteral( $text ) { |
|
474 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
471 | + private function stringLiteral($text) { |
|
472 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
475 | 473 | } |
476 | 474 | |
477 | 475 | /** |
@@ -481,26 +479,26 @@ discard block |
||
481 | 479 | * |
482 | 480 | * @return CachedEntityIds |
483 | 481 | */ |
484 | - private function getOtherEntities( array $results ) { |
|
482 | + private function getOtherEntities(array $results) { |
|
485 | 483 | $allResultBindings = []; |
486 | 484 | $metadatas = []; |
487 | 485 | |
488 | - foreach ( $results as $result ) { |
|
486 | + foreach ($results as $result) { |
|
489 | 487 | $metadatas[] = $result->getMetadata(); |
490 | - $allResultBindings = array_merge( $allResultBindings, $result->getArray()['results']['bindings'] ); |
|
488 | + $allResultBindings = array_merge($allResultBindings, $result->getArray()['results']['bindings']); |
|
491 | 489 | } |
492 | 490 | |
493 | 491 | $entityIds = array_map( |
494 | - function ( $resultBindings ) { |
|
492 | + function($resultBindings) { |
|
495 | 493 | $entityIRI = $resultBindings['otherEntity']['value']; |
496 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
497 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
498 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
494 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
495 | + $entityPrefixLength = strlen($entityPrefix); |
|
496 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
499 | 497 | try { |
500 | 498 | return $this->entityIdParser->parse( |
501 | - substr( $entityIRI, $entityPrefixLength ) |
|
499 | + substr($entityIRI, $entityPrefixLength) |
|
502 | 500 | ); |
503 | - } catch ( EntityIdParsingException $e ) { |
|
501 | + } catch (EntityIdParsingException $e) { |
|
504 | 502 | // fall through |
505 | 503 | } |
506 | 504 | } |
@@ -514,8 +512,8 @@ discard block |
||
514 | 512 | ); |
515 | 513 | |
516 | 514 | return new CachedEntityIds( |
517 | - array_values( array_filter( array_unique( $entityIds ) ) ), |
|
518 | - Metadata::merge( $metadatas ) |
|
515 | + array_values(array_filter(array_unique($entityIds))), |
|
516 | + Metadata::merge($metadatas) |
|
519 | 517 | ); |
520 | 518 | } |
521 | 519 | |
@@ -529,50 +527,50 @@ discard block |
||
529 | 527 | * @return array the literal or IRI as a string in SPARQL syntax, |
530 | 528 | * and a boolean indicating whether it refers to a full value node or not |
531 | 529 | */ |
532 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
533 | - switch ( $dataType ) { |
|
530 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
531 | + switch ($dataType) { |
|
534 | 532 | case 'string': |
535 | 533 | case 'external-id': |
536 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
534 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
537 | 535 | case 'commonsMedia': |
538 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
539 | - return [ '<' . $url . '>', false ]; |
|
536 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
537 | + return ['<'.$url.'>', false]; |
|
540 | 538 | case 'geo-shape': |
541 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
542 | - return [ '<' . $url . '>', false ]; |
|
539 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
540 | + return ['<'.$url.'>', false]; |
|
543 | 541 | case 'tabular-data': |
544 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
545 | - return [ '<' . $url . '>', false ]; |
|
542 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
543 | + return ['<'.$url.'>', false]; |
|
546 | 544 | case 'url': |
547 | 545 | $url = $dataValue->getValue(); |
548 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
546 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
549 | 547 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
550 | 548 | // such an URL should never reach us, so just throw |
551 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
549 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
552 | 550 | } |
553 | - return [ '<' . $url . '>', false ]; |
|
551 | + return ['<'.$url.'>', false]; |
|
554 | 552 | case 'wikibase-item': |
555 | 553 | case 'wikibase-property': |
556 | 554 | /** @var EntityIdValue $dataValue */ |
557 | 555 | '@phan-var EntityIdValue $dataValue'; |
558 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
556 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
559 | 557 | case 'monolingualtext': |
560 | 558 | /** @var MonolingualTextValue $dataValue */ |
561 | 559 | '@phan-var MonolingualTextValue $dataValue'; |
562 | 560 | $lang = $dataValue->getLanguageCode(); |
563 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
561 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
564 | 562 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
565 | 563 | // such a language tag should never reach us, so just throw |
566 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
564 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
567 | 565 | } |
568 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
566 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
569 | 567 | case 'globe-coordinate': |
570 | 568 | case 'quantity': |
571 | 569 | case 'time': |
572 | 570 | // @phan-suppress-next-line PhanUndeclaredMethod |
573 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
571 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
574 | 572 | default: |
575 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
573 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
576 | 574 | } |
577 | 575 | } |
578 | 576 | // phpcs:enable |
@@ -585,43 +583,43 @@ discard block |
||
585 | 583 | * @throws SparqlHelperException if the query times out or some other error occurs |
586 | 584 | * @throws ConstraintParameterException if the $regex is invalid |
587 | 585 | */ |
588 | - public function matchesRegularExpression( $text, $regex ) { |
|
586 | + public function matchesRegularExpression($text, $regex) { |
|
589 | 587 | // caching wrapper around matchesRegularExpressionWithSparql |
590 | 588 | |
591 | - $textHash = hash( 'sha256', $text ); |
|
589 | + $textHash = hash('sha256', $text); |
|
592 | 590 | $cacheKey = $this->cache->makeKey( |
593 | 591 | 'WikibaseQualityConstraints', // extension |
594 | 592 | 'regex', // action |
595 | 593 | 'WDQS-Java', // regex flavor |
596 | - hash( 'sha256', $regex ) |
|
594 | + hash('sha256', $regex) |
|
597 | 595 | ); |
598 | 596 | |
599 | 597 | $cacheMapArray = $this->cache->getWithSetCallback( |
600 | 598 | $cacheKey, |
601 | 599 | WANObjectCache::TTL_DAY, |
602 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
600 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
603 | 601 | // Initialize the cache map if not set |
604 | - if ( $cacheMapArray === false ) { |
|
602 | + if ($cacheMapArray === false) { |
|
605 | 603 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
606 | - $this->dataFactory->increment( $key ); |
|
604 | + $this->dataFactory->increment($key); |
|
607 | 605 | return []; |
608 | 606 | } |
609 | 607 | |
610 | 608 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
611 | - $this->dataFactory->increment( $key ); |
|
612 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
613 | - if ( $cacheMap->has( $textHash ) ) { |
|
609 | + $this->dataFactory->increment($key); |
|
610 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
611 | + if ($cacheMap->has($textHash)) { |
|
614 | 612 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
615 | - $this->dataFactory->increment( $key ); |
|
616 | - $cacheMap->get( $textHash ); // ping cache |
|
613 | + $this->dataFactory->increment($key); |
|
614 | + $cacheMap->get($textHash); // ping cache |
|
617 | 615 | } else { |
618 | 616 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
619 | - $this->dataFactory->increment( $key ); |
|
617 | + $this->dataFactory->increment($key); |
|
620 | 618 | try { |
621 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
622 | - } catch ( ConstraintParameterException $e ) { |
|
623 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
624 | - } catch ( SparqlHelperException $e ) { |
|
619 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
620 | + } catch (ConstraintParameterException $e) { |
|
621 | + $matches = $this->serializeConstraintParameterException($e); |
|
622 | + } catch (SparqlHelperException $e) { |
|
625 | 623 | // don’t cache this |
626 | 624 | return $cacheMap->toArray(); |
627 | 625 | } |
@@ -645,42 +643,42 @@ discard block |
||
645 | 643 | ] |
646 | 644 | ); |
647 | 645 | |
648 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
646 | + if (isset($cacheMapArray[$textHash])) { |
|
649 | 647 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
650 | - $this->dataFactory->increment( $key ); |
|
648 | + $this->dataFactory->increment($key); |
|
651 | 649 | $matches = $cacheMapArray[$textHash]; |
652 | - if ( is_bool( $matches ) ) { |
|
650 | + if (is_bool($matches)) { |
|
653 | 651 | return $matches; |
654 | - } elseif ( is_array( $matches ) && |
|
655 | - $matches['type'] == ConstraintParameterException::class ) { |
|
656 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
652 | + } elseif (is_array($matches) && |
|
653 | + $matches['type'] == ConstraintParameterException::class) { |
|
654 | + throw $this->deserializeConstraintParameterException($matches); |
|
657 | 655 | } else { |
658 | 656 | throw new UnexpectedValueException( |
659 | - 'Value of unknown type in object cache (' . |
|
660 | - 'cache key: ' . $cacheKey . ', ' . |
|
661 | - 'cache map key: ' . $textHash . ', ' . |
|
662 | - 'value type: ' . get_debug_type( $matches ) . ')' |
|
657 | + 'Value of unknown type in object cache ('. |
|
658 | + 'cache key: '.$cacheKey.', '. |
|
659 | + 'cache map key: '.$textHash.', '. |
|
660 | + 'value type: '.get_debug_type($matches).')' |
|
663 | 661 | ); |
664 | 662 | } |
665 | 663 | } else { |
666 | 664 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
667 | - $this->dataFactory->increment( $key ); |
|
668 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
665 | + $this->dataFactory->increment($key); |
|
666 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
669 | 667 | } |
670 | 668 | } |
671 | 669 | |
672 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
670 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
673 | 671 | return [ |
674 | 672 | 'type' => ConstraintParameterException::class, |
675 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
673 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
676 | 674 | ]; |
677 | 675 | } |
678 | 676 | |
679 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
677 | + private function deserializeConstraintParameterException(array $serialization) { |
|
680 | 678 | $message = $this->violationMessageDeserializer->deserialize( |
681 | 679 | $serialization['violationMessage'] |
682 | 680 | ); |
683 | - return new ConstraintParameterException( $message ); |
|
681 | + return new ConstraintParameterException($message); |
|
684 | 682 | } |
685 | 683 | |
686 | 684 | /** |
@@ -694,25 +692,25 @@ discard block |
||
694 | 692 | * @throws SparqlHelperException if the query times out or some other error occurs |
695 | 693 | * @throws ConstraintParameterException if the $regex is invalid |
696 | 694 | */ |
697 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
698 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
699 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
695 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
696 | + $textStringLiteral = $this->stringLiteral($text); |
|
697 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
700 | 698 | |
701 | 699 | $query = <<<EOF |
702 | 700 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
703 | 701 | EOF; |
704 | 702 | |
705 | - $result = $this->runQuery( $query, $this->primaryEndpoint, false ); |
|
703 | + $result = $this->runQuery($query, $this->primaryEndpoint, false); |
|
706 | 704 | |
707 | 705 | $vars = $result->getArray()['results']['bindings'][0]; |
708 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
706 | + if (array_key_exists('matches', $vars)) { |
|
709 | 707 | // true or false ⇒ regex okay, text matches or not |
710 | 708 | return $vars['matches']['value'] === 'true'; |
711 | 709 | } else { |
712 | 710 | // empty result: regex broken |
713 | 711 | throw new ConstraintParameterException( |
714 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
715 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
712 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
713 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
716 | 714 | ); |
717 | 715 | } |
718 | 716 | } |
@@ -724,14 +722,14 @@ discard block |
||
724 | 722 | * |
725 | 723 | * @return boolean |
726 | 724 | */ |
727 | - public function isTimeout( $responseContent ) { |
|
728 | - $timeoutRegex = implode( '|', array_map( |
|
729 | - static function ( $fqn ) { |
|
730 | - return preg_quote( $fqn, '/' ); |
|
725 | + public function isTimeout($responseContent) { |
|
726 | + $timeoutRegex = implode('|', array_map( |
|
727 | + static function($fqn) { |
|
728 | + return preg_quote($fqn, '/'); |
|
731 | 729 | }, |
732 | 730 | $this->timeoutExceptionClasses |
733 | - ) ); |
|
734 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
731 | + )); |
|
732 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
735 | 733 | } |
736 | 734 | |
737 | 735 | /** |
@@ -743,17 +741,17 @@ discard block |
||
743 | 741 | * @return int|boolean the max-age (in seconds) |
744 | 742 | * or a plain boolean if no max-age can be determined |
745 | 743 | */ |
746 | - public function getCacheMaxAge( $responseHeaders ) { |
|
744 | + public function getCacheMaxAge($responseHeaders) { |
|
747 | 745 | if ( |
748 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
749 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
746 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
747 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
750 | 748 | ) { |
751 | 749 | $maxage = []; |
752 | 750 | if ( |
753 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
754 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
751 | + array_key_exists('cache-control', $responseHeaders) && |
|
752 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
755 | 753 | ) { |
756 | - return intval( $maxage[1] ); |
|
754 | + return intval($maxage[1]); |
|
757 | 755 | } else { |
758 | 756 | return true; |
759 | 757 | } |
@@ -774,34 +772,34 @@ discard block |
||
774 | 772 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
775 | 773 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
776 | 774 | */ |
777 | - public function getThrottling( MWHttpRequest $request ) { |
|
778 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
779 | - if ( $retryAfterValue === null ) { |
|
775 | + public function getThrottling(MWHttpRequest $request) { |
|
776 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
777 | + if ($retryAfterValue === null) { |
|
780 | 778 | return self::NO_RETRY_AFTER; |
781 | 779 | } |
782 | 780 | |
783 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
784 | - if ( $trimmedRetryAfterValue === '' ) { |
|
781 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
782 | + if ($trimmedRetryAfterValue === '') { |
|
785 | 783 | return self::EMPTY_RETRY_AFTER; |
786 | 784 | } |
787 | 785 | |
788 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
789 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
790 | - if ( $delaySeconds >= 0 ) { |
|
791 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
786 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
787 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
788 | + if ($delaySeconds >= 0) { |
|
789 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
792 | 790 | } |
793 | 791 | } else { |
794 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
795 | - if ( $return !== false ) { |
|
796 | - return new ConvertibleTimestamp( $return ); |
|
792 | + $return = strtotime($trimmedRetryAfterValue); |
|
793 | + if ($return !== false) { |
|
794 | + return new ConvertibleTimestamp($return); |
|
797 | 795 | } |
798 | 796 | } |
799 | 797 | return self::INVALID_RETRY_AFTER; |
800 | 798 | } |
801 | 799 | |
802 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
800 | + private function getTimestampInFuture(DateInterval $delta) { |
|
803 | 801 | $now = new ConvertibleTimestamp(); |
804 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
802 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
805 | 803 | } |
806 | 804 | |
807 | 805 | /** |
@@ -816,64 +814,63 @@ discard block |
||
816 | 814 | * |
817 | 815 | * @throws SparqlHelperException if the query times out or some other error occurs |
818 | 816 | */ |
819 | - protected function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ) { |
|
820 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
821 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
817 | + protected function runQuery(string $query, string $endpoint, bool $needsPrefixes = true) { |
|
818 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
819 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
822 | 820 | throw new TooManySparqlRequestsException(); |
823 | 821 | } |
824 | 822 | |
825 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
823 | + if ($this->sparqlHasWikibaseSupport) { |
|
826 | 824 | $needsPrefixes = false; |
827 | 825 | } |
828 | 826 | |
829 | - if ( $needsPrefixes ) { |
|
830 | - $query = $this->prefixes . $query; |
|
827 | + if ($needsPrefixes) { |
|
828 | + $query = $this->prefixes.$query; |
|
831 | 829 | } |
832 | - $query = "#wbqc\n" . $query; |
|
830 | + $query = "#wbqc\n".$query; |
|
833 | 831 | |
834 | - $url = $endpoint . '?' . http_build_query( |
|
832 | + $url = $endpoint.'?'.http_build_query( |
|
835 | 833 | [ |
836 | 834 | 'query' => $query, |
837 | 835 | 'format' => 'json', |
838 | 836 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
839 | 837 | ], |
840 | - '', ini_get( 'arg_separator.output' ), |
|
838 | + '', ini_get('arg_separator.output'), |
|
841 | 839 | // encode spaces with %20, not + |
842 | 840 | PHP_QUERY_RFC3986 |
843 | 841 | ); |
844 | 842 | |
845 | 843 | $options = [ |
846 | 844 | 'method' => 'GET', |
847 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
845 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
848 | 846 | 'connectTimeout' => 'default', |
849 | 847 | 'userAgent' => $this->defaultUserAgent, |
850 | 848 | ]; |
851 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
852 | - $startTime = microtime( true ); |
|
849 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
850 | + $startTime = microtime(true); |
|
853 | 851 | $requestStatus = $request->execute(); |
854 | - $endTime = microtime( true ); |
|
852 | + $endTime = microtime(true); |
|
855 | 853 | $this->dataFactory->timing( |
856 | 854 | 'wikibase.quality.constraints.sparql.timing', |
857 | - ( $endTime - $startTime ) * 1000 |
|
855 | + ($endTime - $startTime) * 1000 |
|
858 | 856 | ); |
859 | 857 | |
860 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
858 | + $this->guardAgainstTooManyRequestsError($request); |
|
861 | 859 | |
862 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
863 | - if ( $maxAge ) { |
|
864 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
860 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
861 | + if ($maxAge) { |
|
862 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
865 | 863 | } |
866 | 864 | |
867 | - if ( $requestStatus->isOK() ) { |
|
865 | + if ($requestStatus->isOK()) { |
|
868 | 866 | $json = $request->getContent(); |
869 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
870 | - if ( $jsonStatus->isOK() ) { |
|
867 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
868 | + if ($jsonStatus->isOK()) { |
|
871 | 869 | return new CachedQueryResults( |
872 | 870 | $jsonStatus->getValue(), |
873 | 871 | Metadata::ofCachingMetadata( |
874 | 872 | $maxAge ? |
875 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
876 | - CachingMetadata::fresh() |
|
873 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
877 | 874 | ) |
878 | 875 | ); |
879 | 876 | } else { |
@@ -890,9 +887,9 @@ discard block |
||
890 | 887 | // fall through to general error handling |
891 | 888 | } |
892 | 889 | |
893 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
890 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
894 | 891 | |
895 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
892 | + if ($this->isTimeout($request->getContent())) { |
|
896 | 893 | $this->dataFactory->increment( |
897 | 894 | 'wikibase.quality.constraints.sparql.error.timeout' |
898 | 895 | ); |
@@ -907,29 +904,29 @@ discard block |
||
907 | 904 | * @param MWHttpRequest $request |
908 | 905 | * @throws TooManySparqlRequestsException |
909 | 906 | */ |
910 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
911 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
907 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
908 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
912 | 909 | return; |
913 | 910 | } |
914 | 911 | |
915 | 912 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
916 | 913 | |
917 | - if ( $fallbackBlockDuration < 0 ) { |
|
918 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
919 | - $fallbackBlockDuration ); |
|
914 | + if ($fallbackBlockDuration < 0) { |
|
915 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
916 | + $fallbackBlockDuration); |
|
920 | 917 | } |
921 | 918 | |
922 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
923 | - $throttlingUntil = $this->getThrottling( $request ); |
|
924 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
925 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
919 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
920 | + $throttlingUntil = $this->getThrottling($request); |
|
921 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
922 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
926 | 923 | $this->throttlingLock->lock( |
927 | 924 | self::EXPIRY_LOCK_ID, |
928 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
925 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
929 | 926 | ); |
930 | 927 | } else { |
931 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
932 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
928 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
929 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
933 | 930 | } |
934 | 931 | throw new TooManySparqlRequestsException(); |
935 | 932 | } |