Completed
Push — master ( 64b8b5...1ef719 )
by
unknown
06:56
created
src/ConstraintCheck/Helper/SparqlHelper.php 1 patch
Spacing   +163 added lines, -165 removed lines patch added patch discarded remove patch
@@ -161,18 +161,18 @@  discard block
 block discarded – undo
161 161
 		$this->loggingHelper = $loggingHelper;
162 162
 		$this->defaultUserAgent = $defaultUserAgent;
163 163
 		$this->requestFactory = $requestFactory;
164
-		$this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY );
164
+		$this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY);
165 165
 		$this->prefixes = <<<EOT
166
-PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}>
167
-PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}>
168
-PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}>
169
-PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>
170
-PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}>
171
-PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}>
172
-PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}>
173
-PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}>
174
-PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}>
175
-PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}>
166
+PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}>
167
+PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}>
168
+PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}>
169
+PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>
170
+PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}>
171
+PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}>
172
+PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}>
173
+PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}>
174
+PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}>
175
+PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}>
176 176
 PREFIX wikibase: <http://wikiba.se/ontology#>
177 177
 PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#>
178 178
 EOT;
@@ -187,21 +187,21 @@  discard block
 block discarded – undo
187 187
 	 * @return CachedBool
188 188
 	 * @throws SparqlHelperException if the query times out or some other error occurs
189 189
 	 */
190
-	public function hasType( $id, array $classes, $withInstance ) {
191
-		$instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
192
-		$subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
190
+	public function hasType($id, array $classes, $withInstance) {
191
+		$instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId');
192
+		$subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId');
193 193
 
194
-		$path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*";
194
+		$path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*";
195 195
 
196 196
 		$metadatas = [];
197 197
 
198
-		foreach ( array_chunk( $classes, 20 ) as $classesChunk ) {
199
-			$classesValues = implode( ' ', array_map(
200
-				function( $class ) {
201
-					return 'wd:' . $class;
198
+		foreach (array_chunk($classes, 20) as $classesChunk) {
199
+			$classesValues = implode(' ', array_map(
200
+				function($class) {
201
+					return 'wd:'.$class;
202 202
 				},
203 203
 				$classesChunk
204
-			) );
204
+			));
205 205
 
206 206
 			$query = <<<EOF
207 207
 ASK {
@@ -212,19 +212,19 @@  discard block
 block discarded – undo
212 212
 EOF;
213 213
 			// TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually
214 214
 
215
-			$result = $this->runQuery( $query );
215
+			$result = $this->runQuery($query);
216 216
 			$metadatas[] = $result->getMetadata();
217
-			if ( $result->getArray()['boolean'] ) {
217
+			if ($result->getArray()['boolean']) {
218 218
 				return new CachedBool(
219 219
 					true,
220
-					Metadata::merge( $metadatas )
220
+					Metadata::merge($metadatas)
221 221
 				);
222 222
 			}
223 223
 		}
224 224
 
225 225
 		return new CachedBool(
226 226
 			false,
227
-			Metadata::merge( $metadatas )
227
+			Metadata::merge($metadatas)
228 228
 		);
229 229
 	}
230 230
 
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 		$ignoreDeprecatedStatements
241 241
 	) {
242 242
 		$pid = $statement->getPropertyId()->serialize();
243
-		$guid = str_replace( '$', '-', $statement->getGuid() );
243
+		$guid = str_replace('$', '-', $statement->getGuid());
244 244
 
245 245
 		$deprecatedFilter = '';
246
-		if ( $ignoreDeprecatedStatements ) {
246
+		if ($ignoreDeprecatedStatements) {
247 247
 			$deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }';
248 248
 			$deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }';
249 249
 		}
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
 LIMIT 10
264 264
 EOF;
265 265
 
266
-		$result = $this->runQuery( $query );
266
+		$result = $this->runQuery($query);
267 267
 
268
-		return $this->getOtherEntities( $result );
268
+		return $this->getOtherEntities($result);
269 269
 	}
270 270
 
271 271
 	/**
@@ -290,16 +290,15 @@  discard block
 block discarded – undo
290 290
 		$dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty(
291 291
 			$snak->getPropertyId()
292 292
 		);
293
-		list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue );
294
-		if ( $isFullValue ) {
293
+		list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue);
294
+		if ($isFullValue) {
295 295
 			$prefix .= 'v';
296 296
 		}
297 297
 		$path = $type === Context::TYPE_QUALIFIER ?
298
-			"$prefix:$pid" :
299
-			"prov:wasDerivedFrom/$prefix:$pid";
298
+			"$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid";
300 299
 
301 300
 		$deprecatedFilter = '';
302
-		if ( $ignoreDeprecatedStatements ) {
301
+		if ($ignoreDeprecatedStatements) {
303 302
 			$deprecatedFilter = <<< EOF
304 303
   MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }
305 304
   MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }
@@ -320,9 +319,9 @@  discard block
 block discarded – undo
320 319
 LIMIT 10
321 320
 EOF;
322 321
 
323
-		$result = $this->runQuery( $query );
322
+		$result = $this->runQuery($query);
324 323
 
325
-		return $this->getOtherEntities( $result );
324
+		return $this->getOtherEntities($result);
326 325
 	}
327 326
 
328 327
 	/**
@@ -332,8 +331,8 @@  discard block
 block discarded – undo
332 331
 	 *
333 332
 	 * @return string
334 333
 	 */
335
-	private function stringLiteral( $text ) {
336
-		return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"';
334
+	private function stringLiteral($text) {
335
+		return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"';
337 336
 	}
338 337
 
339 338
 	/**
@@ -343,17 +342,17 @@  discard block
 block discarded – undo
343 342
 	 *
344 343
 	 * @return CachedEntityIds
345 344
 	 */
346
-	private function getOtherEntities( CachedQueryResults $results ) {
347
-		return new CachedEntityIds( array_map(
348
-			function ( $resultBindings ) {
345
+	private function getOtherEntities(CachedQueryResults $results) {
346
+		return new CachedEntityIds(array_map(
347
+			function($resultBindings) {
349 348
 				$entityIRI = $resultBindings['otherEntity']['value'];
350
-				$entityPrefixLength = strlen( $this->entityPrefix );
351
-				if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) {
349
+				$entityPrefixLength = strlen($this->entityPrefix);
350
+				if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) {
352 351
 					try {
353 352
 						return $this->entityIdParser->parse(
354
-							substr( $entityIRI, $entityPrefixLength )
353
+							substr($entityIRI, $entityPrefixLength)
355 354
 						);
356
-					} catch ( EntityIdParsingException $e ) {
355
+					} catch (EntityIdParsingException $e) {
357 356
 						// fall through
358 357
 					}
359 358
 				}
@@ -361,7 +360,7 @@  discard block
 block discarded – undo
361 360
 				return null;
362 361
 			},
363 362
 			$results->getArray()['results']['bindings']
364
-		), $results->getMetadata() );
363
+		), $results->getMetadata());
365 364
 	}
366 365
 
367 366
 	// @codingStandardsIgnoreStart cyclomatic complexity of this function is too high
@@ -374,47 +373,47 @@  discard block
 block discarded – undo
374 373
 	 * @return array the literal or IRI as a string in SPARQL syntax,
375 374
 	 * and a boolean indicating whether it refers to a full value node or not
376 375
 	 */
377
-	private function getRdfLiteral( $dataType, DataValue $dataValue ) {
378
-		switch ( $dataType ) {
376
+	private function getRdfLiteral($dataType, DataValue $dataValue) {
377
+		switch ($dataType) {
379 378
 			case 'string':
380 379
 			case 'external-id':
381
-				return [ $this->stringLiteral( $dataValue->getValue() ), false ];
380
+				return [$this->stringLiteral($dataValue->getValue()), false];
382 381
 			case 'commonsMedia':
383
-				$url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() );
384
-				return [ '<' . $url . '>', false ];
382
+				$url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue());
383
+				return ['<'.$url.'>', false];
385 384
 			case 'geo-shape':
386
-				$url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() );
387
-				return [ '<' . $url . '>', false ];
385
+				$url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue());
386
+				return ['<'.$url.'>', false];
388 387
 			case 'tabular-data':
389
-				$url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() );
390
-				return [ '<' . $url . '>', false ];
388
+				$url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue());
389
+				return ['<'.$url.'>', false];
391 390
 			case 'url':
392 391
 				$url = $dataValue->getValue();
393
-				if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) {
392
+				if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) {
394 393
 					// not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF)
395 394
 					// such an URL should never reach us, so just throw
396
-					throw new InvalidArgumentException( 'invalid URL: ' . $url );
395
+					throw new InvalidArgumentException('invalid URL: '.$url);
397 396
 				}
398
-				return [ '<' . $url . '>', false ];
397
+				return ['<'.$url.'>', false];
399 398
 			case 'wikibase-item':
400 399
 			case 'wikibase-property':
401 400
 				/** @var EntityIdValue $dataValue */
402
-				return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ];
401
+				return ['wd:'.$dataValue->getEntityId()->getSerialization(), false];
403 402
 			case 'monolingualtext':
404 403
 				/** @var MonolingualTextValue $dataValue */
405 404
 				$lang = $dataValue->getLanguageCode();
406
-				if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) {
405
+				if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) {
407 406
 					// not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG)
408 407
 					// such a language tag should never reach us, so just throw
409
-					throw new InvalidArgumentException( 'invalid language tag: ' . $lang );
408
+					throw new InvalidArgumentException('invalid language tag: '.$lang);
410 409
 				}
411
-				return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ];
410
+				return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false];
412 411
 			case 'globe-coordinate':
413 412
 			case 'quantity':
414 413
 			case 'time':
415
-				return [ 'wdv:' . $dataValue->getHash(), true ];
414
+				return ['wdv:'.$dataValue->getHash(), true];
416 415
 			default:
417
-				throw new InvalidArgumentException( 'unknown data type: ' . $dataType );
416
+				throw new InvalidArgumentException('unknown data type: '.$dataType);
418 417
 		}
419 418
 	}
420 419
 	// @codingStandardsIgnoreEnd
@@ -427,44 +426,44 @@  discard block
 block discarded – undo
427 426
 	 * @throws SparqlHelperException if the query times out or some other error occurs
428 427
 	 * @throws ConstraintParameterException if the $regex is invalid
429 428
 	 */
430
-	public function matchesRegularExpression( $text, $regex ) {
429
+	public function matchesRegularExpression($text, $regex) {
431 430
 		// caching wrapper around matchesRegularExpressionWithSparql
432 431
 
433
-		$textHash = hash( 'sha256', $text );
432
+		$textHash = hash('sha256', $text);
434 433
 		$cacheKey = $this->cache->makeKey(
435 434
 			'WikibaseQualityConstraints', // extension
436 435
 			'regex', // action
437 436
 			'WDQS-Java', // regex flavor
438
-			hash( 'sha256', $regex )
437
+			hash('sha256', $regex)
439 438
 		);
440
-		$cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' );
439
+		$cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize');
441 440
 
442 441
 		$cacheMapArray = $this->cache->getWithSetCallback(
443 442
 			$cacheKey,
444 443
 			WANObjectCache::TTL_DAY,
445
-			function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) {
444
+			function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) {
446 445
 				// Initialize the cache map if not set
447
-				if ( $cacheMapArray === false ) {
446
+				if ($cacheMapArray === false) {
448 447
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.init';
449
-					$this->dataFactory->increment( $key );
448
+					$this->dataFactory->increment($key);
450 449
 					return [];
451 450
 				}
452 451
 
453 452
 				$key = 'wikibase.quality.constraints.regex.cache.refresh';
454
-				$this->dataFactory->increment( $key );
455
-				$cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize );
456
-				if ( $cacheMap->has( $textHash ) ) {
453
+				$this->dataFactory->increment($key);
454
+				$cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize);
455
+				if ($cacheMap->has($textHash)) {
457 456
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.hit';
458
-					$this->dataFactory->increment( $key );
459
-					$cacheMap->get( $textHash ); // ping cache
457
+					$this->dataFactory->increment($key);
458
+					$cacheMap->get($textHash); // ping cache
460 459
 				} else {
461 460
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.miss';
462
-					$this->dataFactory->increment( $key );
461
+					$this->dataFactory->increment($key);
463 462
 					try {
464
-						$matches = $this->matchesRegularExpressionWithSparql( $text, $regex );
465
-					} catch ( ConstraintParameterException $e ) {
466
-						$matches = $this->serializeConstraintParameterException( $e );
467
-					} catch ( SparqlHelperException $e ) {
463
+						$matches = $this->matchesRegularExpressionWithSparql($text, $regex);
464
+					} catch (ConstraintParameterException $e) {
465
+						$matches = $this->serializeConstraintParameterException($e);
466
+					} catch (SparqlHelperException $e) {
468 467
 						// don’t cache this
469 468
 						return $cacheMap->toArray();
470 469
 					}
@@ -488,42 +487,42 @@  discard block
 block discarded – undo
488 487
 			]
489 488
 		);
490 489
 
491
-		if ( isset( $cacheMapArray[$textHash] ) ) {
490
+		if (isset($cacheMapArray[$textHash])) {
492 491
 			$key = 'wikibase.quality.constraints.regex.cache.hit';
493
-			$this->dataFactory->increment( $key );
492
+			$this->dataFactory->increment($key);
494 493
 			$matches = $cacheMapArray[$textHash];
495
-			if ( is_bool( $matches ) ) {
494
+			if (is_bool($matches)) {
496 495
 				return $matches;
497
-			} elseif ( is_array( $matches ) &&
498
-				$matches['type'] == ConstraintParameterException::class ) {
499
-				throw $this->deserializeConstraintParameterException( $matches );
496
+			} elseif (is_array($matches) &&
497
+				$matches['type'] == ConstraintParameterException::class) {
498
+				throw $this->deserializeConstraintParameterException($matches);
500 499
 			} else {
501 500
 				throw new MWException(
502
-					'Value of unknown type in object cache (' .
503
-					'cache key: ' . $cacheKey . ', ' .
504
-					'cache map key: ' . $textHash . ', ' .
505
-					'value type: ' . gettype( $matches ) . ')'
501
+					'Value of unknown type in object cache ('.
502
+					'cache key: '.$cacheKey.', '.
503
+					'cache map key: '.$textHash.', '.
504
+					'value type: '.gettype($matches).')'
506 505
 				);
507 506
 			}
508 507
 		} else {
509 508
 			$key = 'wikibase.quality.constraints.regex.cache.miss';
510
-			$this->dataFactory->increment( $key );
511
-			return $this->matchesRegularExpressionWithSparql( $text, $regex );
509
+			$this->dataFactory->increment($key);
510
+			return $this->matchesRegularExpressionWithSparql($text, $regex);
512 511
 		}
513 512
 	}
514 513
 
515
-	private function serializeConstraintParameterException( ConstraintParameterException $cpe ) {
514
+	private function serializeConstraintParameterException(ConstraintParameterException $cpe) {
516 515
 		return [
517 516
 			'type' => ConstraintParameterException::class,
518
-			'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ),
517
+			'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()),
519 518
 		];
520 519
 	}
521 520
 
522
-	private function deserializeConstraintParameterException( array $serialization ) {
521
+	private function deserializeConstraintParameterException(array $serialization) {
523 522
 		$message = $this->violationMessageDeserializer->deserialize(
524 523
 			$serialization['violationMessage']
525 524
 		);
526
-		return new ConstraintParameterException( $message );
525
+		return new ConstraintParameterException($message);
527 526
 	}
528 527
 
529 528
 	/**
@@ -537,25 +536,25 @@  discard block
 block discarded – undo
537 536
 	 * @throws SparqlHelperException if the query times out or some other error occurs
538 537
 	 * @throws ConstraintParameterException if the $regex is invalid
539 538
 	 */
540
-	public function matchesRegularExpressionWithSparql( $text, $regex ) {
541
-		$textStringLiteral = $this->stringLiteral( $text );
542
-		$regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' );
539
+	public function matchesRegularExpressionWithSparql($text, $regex) {
540
+		$textStringLiteral = $this->stringLiteral($text);
541
+		$regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$');
543 542
 
544 543
 		$query = <<<EOF
545 544
 SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {}
546 545
 EOF;
547 546
 
548
-		$result = $this->runQuery( $query, false );
547
+		$result = $this->runQuery($query, false);
549 548
 
550 549
 		$vars = $result->getArray()['results']['bindings'][0];
551
-		if ( array_key_exists( 'matches', $vars ) ) {
550
+		if (array_key_exists('matches', $vars)) {
552 551
 			// true or false ⇒ regex okay, text matches or not
553 552
 			return $vars['matches']['value'] === 'true';
554 553
 		} else {
555 554
 			// empty result: regex broken
556 555
 			throw new ConstraintParameterException(
557
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
558
-					->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE )
556
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
557
+					->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE)
559 558
 			);
560 559
 		}
561 560
 	}
@@ -567,14 +566,14 @@  discard block
 block discarded – undo
567 566
 	 *
568 567
 	 * @return boolean
569 568
 	 */
570
-	public function isTimeout( $responseContent ) {
571
-		$timeoutRegex = implode( '|', array_map(
572
-			function ( $fqn ) {
573
-				return preg_quote( $fqn, '/' );
569
+	public function isTimeout($responseContent) {
570
+		$timeoutRegex = implode('|', array_map(
571
+			function($fqn) {
572
+				return preg_quote($fqn, '/');
574 573
 			},
575
-			$this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' )
576
-		) );
577
-		return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent );
574
+			$this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses')
575
+		));
576
+		return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent);
578 577
 	}
579 578
 
580 579
 	/**
@@ -586,17 +585,17 @@  discard block
 block discarded – undo
586 585
 	 * @return int|boolean the max-age (in seconds)
587 586
 	 * or a plain boolean if no max-age can be determined
588 587
 	 */
589
-	public function getCacheMaxAge( $responseHeaders ) {
588
+	public function getCacheMaxAge($responseHeaders) {
590 589
 		if (
591
-			array_key_exists( 'x-cache-status', $responseHeaders ) &&
592
-			preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] )
590
+			array_key_exists('x-cache-status', $responseHeaders) &&
591
+			preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0])
593 592
 		) {
594 593
 			$maxage = [];
595 594
 			if (
596
-				array_key_exists( 'cache-control', $responseHeaders ) &&
597
-				preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage )
595
+				array_key_exists('cache-control', $responseHeaders) &&
596
+				preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage)
598 597
 			) {
599
-				return intval( $maxage[1] );
598
+				return intval($maxage[1]);
600 599
 			} else {
601 600
 				return true;
602 601
 			}
@@ -618,33 +617,33 @@  discard block
 block discarded – undo
618 617
 	 * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format
619 618
 	 *
620 619
 	 */
621
-	public function getThrottling( array $responseHeaders ) {
622
-		if ( !array_key_exists( 'Retry-After', $responseHeaders ) ) {
620
+	public function getThrottling(array $responseHeaders) {
621
+		if (!array_key_exists('Retry-After', $responseHeaders)) {
623 622
 			return self::NO_RETRY_AFTER;
624 623
 		}
625 624
 
626
-		$trimmedRetryAfterValue = trim( $responseHeaders[ 'Retry-After' ] );
627
-		if ( empty( $trimmedRetryAfterValue ) ) {
625
+		$trimmedRetryAfterValue = trim($responseHeaders['Retry-After']);
626
+		if (empty($trimmedRetryAfterValue)) {
628 627
 			return self::EMPTY_RETRY_AFTER;
629 628
 		}
630 629
 
631
-		if ( is_numeric( $trimmedRetryAfterValue ) ) {
632
-			$delaySeconds = (int)$trimmedRetryAfterValue;
633
-			if ( $delaySeconds >= 0 ) {
634
-				return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) );
630
+		if (is_numeric($trimmedRetryAfterValue)) {
631
+			$delaySeconds = (int) $trimmedRetryAfterValue;
632
+			if ($delaySeconds >= 0) {
633
+				return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S'));
635 634
 			}
636 635
 		} else {
637
-			$return = strtotime( $responseHeaders[ 'Retry-After' ] );
638
-			if ( !empty( $return ) ) {
639
-				return new ConvertibleTimestamp( $return );
636
+			$return = strtotime($responseHeaders['Retry-After']);
637
+			if (!empty($return)) {
638
+				return new ConvertibleTimestamp($return);
640 639
 			}
641 640
 		}
642 641
 		return self::INVALID_RETRY_AFTER;
643 642
 	}
644 643
 
645
-	private function getTimestampInFuture( DateInterval $delta ) {
644
+	private function getTimestampInFuture(DateInterval $delta) {
646 645
 		$now = new ConvertibleTimestamp();
647
-		return new ConvertibleTimestamp( $now->timestamp->add( $delta ) );
646
+		return new ConvertibleTimestamp($now->timestamp->add($delta));
648 647
 	}
649 648
 
650 649
 	/**
@@ -658,93 +657,92 @@  discard block
 block discarded – undo
658 657
 	 *
659 658
 	 * @throws SparqlHelperException if the query times out or some other error occurs
660 659
 	 */
661
-	public function runQuery( $query, $needsPrefixes = true ) {
660
+	public function runQuery($query, $needsPrefixes = true) {
662 661
 
663
-		if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) {
664
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
662
+		if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) {
663
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
665 664
 			throw new TooManySparqlRequestsException();
666 665
 		}
667 666
 
668
-		$endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' );
669
-		$maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' );
670
-		$fallbackBlockDuration = (int)$this->config->get( 'WBQualityConstraintsSparqlThrottlingFallbackDuration' );
667
+		$endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint');
668
+		$maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis');
669
+		$fallbackBlockDuration = (int) $this->config->get('WBQualityConstraintsSparqlThrottlingFallbackDuration');
671 670
 
672
-		if ( $fallbackBlockDuration < 0 ) {
673
-			throw new InvalidArgumentException( 'Fallback duration must be positive int but is: '.
674
-				$fallbackBlockDuration );
671
+		if ($fallbackBlockDuration < 0) {
672
+			throw new InvalidArgumentException('Fallback duration must be positive int but is: '.
673
+				$fallbackBlockDuration);
675 674
 		}
676 675
 
677
-		if ( $needsPrefixes ) {
678
-			$query = $this->prefixes . $query;
676
+		if ($needsPrefixes) {
677
+			$query = $this->prefixes.$query;
679 678
 		}
680
-		$query = "#wbqc\n" . $query;
679
+		$query = "#wbqc\n".$query;
681 680
 
682
-		$url = $endpoint . '?' . http_build_query(
681
+		$url = $endpoint.'?'.http_build_query(
683 682
 			[
684 683
 				'query' => $query,
685 684
 				'format' => 'json',
686 685
 				'maxQueryTimeMillis' => $maxQueryTimeMillis,
687 686
 			],
688
-			null, ini_get( 'arg_separator.output' ),
687
+			null, ini_get('arg_separator.output'),
689 688
 			// encode spaces with %20, not +
690 689
 			PHP_QUERY_RFC3986
691 690
 		);
692 691
 
693 692
 		$options = [
694 693
 			'method' => 'GET',
695
-			'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ),
694
+			'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000),
696 695
 			'connectTimeout' => 'default',
697 696
 			'userAgent' => $this->defaultUserAgent,
698 697
 		];
699
-		$request = $this->requestFactory->create( $url, $options );
700
-		$startTime = microtime( true );
698
+		$request = $this->requestFactory->create($url, $options);
699
+		$startTime = microtime(true);
701 700
 		$status = $request->execute();
702
-		$endTime = microtime( true );
701
+		$endTime = microtime(true);
703 702
 		$this->dataFactory->timing(
704 703
 			'wikibase.quality.constraints.sparql.timing',
705
-			( $endTime - $startTime ) * 1000
704
+			($endTime - $startTime) * 1000
706 705
 		);
707 706
 
708
-		if ( $request->getStatus() === self::HTTP_TOO_MANY_REQUESTS ) {
709
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
710
-			$throttlingUntil = $this->getThrottling( $request->getResponseHeaders() );
711
-			if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) {
712
-				$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request );
707
+		if ($request->getStatus() === self::HTTP_TOO_MANY_REQUESTS) {
708
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
709
+			$throttlingUntil = $this->getThrottling($request->getResponseHeaders());
710
+			if (!($throttlingUntil instanceof ConvertibleTimestamp)) {
711
+				$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request);
713 712
 				$this->throttlingLock->lock(
714 713
 					self::EXPIRY_LOCK_ID,
715
-					$this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) )
714
+					$this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S'))
716 715
 				);
717 716
 			} else {
718
-				$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request );
719
-				$this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil );
717
+				$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request);
718
+				$this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil);
720 719
 			}
721 720
 			throw new TooManySparqlRequestsException();
722 721
 		}
723 722
 
724
-		$maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() );
725
-		if ( $maxAge ) {
726
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' );
723
+		$maxAge = $this->getCacheMaxAge($request->getResponseHeaders());
724
+		if ($maxAge) {
725
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.cached');
727 726
 		}
728 727
 
729
-		if ( $status->isOK() ) {
728
+		if ($status->isOK()) {
730 729
 			$json = $request->getContent();
731
-			$arr = json_decode( $json, true );
730
+			$arr = json_decode($json, true);
732 731
 			return new CachedQueryResults(
733 732
 				$arr,
734 733
 				Metadata::ofCachingMetadata(
735 734
 					$maxAge ?
736
-						CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) :
737
-						CachingMetadata::fresh()
735
+						CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh()
738 736
 				)
739 737
 			);
740 738
 		} else {
741
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' );
739
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.error');
742 740
 
743 741
 			$this->dataFactory->increment(
744 742
 				"wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}"
745 743
 			);
746 744
 
747
-			if ( $this->isTimeout( $request->getContent() ) ) {
745
+			if ($this->isTimeout($request->getContent())) {
748 746
 				$this->dataFactory->increment(
749 747
 					'wikibase.quality.constraints.sparql.error.timeout'
750 748
 				);
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/TooManySparqlRequestsException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 class TooManySparqlRequestsException extends SparqlHelperException {
9 9
 
10 10
 	public function __construct() {
11
-		parent::__construct( 'The SPARQL query endpoint reports too many requests.' );
11
+		parent::__construct('The SPARQL query endpoint reports too many requests.');
12 12
 	}
13 13
 
14 14
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/LoggingHelper.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
 		$this->dataFactory = $dataFactory;
54 54
 		$this->logger = $logger;
55 55
 		$this->constraintCheckDurationLimits = [
56
-			'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ),
57
-			'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ),
56
+			'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'),
57
+			'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'),
58 58
 		];
59 59
 		$this->constraintCheckOnEntityDurationLimits = [
60
-			'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ),
61
-			'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ),
60
+			'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'),
61
+			'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'),
62 62
 		];
63 63
 	}
64 64
 
@@ -69,23 +69,23 @@  discard block
 block discarded – undo
69 69
 	 * @param float $durationSeconds
70 70
 	 * @return array [ $limitSeconds, $logLevel ]
71 71
 	 */
72
-	private function findLimit( $limits, $durationSeconds ) {
72
+	private function findLimit($limits, $durationSeconds) {
73 73
 		$limitSeconds = null;
74 74
 		$logLevel = null;
75 75
 
76
-		foreach ( $limits as $level => $limit ) {
76
+		foreach ($limits as $level => $limit) {
77 77
 			if (
78 78
 				// duration exceeds this limit
79
-				isset( $limit ) && $durationSeconds > $limit &&
79
+				isset($limit) && $durationSeconds > $limit &&
80 80
 				// this limit is longer than previous longest limit
81
-				( $limitSeconds === null || $limit > $limitSeconds )
81
+				($limitSeconds === null || $limit > $limitSeconds)
82 82
 			) {
83 83
 				$limitSeconds = $limit;
84 84
 				$logLevel = $level;
85 85
 			}
86 86
 		}
87 87
 
88
-		return [ $limitSeconds, $logLevel ];
88
+		return [$limitSeconds, $logLevel];
89 89
 	}
90 90
 
91 91
 	/**
@@ -110,31 +110,31 @@  discard block
 block discarded – undo
110 110
 		$durationSeconds,
111 111
 		$method
112 112
 	) {
113
-		$constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 );
113
+		$constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1);
114 114
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
115 115
 
116 116
 		$this->dataFactory->timing(
117
-			'wikibase.quality.constraints.check.timing.' .
118
-				$constraintTypeItemId . '-' .
117
+			'wikibase.quality.constraints.check.timing.'.
118
+				$constraintTypeItemId.'-'.
119 119
 				$constraintCheckerClassShortName,
120 120
 			$durationSeconds * 1000
121 121
 		);
122 122
 
123 123
 		// find the longest limit (and associated log level) that the duration exceeds
124
-		list( $limitSeconds, $logLevel ) = $this->findLimit(
124
+		list($limitSeconds, $logLevel) = $this->findLimit(
125 125
 			$this->constraintCheckDurationLimits,
126 126
 			$durationSeconds
127 127
 		);
128
-		if ( $limitSeconds === null ) {
128
+		if ($limitSeconds === null) {
129 129
 			return;
130 130
 		}
131
-		if ( $context->getType() !== Context::TYPE_STATEMENT ) {
131
+		if ($context->getType() !== Context::TYPE_STATEMENT) {
132 132
 			// TODO log less details but still log something
133 133
 			return;
134 134
 		}
135 135
 
136 136
 		$resultMessage = $result->getMessage();
137
-		if ( $resultMessage !== null ) {
137
+		if ($resultMessage !== null) {
138 138
 			$resultMessageKey = $resultMessage->getMessageKey();
139 139
 		} else {
140 140
 			$resultMessageKey = null;
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 
143 143
 		$this->logger->log(
144 144
 			$logLevel,
145
-			'Constraint check with {constraintCheckerClassShortName} ' .
146
-			'took longer than {limitSeconds} second(s) ' .
145
+			'Constraint check with {constraintCheckerClassShortName} '.
146
+			'took longer than {limitSeconds} second(s) '.
147 147
 			'(duration: {durationSeconds} seconds).',
148 148
 			[
149 149
 				'method' => $method,
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
 				'constraintId' => $constraint->getConstraintId(),
154 154
 				'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(),
155 155
 				'constraintTypeItemId' => $constraintTypeItemId,
156
-				'constraintParameters' => json_encode( $constraint->getConstraintParameters() ),
156
+				'constraintParameters' => json_encode($constraint->getConstraintParameters()),
157 157
 				'constraintCheckerClass' => $constraintCheckerClass,
158 158
 				'constraintCheckerClassShortName' => $constraintCheckerClassShortName,
159 159
 				'entityId' => $context->getEntity()->getId()->getSerialization(),
160 160
 				'statementGuid' => $context->getSnakStatement()->getGuid(),
161 161
 				'resultStatus' => $result->getStatus(),
162
-				'resultParameters' => json_encode( $result->getParameters() ),
162
+				'resultParameters' => json_encode($result->getParameters()),
163 163
 				'resultMessage' => $resultMessageKey,
164 164
 			]
165 165
 		);
@@ -189,18 +189,18 @@  discard block
 block discarded – undo
189 189
 		);
190 190
 
191 191
 		// find the longest limit (and associated log level) that the duration exceeds
192
-		list( $limitSeconds, $logLevel ) = $this->findLimit(
192
+		list($limitSeconds, $logLevel) = $this->findLimit(
193 193
 			$this->constraintCheckOnEntityDurationLimits,
194 194
 			$durationSeconds
195 195
 		);
196
-		if ( $limitSeconds === null ) {
196
+		if ($limitSeconds === null) {
197 197
 			return;
198 198
 		}
199 199
 
200 200
 		$this->logger->log(
201 201
 			$logLevel,
202
-			'Full constraint check on {entityId} ' .
203
-			'took longer than {limitSeconds} second(s) ' .
202
+			'Full constraint check on {entityId} '.
203
+			'took longer than {limitSeconds} second(s) '.
204 204
 			'(duration: {durationSeconds} seconds).',
205 205
 			[
206 206
 				'method' => $method,
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 *
219 219
 	 * @param EntityId $entityId
220 220
 	 */
221
-	public function logCheckConstraintsCacheHit( EntityId $entityId ) {
221
+	public function logCheckConstraintsCacheHit(EntityId $entityId) {
222 222
 		$this->dataFactory->increment(
223 223
 			'wikibase.quality.constraints.cache.entity.hit'
224 224
 		);
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @param EntityId[] $entityIds
231 231
 	 */
232
-	public function logCheckConstraintsCacheMisses( array $entityIds ) {
232
+	public function logCheckConstraintsCacheMisses(array $entityIds) {
233 233
 		$this->dataFactory->updateCount(
234 234
 			'wikibase.quality.constraints.cache.entity.miss',
235
-			count( $entityIds )
235
+			count($entityIds)
236 236
 		);
237 237
 	}
238 238
 
@@ -259,17 +259,17 @@  discard block
 block discarded – undo
259 259
 	 * @param EntityId[] $entityIds
260 260
 	 * @param int $maxRevisionIds
261 261
 	 */
262
-	public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) {
262
+	public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) {
263 263
 		$this->logger->log(
264 264
 			'warning',
265
-			'Dependency metadata for constraint check result has huge set of entity IDs ' .
266
-			'(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' .
265
+			'Dependency metadata for constraint check result has huge set of entity IDs '.
266
+			'(count '.count($entityIds).', limit '.$maxRevisionIds.'); '.
267 267
 			'caching disabled for this check result.',
268 268
 			[
269 269
 				'loggingMethod' => __METHOD__,
270 270
 				'entityIds' => json_encode(
271 271
 					array_map(
272
-						function ( EntityId $entityId ) {
272
+						function(EntityId $entityId) {
273 273
 							return $entityId->getSerialization();
274 274
 						},
275 275
 						$entityIds
@@ -280,22 +280,22 @@  discard block
 block discarded – undo
280 280
 		);
281 281
 	}
282 282
 
283
-	public function logSparqlHelperTooManyRequestsRetryAfterPresent( ConvertibleTimestamp $retryAfterTime, MWHttpRequest $request ) {
283
+	public function logSparqlHelperTooManyRequestsRetryAfterPresent(ConvertibleTimestamp $retryAfterTime, MWHttpRequest $request) {
284 284
 		$this->logger->notice(
285 285
 			'Sparql API replied with status 429 and a retry-after header. Requesting to retry after {retryAfterTime}',
286 286
 			[
287 287
 				'retryAfterTime' => $retryAfterTime,
288
-				'responseHeaders' => json_encode( $request->getResponseHeaders() ),
288
+				'responseHeaders' => json_encode($request->getResponseHeaders()),
289 289
 				'responseContent' => $request->getContent(),
290 290
 			]
291 291
 		);
292 292
 	}
293 293
 
294
-	public function logSparqlHelperTooManyRequestsRetryAfterInvalid( MWHttpRequest $request ) {
294
+	public function logSparqlHelperTooManyRequestsRetryAfterInvalid(MWHttpRequest $request) {
295 295
 		$this->logger->warning(
296 296
 			'Sparql API replied with status 429 and no valid retry-after header.',
297 297
 			[
298
-				'responseHeaders' => json_encode( $request->getResponseHeaders() ),
298
+				'responseHeaders' => json_encode($request->getResponseHeaders()),
299 299
 				'responseContent' => $request->getContent(),
300 300
 			]
301 301
 		);
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/SparqlHelperException.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@
 block discarded – undo
9 9
  */
10 10
 class SparqlHelperException extends RuntimeException {
11 11
 
12
-	public function __construct( $msg = 'The SPARQL query endpoint returned an error.' ) {
13
-		parent::__construct( $msg );
12
+	public function __construct($msg = 'The SPARQL query endpoint returned an error.') {
13
+		parent::__construct($msg);
14 14
 	}
15 15
 
16 16
 }
Please login to merge, or discard this patch.
src/ServiceWiring.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -29,28 +29,28 @@  discard block
 block discarded – undo
29 29
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer;
30 30
 
31 31
 return [
32
-	ConstraintsServices::EXPIRY_LOCK => function( MediaWikiServices $services ) {
33
-		return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) );
32
+	ConstraintsServices::EXPIRY_LOCK => function(MediaWikiServices $services) {
33
+		return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING));
34 34
 	},
35 35
 
36
-	ConstraintsServices::LOGGING_HELPER => function( MediaWikiServices $services ) {
36
+	ConstraintsServices::LOGGING_HELPER => function(MediaWikiServices $services) {
37 37
 		return new LoggingHelper(
38 38
 			$services->getStatsdDataFactory(),
39
-			LoggerFactory::getInstance( 'WikibaseQualityConstraints' ),
39
+			LoggerFactory::getInstance('WikibaseQualityConstraints'),
40 40
 			$services->getMainConfig()
41 41
 		);
42 42
 	},
43 43
 
44
-	ConstraintsServices::CONSTRAINT_REPOSITORY => function( MediaWikiServices $services ) {
44
+	ConstraintsServices::CONSTRAINT_REPOSITORY => function(MediaWikiServices $services) {
45 45
 		return new ConstraintRepository();
46 46
 	},
47 47
 
48
-	ConstraintsServices::CONSTRAINT_LOOKUP => function( MediaWikiServices $services ) {
49
-		$constraintRepository = ConstraintsServices::getConstraintRepository( $services );
50
-		return new CachingConstraintLookup( $constraintRepository );
48
+	ConstraintsServices::CONSTRAINT_LOOKUP => function(MediaWikiServices $services) {
49
+		$constraintRepository = ConstraintsServices::getConstraintRepository($services);
50
+		return new CachingConstraintLookup($constraintRepository);
51 51
 	},
52 52
 
53
-	ConstraintsServices::CHECK_RESULT_SERIALIZER => function( MediaWikiServices $services ) {
53
+	ConstraintsServices::CHECK_RESULT_SERIALIZER => function(MediaWikiServices $services) {
54 54
 		return new CheckResultSerializer(
55 55
 			new ConstraintSerializer(
56 56
 				false // constraint parameters are not exposed
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		);
62 62
 	},
63 63
 
64
-	ConstraintsServices::CHECK_RESULT_DESERIALIZER => function( MediaWikiServices $services ) {
64
+	ConstraintsServices::CHECK_RESULT_DESERIALIZER => function(MediaWikiServices $services) {
65 65
 		// TODO in the future, get EntityIdParser and DataValueFactory from $services?
66 66
 		$repo = WikibaseRepo::getDefaultInstance();
67 67
 		$entityIdParser = $repo->getEntityIdParser();
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
 		);
79 79
 	},
80 80
 
81
-	ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function( MediaWikiServices $services ) {
81
+	ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function(MediaWikiServices $services) {
82 82
 		return new ViolationMessageSerializer();
83 83
 	},
84 84
 
85
-	ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function( MediaWikiServices $services ) {
85
+	ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function(MediaWikiServices $services) {
86 86
 		// TODO in the future, get EntityIdParser and DataValueFactory from $services?
87 87
 		$repo = WikibaseRepo::getDefaultInstance();
88 88
 		$entityIdParser = $repo->getEntityIdParser();
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		);
95 95
 	},
96 96
 
97
-	ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function( MediaWikiServices $services ) {
97
+	ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function(MediaWikiServices $services) {
98 98
 		// TODO in the future, get DeserializerFactory and concept base URIs from $services?
99 99
 		$repo = WikibaseRepo::getDefaultInstance();
100 100
 		$deserializerFactory = $repo->getBaseDataModelDeserializerFactory();
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 	},
109 109
 
110
-	ConstraintsServices::CONNECTION_CHECKER_HELPER => function( MediaWikiServices $services ) {
110
+	ConstraintsServices::CONNECTION_CHECKER_HELPER => function(MediaWikiServices $services) {
111 111
 		return new ConnectionCheckerHelper();
112 112
 	},
113 113
 
114
-	ConstraintsServices::RANGE_CHECKER_HELPER => function( MediaWikiServices $services ) {
114
+	ConstraintsServices::RANGE_CHECKER_HELPER => function(MediaWikiServices $services) {
115 115
 		// TODO in the future, get UnitConverter from $services?
116 116
 		$repo = WikibaseRepo::getDefaultInstance();
117 117
 		$unitConverter = $repo->getUnitConverter();
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 		);
123 123
 	},
124 124
 
125
-	ConstraintsServices::SPARQL_HELPER => function( MediaWikiServices $services ) {
126
-		$endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' );
127
-		if ( $endpoint === '' ) {
125
+	ConstraintsServices::SPARQL_HELPER => function(MediaWikiServices $services) {
126
+		$endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint');
127
+		if ($endpoint === '') {
128 128
 			return new DummySparqlHelper();
129 129
 		}
130 130
 
@@ -140,117 +140,117 @@  discard block
 block discarded – undo
140 140
 			$entityIdParser,
141 141
 			$propertyDataTypeLookup,
142 142
 			$services->getMainWANObjectCache(),
143
-			ConstraintsServices::getViolationMessageSerializer( $services ),
144
-			ConstraintsServices::getViolationMessageDeserializer( $services ),
143
+			ConstraintsServices::getViolationMessageSerializer($services),
144
+			ConstraintsServices::getViolationMessageDeserializer($services),
145 145
 			$services->getStatsdDataFactory(),
146
-			ConstraintsServices::getExpiryLock( $services ),
146
+			ConstraintsServices::getExpiryLock($services),
147 147
 			ConstraintsServices::getLoggingHelper(),
148
-			wfWikiID() . ' WikibaseQualityConstraints ' . Http::userAgent(),
148
+			wfWikiID().' WikibaseQualityConstraints '.Http::userAgent(),
149 149
 			$services->getHttpRequestFactory()
150 150
 		);
151 151
 	},
152 152
 
153
-	ConstraintsServices::TYPE_CHECKER_HELPER => function( MediaWikiServices $services ) {
153
+	ConstraintsServices::TYPE_CHECKER_HELPER => function(MediaWikiServices $services) {
154 154
 		return new TypeCheckerHelper(
155
-			WikibaseServices::getEntityLookup( $services ),
155
+			WikibaseServices::getEntityLookup($services),
156 156
 			$services->getMainConfig(),
157
-			ConstraintsServices::getSparqlHelper( $services ),
157
+			ConstraintsServices::getSparqlHelper($services),
158 158
 			$services->getStatsdDataFactory()
159 159
 		);
160 160
 	},
161 161
 
162
-	ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function( MediaWikiServices $services ) {
162
+	ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function(MediaWikiServices $services) {
163 163
 		// TODO in the future, get StatementGuidParser from $services?
164 164
 		$repo = WikibaseRepo::getDefaultInstance();
165 165
 		$statementGuidParser = $repo->getStatementGuidParser();
166 166
 
167 167
 		$config = $services->getMainConfig();
168 168
 		$checkerMap = [
169
-			$config->get( 'WBQualityConstraintsConflictsWithConstraintId' )
170
-				=> ConstraintCheckerServices::getConflictsWithChecker( $services ),
171
-			$config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' )
172
-				=> ConstraintCheckerServices::getItemChecker( $services ),
173
-			$config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' )
174
-				=> ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ),
175
-			$config->get( 'WBQualityConstraintsSymmetricConstraintId' )
176
-				=> ConstraintCheckerServices::getSymmetricChecker( $services ),
177
-			$config->get( 'WBQualityConstraintsInverseConstraintId' )
178
-				=> ConstraintCheckerServices::getInverseChecker( $services ),
179
-			$config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' )
180
-				=> ConstraintCheckerServices::getQualifierChecker( $services ),
181
-			$config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' )
182
-				=> ConstraintCheckerServices::getQualifiersChecker( $services ),
183
-			$config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' )
184
-				=> ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ),
185
-			$config->get( 'WBQualityConstraintsRangeConstraintId' )
186
-				=> ConstraintCheckerServices::getRangeChecker( $services ),
187
-			$config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' )
188
-				=> ConstraintCheckerServices::getDiffWithinRangeChecker( $services ),
189
-			$config->get( 'WBQualityConstraintsTypeConstraintId' )
190
-				=> ConstraintCheckerServices::getTypeChecker( $services ),
191
-			$config->get( 'WBQualityConstraintsValueTypeConstraintId' )
192
-				=> ConstraintCheckerServices::getValueTypeChecker( $services ),
193
-			$config->get( 'WBQualityConstraintsSingleValueConstraintId' )
194
-				=> ConstraintCheckerServices::getSingleValueChecker( $services ),
195
-			$config->get( 'WBQualityConstraintsMultiValueConstraintId' )
196
-				=> ConstraintCheckerServices::getMultiValueChecker( $services ),
197
-			$config->get( 'WBQualityConstraintsDistinctValuesConstraintId' )
198
-				=> ConstraintCheckerServices::getUniqueValueChecker( $services ),
199
-			$config->get( 'WBQualityConstraintsFormatConstraintId' )
200
-				=> ConstraintCheckerServices::getFormatChecker( $services ),
201
-			$config->get( 'WBQualityConstraintsCommonsLinkConstraintId' )
202
-				=> ConstraintCheckerServices::getCommonsLinkChecker( $services ),
203
-			$config->get( 'WBQualityConstraintsOneOfConstraintId' )
204
-				=> ConstraintCheckerServices::getOneOfChecker( $services ),
205
-			$config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' )
206
-				=> ConstraintCheckerServices::getValueOnlyChecker( $services ),
207
-			$config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' )
208
-				=> ConstraintCheckerServices::getReferenceChecker( $services ),
209
-			$config->get( 'WBQualityConstraintsNoBoundsConstraintId' )
210
-				=> ConstraintCheckerServices::getNoBoundsChecker( $services ),
211
-			$config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' )
212
-				=> ConstraintCheckerServices::getAllowedUnitsChecker( $services ),
213
-			$config->get( 'WBQualityConstraintsSingleBestValueConstraintId' )
214
-				=> ConstraintCheckerServices::getSingleBestValueChecker( $services ),
215
-			$config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' )
216
-				=> ConstraintCheckerServices::getEntityTypeChecker( $services ),
217
-			$config->get( 'WBQualityConstraintsNoneOfConstraintId' )
218
-				=> ConstraintCheckerServices::getNoneOfChecker( $services ),
219
-			$config->get( 'WBQualityConstraintsIntegerConstraintId' )
220
-				=> ConstraintCheckerServices::getIntegerChecker( $services ),
221
-			$config->get( 'WBQualityConstraintsCitationNeededConstraintId' )
222
-				=> ConstraintCheckerServices::getCitationNeededChecker( $services ),
223
-			$config->get( 'WBQualityConstraintsPropertyScopeConstraintId' )
224
-				=> ConstraintCheckerServices::getPropertyScopeChecker( $services ),
225
-			$config->get( 'WBQualityConstraintsContemporaryConstraintId' )
226
-				=> ConstraintCheckerServices::getContemporaryChecker( $services ),
169
+			$config->get('WBQualityConstraintsConflictsWithConstraintId')
170
+				=> ConstraintCheckerServices::getConflictsWithChecker($services),
171
+			$config->get('WBQualityConstraintsItemRequiresClaimConstraintId')
172
+				=> ConstraintCheckerServices::getItemChecker($services),
173
+			$config->get('WBQualityConstraintsValueRequiresClaimConstraintId')
174
+				=> ConstraintCheckerServices::getTargetRequiredClaimChecker($services),
175
+			$config->get('WBQualityConstraintsSymmetricConstraintId')
176
+				=> ConstraintCheckerServices::getSymmetricChecker($services),
177
+			$config->get('WBQualityConstraintsInverseConstraintId')
178
+				=> ConstraintCheckerServices::getInverseChecker($services),
179
+			$config->get('WBQualityConstraintsUsedAsQualifierConstraintId')
180
+				=> ConstraintCheckerServices::getQualifierChecker($services),
181
+			$config->get('WBQualityConstraintsAllowedQualifiersConstraintId')
182
+				=> ConstraintCheckerServices::getQualifiersChecker($services),
183
+			$config->get('WBQualityConstraintsMandatoryQualifierConstraintId')
184
+				=> ConstraintCheckerServices::getMandatoryQualifiersChecker($services),
185
+			$config->get('WBQualityConstraintsRangeConstraintId')
186
+				=> ConstraintCheckerServices::getRangeChecker($services),
187
+			$config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId')
188
+				=> ConstraintCheckerServices::getDiffWithinRangeChecker($services),
189
+			$config->get('WBQualityConstraintsTypeConstraintId')
190
+				=> ConstraintCheckerServices::getTypeChecker($services),
191
+			$config->get('WBQualityConstraintsValueTypeConstraintId')
192
+				=> ConstraintCheckerServices::getValueTypeChecker($services),
193
+			$config->get('WBQualityConstraintsSingleValueConstraintId')
194
+				=> ConstraintCheckerServices::getSingleValueChecker($services),
195
+			$config->get('WBQualityConstraintsMultiValueConstraintId')
196
+				=> ConstraintCheckerServices::getMultiValueChecker($services),
197
+			$config->get('WBQualityConstraintsDistinctValuesConstraintId')
198
+				=> ConstraintCheckerServices::getUniqueValueChecker($services),
199
+			$config->get('WBQualityConstraintsFormatConstraintId')
200
+				=> ConstraintCheckerServices::getFormatChecker($services),
201
+			$config->get('WBQualityConstraintsCommonsLinkConstraintId')
202
+				=> ConstraintCheckerServices::getCommonsLinkChecker($services),
203
+			$config->get('WBQualityConstraintsOneOfConstraintId')
204
+				=> ConstraintCheckerServices::getOneOfChecker($services),
205
+			$config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId')
206
+				=> ConstraintCheckerServices::getValueOnlyChecker($services),
207
+			$config->get('WBQualityConstraintsUsedAsReferenceConstraintId')
208
+				=> ConstraintCheckerServices::getReferenceChecker($services),
209
+			$config->get('WBQualityConstraintsNoBoundsConstraintId')
210
+				=> ConstraintCheckerServices::getNoBoundsChecker($services),
211
+			$config->get('WBQualityConstraintsAllowedUnitsConstraintId')
212
+				=> ConstraintCheckerServices::getAllowedUnitsChecker($services),
213
+			$config->get('WBQualityConstraintsSingleBestValueConstraintId')
214
+				=> ConstraintCheckerServices::getSingleBestValueChecker($services),
215
+			$config->get('WBQualityConstraintsAllowedEntityTypesConstraintId')
216
+				=> ConstraintCheckerServices::getEntityTypeChecker($services),
217
+			$config->get('WBQualityConstraintsNoneOfConstraintId')
218
+				=> ConstraintCheckerServices::getNoneOfChecker($services),
219
+			$config->get('WBQualityConstraintsIntegerConstraintId')
220
+				=> ConstraintCheckerServices::getIntegerChecker($services),
221
+			$config->get('WBQualityConstraintsCitationNeededConstraintId')
222
+				=> ConstraintCheckerServices::getCitationNeededChecker($services),
223
+			$config->get('WBQualityConstraintsPropertyScopeConstraintId')
224
+				=> ConstraintCheckerServices::getPropertyScopeChecker($services),
225
+			$config->get('WBQualityConstraintsContemporaryConstraintId')
226
+				=> ConstraintCheckerServices::getContemporaryChecker($services),
227 227
 		];
228 228
 
229 229
 		return new DelegatingConstraintChecker(
230
-			WikibaseServices::getEntityLookup( $services ),
230
+			WikibaseServices::getEntityLookup($services),
231 231
 			$checkerMap,
232
-			ConstraintsServices::getConstraintLookup( $services ),
233
-			ConstraintsServices::getConstraintParameterParser( $services ),
232
+			ConstraintsServices::getConstraintLookup($services),
233
+			ConstraintsServices::getConstraintParameterParser($services),
234 234
 			$statementGuidParser,
235
-			ConstraintsServices::getLoggingHelper( $services ),
236
-			$config->get( 'WBQualityConstraintsCheckQualifiers' ),
237
-			$config->get( 'WBQualityConstraintsCheckReferences' ),
238
-			$config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' )
235
+			ConstraintsServices::getLoggingHelper($services),
236
+			$config->get('WBQualityConstraintsCheckQualifiers'),
237
+			$config->get('WBQualityConstraintsCheckReferences'),
238
+			$config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers')
239 239
 		);
240 240
 	},
241 241
 
242
-	ConstraintsServices::RESULTS_SOURCE => function( MediaWikiServices $services ) {
242
+	ConstraintsServices::RESULTS_SOURCE => function(MediaWikiServices $services) {
243 243
 		$config = $services->getMainConfig();
244 244
 		$resultsSource = new CheckingResultsSource(
245
-			ConstraintsServices::getDelegatingConstraintChecker( $services )
245
+			ConstraintsServices::getDelegatingConstraintChecker($services)
246 246
 		);
247 247
 
248
-		if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) {
248
+		if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) {
249 249
 			$possiblyStaleConstraintTypes = [
250
-				$config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ),
251
-				$config->get( 'WBQualityConstraintsTypeConstraintId' ),
252
-				$config->get( 'WBQualityConstraintsValueTypeConstraintId' ),
253
-				$config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ),
250
+				$config->get('WBQualityConstraintsCommonsLinkConstraintId'),
251
+				$config->get('WBQualityConstraintsTypeConstraintId'),
252
+				$config->get('WBQualityConstraintsValueTypeConstraintId'),
253
+				$config->get('WBQualityConstraintsDistinctValuesConstraintId'),
254 254
 			];
255 255
 			// TODO in the future, get EntityIdParser and WikiPageEntityMetaDataAccessor from $services?
256 256
 			$repo = WikibaseRepo::getDefaultInstance();
@@ -262,21 +262,21 @@  discard block
 block discarded – undo
262 262
 					$entityNamespaceLookup,
263 263
 					$services->getSlotRoleStore()
264 264
 				),
265
-				$repo->getSettings()->getSetting( 'changesDatabase' ),
265
+				$repo->getSettings()->getSetting('changesDatabase'),
266 266
 				'' // Empty string here means this only works for the local repo
267 267
 			);
268 268
 
269 269
 			$resultsSource = new CachingResultsSource(
270 270
 				$resultsSource,
271 271
 				ResultsCache::getDefaultInstance(),
272
-				ConstraintsServices::getCheckResultSerializer( $services ),
273
-				ConstraintsServices::getCheckResultDeserializer( $services ),
272
+				ConstraintsServices::getCheckResultSerializer($services),
273
+				ConstraintsServices::getCheckResultDeserializer($services),
274 274
 				$wikiPageEntityMetaDataAccessor,
275 275
 				$entityIdParser,
276
-				$config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ),
276
+				$config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'),
277 277
 				$possiblyStaleConstraintTypes,
278
-				$config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ),
279
-				ConstraintsServices::getLoggingHelper( $services )
278
+				$config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'),
279
+				ConstraintsServices::getLoggingHelper($services)
280 280
 			);
281 281
 		}
282 282
 
Please login to merge, or discard this patch.