Completed
Push — master ( 3f5d04...b6de96 )
by
unknown
18s
created
src/ConstraintCheck/Helper/SparqlHelper.php 1 patch
Spacing   +184 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper;
6 6
 
@@ -146,73 +146,73 @@  discard block
 block discarded – undo
146 146
 		$this->defaultUserAgent = $defaultUserAgent;
147 147
 		$this->requestFactory = $requestFactory;
148 148
 		$this->entityPrefixes = [];
149
-		foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) {
150
-			$this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName );
149
+		foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) {
150
+			$this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName);
151 151
 		}
152 152
 
153
-		$this->primaryEndpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' );
154
-		$this->additionalEndpoints = $config->get( 'WBQualityConstraintsAdditionalSparqlEndpoints' ) ?: [];
155
-		$this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' );
156
-		$this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' );
157
-		$this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' );
153
+		$this->primaryEndpoint = $config->get('WBQualityConstraintsSparqlEndpoint');
154
+		$this->additionalEndpoints = $config->get('WBQualityConstraintsAdditionalSparqlEndpoints') ?: [];
155
+		$this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis');
156
+		$this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId');
157
+		$this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize');
158 158
 		$this->timeoutExceptionClasses = $config->get(
159 159
 			'WBQualityConstraintsSparqlTimeoutExceptionClasses'
160 160
 		);
161 161
 		$this->sparqlHasWikibaseSupport = $config->get(
162 162
 			'WBQualityConstraintsSparqlHasWikibaseSupport'
163 163
 		);
164
-		$this->sparqlThrottlingFallbackDuration = (int)$config->get(
164
+		$this->sparqlThrottlingFallbackDuration = (int) $config->get(
165 165
 			'WBQualityConstraintsSparqlThrottlingFallbackDuration'
166 166
 		);
167 167
 
168
-		$this->prefixes = $this->getQueryPrefixes( $rdfVocabulary );
168
+		$this->prefixes = $this->getQueryPrefixes($rdfVocabulary);
169 169
 	}
170 170
 
171
-	private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ): string {
171
+	private function getQueryPrefixes(RdfVocabulary $rdfVocabulary): string {
172 172
 		// TODO: it would probably be smarter that RdfVocabulary exposed these prefixes somehow
173 173
 		$prefixes = '';
174
-		foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) {
174
+		foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) {
175 175
 			$prefixes .= <<<END
176
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
176
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
177 177
 END;
178 178
 		}
179 179
 		$prefixes .= <<<END
180
-PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}>
181
-PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n
180
+PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}>
181
+PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n
182 182
 END;
183 183
 
184
-		foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) {
184
+		foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) {
185 185
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM];
186 186
 			$prefixes .= <<<END
187
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
187
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
188 188
 END;
189 189
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM];
190 190
 			$prefixes .= <<<END
191
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
191
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
192 192
 END;
193 193
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT];
194 194
 			$prefixes .= <<<END
195
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
195
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
196 196
 END;
197 197
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER];
198 198
 			$prefixes .= <<<END
199
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
199
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
200 200
 END;
201 201
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE];
202 202
 			$prefixes .= <<<END
203
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
203
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
204 204
 END;
205 205
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE];
206 206
 			$prefixes .= <<<END
207
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
207
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
208 208
 END;
209 209
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE];
210 210
 			$prefixes .= <<<END
211
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
211
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
212 212
 END;
213 213
 		}
214 214
 		$prefixes .= <<<END
215
-PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n
215
+PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n
216 216
 END;
217 217
 		return $prefixes;
218 218
 	}
@@ -224,21 +224,20 @@  discard block
 block discarded – undo
224 224
 	 * @return CachedBool
225 225
 	 * @throws SparqlHelperException if the query times out or some other error occurs
226 226
 	 */
227
-	public function hasType( string $id, array $classes ): CachedBool {
227
+	public function hasType(string $id, array $classes): CachedBool {
228 228
 		// TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually
229 229
 		$gearingHint = $this->sparqlHasWikibaseSupport ?
230
-			' hint:Prior hint:gearing "forward".' :
231
-			'';
230
+			' hint:Prior hint:gearing "forward".' : '';
232 231
 
233 232
 		$metadatas = [];
234 233
 
235
-		foreach ( array_chunk( $classes, 20 ) as $classesChunk ) {
236
-			$classesValues = implode( ' ', array_map(
237
-				static function ( $class ) {
238
-					return 'wd:' . $class;
234
+		foreach (array_chunk($classes, 20) as $classesChunk) {
235
+			$classesValues = implode(' ', array_map(
236
+				static function($class) {
237
+					return 'wd:'.$class;
239 238
 				},
240 239
 				$classesChunk
241
-			) );
240
+			));
242 241
 
243 242
 			$query = <<<EOF
244 243
 ASK {
@@ -248,19 +247,19 @@  discard block
 block discarded – undo
248 247
 }
249 248
 EOF;
250 249
 
251
-			$result = $this->runQuery( $query, $this->primaryEndpoint );
250
+			$result = $this->runQuery($query, $this->primaryEndpoint);
252 251
 			$metadatas[] = $result->getMetadata();
253
-			if ( $result->getArray()['boolean'] ) {
252
+			if ($result->getArray()['boolean']) {
254 253
 				return new CachedBool(
255 254
 					true,
256
-					Metadata::merge( $metadatas )
255
+					Metadata::merge($metadatas)
257 256
 				);
258 257
 			}
259 258
 		}
260 259
 
261 260
 		return new CachedBool(
262 261
 			false,
263
-			Metadata::merge( $metadatas )
262
+			Metadata::merge($metadatas)
264 263
 		);
265 264
 	}
266 265
 
@@ -268,7 +267,7 @@  discard block
 block discarded – undo
268 267
 	 * Helper function used by findEntitiesWithSameStatement to filter
269 268
 	 * out entities with different qualifiers or no qualifier value.
270 269
 	 */
271
-	private function nestedSeparatorFilter( PropertyId $separator ): string {
270
+	private function nestedSeparatorFilter(PropertyId $separator): string {
272 271
 		$filter = <<<EOF
273 272
   MINUS {
274 273
     ?statement pq:$separator ?qualifier.
@@ -305,14 +304,14 @@  discard block
 block discarded – undo
305 304
 	 * @return CachedEntityIds
306 305
 	 * @throws SparqlHelperException if the query times out or some other error occurs
307 306
 	 */
308
-	public function findEntitiesWithSameStatement( Statement $statement, array $separators ): CachedEntityIds {
307
+	public function findEntitiesWithSameStatement(Statement $statement, array $separators): CachedEntityIds {
309 308
 		$pid = $statement->getPropertyId()->getSerialization();
310 309
 		$guid = $statement->getGuid();
311 310
 		'@phan-var string $guid'; // statement must have a non-null GUID
312
-		$guidForRdf = str_replace( '$', '-', $guid );
311
+		$guidForRdf = str_replace('$', '-', $guid);
313 312
 
314
-		$separatorFilters = array_map( [ $this, 'nestedSeparatorFilter' ], $separators );
315
-		$finalSeparatorFilter = implode( "\n", $separatorFilters );
313
+		$separatorFilters = array_map([$this, 'nestedSeparatorFilter'], $separators);
314
+		$finalSeparatorFilter = implode("\n", $separatorFilters);
316 315
 
317 316
 		$query = <<<EOF
318 317
 SELECT DISTINCT ?otherEntity WHERE {
@@ -330,12 +329,12 @@  discard block
 block discarded – undo
330 329
 LIMIT 10
331 330
 EOF;
332 331
 
333
-		$results = [ $this->runQuery( $query, $this->primaryEndpoint ) ];
334
-		foreach ( $this->additionalEndpoints as $endpoint ) {
335
-			$results[] = $this->runQuery( $query, $endpoint );
332
+		$results = [$this->runQuery($query, $this->primaryEndpoint)];
333
+		foreach ($this->additionalEndpoints as $endpoint) {
334
+			$results[] = $this->runQuery($query, $endpoint);
336 335
 		}
337 336
 
338
-		return $this->getOtherEntities( $results );
337
+		return $this->getOtherEntities($results);
339 338
 	}
340 339
 
341 340
 	/**
@@ -360,16 +359,15 @@  discard block
 block discarded – undo
360 359
 		$dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty(
361 360
 			$snak->getPropertyId()
362 361
 		);
363
-		[ $value, $isFullValue ] = $this->getRdfLiteral( $dataType, $dataValue );
364
-		if ( $isFullValue ) {
362
+		[$value, $isFullValue] = $this->getRdfLiteral($dataType, $dataValue);
363
+		if ($isFullValue) {
365 364
 			$prefix .= 'v';
366 365
 		}
367 366
 		$path = $type === Context::TYPE_QUALIFIER ?
368
-			"$prefix:$pid" :
369
-			"prov:wasDerivedFrom/$prefix:$pid";
367
+			"$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid";
370 368
 
371 369
 		$deprecatedFilter = '';
372
-		if ( $ignoreDeprecatedStatements ) {
370
+		if ($ignoreDeprecatedStatements) {
373 371
 			$deprecatedFilter = <<< EOF
374 372
   MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }
375 373
 EOF;
@@ -389,19 +387,19 @@  discard block
 block discarded – undo
389 387
 LIMIT 10
390 388
 EOF;
391 389
 
392
-		$results = [ $this->runQuery( $query, $this->primaryEndpoint ) ];
393
-		foreach ( $this->additionalEndpoints as $endpoint ) {
394
-			$results[] = $this->runQuery( $query, $endpoint );
390
+		$results = [$this->runQuery($query, $this->primaryEndpoint)];
391
+		foreach ($this->additionalEndpoints as $endpoint) {
392
+			$results[] = $this->runQuery($query, $endpoint);
395 393
 		}
396 394
 
397
-		return $this->getOtherEntities( $results );
395
+		return $this->getOtherEntities($results);
398 396
 	}
399 397
 
400 398
 	/**
401 399
 	 * Return SPARQL code for a string literal with $text as content.
402 400
 	 */
403
-	private function stringLiteral( string $text ): string {
404
-		return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"';
401
+	private function stringLiteral(string $text): string {
402
+		return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"';
405 403
 	}
406 404
 
407 405
 	/**
@@ -411,26 +409,26 @@  discard block
 block discarded – undo
411 409
 	 *
412 410
 	 * @return CachedEntityIds
413 411
 	 */
414
-	private function getOtherEntities( array $results ): CachedEntityIds {
412
+	private function getOtherEntities(array $results): CachedEntityIds {
415 413
 		$allResultBindings = [];
416 414
 		$metadatas = [];
417 415
 
418
-		foreach ( $results as $result ) {
416
+		foreach ($results as $result) {
419 417
 			$metadatas[] = $result->getMetadata();
420
-			$allResultBindings = array_merge( $allResultBindings, $result->getArray()['results']['bindings'] );
418
+			$allResultBindings = array_merge($allResultBindings, $result->getArray()['results']['bindings']);
421 419
 		}
422 420
 
423 421
 		$entityIds = array_map(
424
-			function ( $resultBindings ) {
422
+			function($resultBindings) {
425 423
 				$entityIRI = $resultBindings['otherEntity']['value'];
426
-				foreach ( $this->entityPrefixes as $entityPrefix ) {
427
-					$entityPrefixLength = strlen( $entityPrefix );
428
-					if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) {
424
+				foreach ($this->entityPrefixes as $entityPrefix) {
425
+					$entityPrefixLength = strlen($entityPrefix);
426
+					if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) {
429 427
 						try {
430 428
 							return $this->entityIdParser->parse(
431
-								substr( $entityIRI, $entityPrefixLength )
429
+								substr($entityIRI, $entityPrefixLength)
432 430
 							);
433
-						} catch ( EntityIdParsingException $e ) {
431
+						} catch (EntityIdParsingException $e) {
434 432
 							// fall through
435 433
 						}
436 434
 					}
@@ -444,8 +442,8 @@  discard block
 block discarded – undo
444 442
 		);
445 443
 
446 444
 		return new CachedEntityIds(
447
-			array_values( array_filter( array_unique( $entityIds ) ) ),
448
-			Metadata::merge( $metadatas )
445
+			array_values(array_filter(array_unique($entityIds))),
446
+			Metadata::merge($metadatas)
449 447
 		);
450 448
 	}
451 449
 
@@ -456,50 +454,50 @@  discard block
 block discarded – undo
456 454
 	 * @return array the literal or IRI as a string in SPARQL syntax,
457 455
 	 * and a boolean indicating whether it refers to a full value node or not
458 456
 	 */
459
-	private function getRdfLiteral( string $dataType, DataValue $dataValue ): array {
460
-		switch ( $dataType ) {
457
+	private function getRdfLiteral(string $dataType, DataValue $dataValue): array {
458
+		switch ($dataType) {
461 459
 			case 'string':
462 460
 			case 'external-id':
463
-				return [ $this->stringLiteral( $dataValue->getValue() ), false ];
461
+				return [$this->stringLiteral($dataValue->getValue()), false];
464 462
 			case 'commonsMedia':
465
-				$url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() );
466
-				return [ '<' . $url . '>', false ];
463
+				$url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue());
464
+				return ['<'.$url.'>', false];
467 465
 			case 'geo-shape':
468
-				$url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() );
469
-				return [ '<' . $url . '>', false ];
466
+				$url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue());
467
+				return ['<'.$url.'>', false];
470 468
 			case 'tabular-data':
471
-				$url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() );
472
-				return [ '<' . $url . '>', false ];
469
+				$url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue());
470
+				return ['<'.$url.'>', false];
473 471
 			case 'url':
474 472
 				$url = $dataValue->getValue();
475
-				if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) {
473
+				if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) {
476 474
 					// not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF)
477 475
 					// such an URL should never reach us, so just throw
478
-					throw new InvalidArgumentException( 'invalid URL: ' . $url );
476
+					throw new InvalidArgumentException('invalid URL: '.$url);
479 477
 				}
480
-				return [ '<' . $url . '>', false ];
478
+				return ['<'.$url.'>', false];
481 479
 			case 'wikibase-item':
482 480
 			case 'wikibase-property':
483 481
 				/** @var EntityIdValue $dataValue */
484 482
 				'@phan-var EntityIdValue $dataValue';
485
-				return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ];
483
+				return ['wd:'.$dataValue->getEntityId()->getSerialization(), false];
486 484
 			case 'monolingualtext':
487 485
 				/** @var MonolingualTextValue $dataValue */
488 486
 				'@phan-var MonolingualTextValue $dataValue';
489 487
 				$lang = $dataValue->getLanguageCode();
490
-				if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) {
488
+				if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) {
491 489
 					// not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG)
492 490
 					// such a language tag should never reach us, so just throw
493
-					throw new InvalidArgumentException( 'invalid language tag: ' . $lang );
491
+					throw new InvalidArgumentException('invalid language tag: '.$lang);
494 492
 				}
495
-				return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ];
493
+				return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false];
496 494
 			case 'globe-coordinate':
497 495
 			case 'quantity':
498 496
 			case 'time':
499 497
 				// @phan-suppress-next-line PhanUndeclaredMethod
500
-				return [ 'wdv:' . $dataValue->getHash(), true ];
498
+				return ['wdv:'.$dataValue->getHash(), true];
501 499
 			default:
502
-				throw new InvalidArgumentException( 'unknown data type: ' . $dataType );
500
+				throw new InvalidArgumentException('unknown data type: '.$dataType);
503 501
 		}
504 502
 	}
505 503
 	// phpcs:enable
@@ -508,43 +506,43 @@  discard block
 block discarded – undo
508 506
 	 * @throws SparqlHelperException if the query times out or some other error occurs
509 507
 	 * @throws ConstraintParameterException if the $regex is invalid
510 508
 	 */
511
-	public function matchesRegularExpression( string $text, string $regex ): bool {
509
+	public function matchesRegularExpression(string $text, string $regex): bool {
512 510
 		// caching wrapper around matchesRegularExpressionWithSparql
513 511
 
514
-		$textHash = hash( 'sha256', $text );
512
+		$textHash = hash('sha256', $text);
515 513
 		$cacheKey = $this->cache->makeKey(
516 514
 			'WikibaseQualityConstraints', // extension
517 515
 			'regex', // action
518 516
 			'WDQS-Java', // regex flavor
519
-			hash( 'sha256', $regex )
517
+			hash('sha256', $regex)
520 518
 		);
521 519
 
522 520
 		$cacheMapArray = $this->cache->getWithSetCallback(
523 521
 			$cacheKey,
524 522
 			WANObjectCache::TTL_DAY,
525
-			function ( $cacheMapArray ) use ( $text, $regex, $textHash ) {
523
+			function($cacheMapArray) use ($text, $regex, $textHash) {
526 524
 				// Initialize the cache map if not set
527
-				if ( $cacheMapArray === false ) {
525
+				if ($cacheMapArray === false) {
528 526
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.init';
529
-					$this->dataFactory->increment( $key );
527
+					$this->dataFactory->increment($key);
530 528
 					return [];
531 529
 				}
532 530
 
533 531
 				$key = 'wikibase.quality.constraints.regex.cache.refresh';
534
-				$this->dataFactory->increment( $key );
535
-				$cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize );
536
-				if ( $cacheMap->has( $textHash ) ) {
532
+				$this->dataFactory->increment($key);
533
+				$cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize);
534
+				if ($cacheMap->has($textHash)) {
537 535
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.hit';
538
-					$this->dataFactory->increment( $key );
539
-					$cacheMap->get( $textHash ); // ping cache
536
+					$this->dataFactory->increment($key);
537
+					$cacheMap->get($textHash); // ping cache
540 538
 				} else {
541 539
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.miss';
542
-					$this->dataFactory->increment( $key );
540
+					$this->dataFactory->increment($key);
543 541
 					try {
544
-						$matches = $this->matchesRegularExpressionWithSparql( $text, $regex );
545
-					} catch ( ConstraintParameterException $e ) {
546
-						$matches = $this->serializeConstraintParameterException( $e );
547
-					} catch ( SparqlHelperException $e ) {
542
+						$matches = $this->matchesRegularExpressionWithSparql($text, $regex);
543
+					} catch (ConstraintParameterException $e) {
544
+						$matches = $this->serializeConstraintParameterException($e);
545
+					} catch (SparqlHelperException $e) {
548 546
 						// don’t cache this
549 547
 						return $cacheMap->toArray();
550 548
 					}
@@ -568,42 +566,42 @@  discard block
 block discarded – undo
568 566
 			]
569 567
 		);
570 568
 
571
-		if ( isset( $cacheMapArray[$textHash] ) ) {
569
+		if (isset($cacheMapArray[$textHash])) {
572 570
 			$key = 'wikibase.quality.constraints.regex.cache.hit';
573
-			$this->dataFactory->increment( $key );
571
+			$this->dataFactory->increment($key);
574 572
 			$matches = $cacheMapArray[$textHash];
575
-			if ( is_bool( $matches ) ) {
573
+			if (is_bool($matches)) {
576 574
 				return $matches;
577
-			} elseif ( is_array( $matches ) &&
578
-				$matches['type'] == ConstraintParameterException::class ) {
579
-				throw $this->deserializeConstraintParameterException( $matches );
575
+			} elseif (is_array($matches) &&
576
+				$matches['type'] == ConstraintParameterException::class) {
577
+				throw $this->deserializeConstraintParameterException($matches);
580 578
 			} else {
581 579
 				throw new UnexpectedValueException(
582
-					'Value of unknown type in object cache (' .
583
-					'cache key: ' . $cacheKey . ', ' .
584
-					'cache map key: ' . $textHash . ', ' .
585
-					'value type: ' . get_debug_type( $matches ) . ')'
580
+					'Value of unknown type in object cache ('.
581
+					'cache key: '.$cacheKey.', '.
582
+					'cache map key: '.$textHash.', '.
583
+					'value type: '.get_debug_type($matches).')'
586 584
 				);
587 585
 			}
588 586
 		} else {
589 587
 			$key = 'wikibase.quality.constraints.regex.cache.miss';
590
-			$this->dataFactory->increment( $key );
591
-			return $this->matchesRegularExpressionWithSparql( $text, $regex );
588
+			$this->dataFactory->increment($key);
589
+			return $this->matchesRegularExpressionWithSparql($text, $regex);
592 590
 		}
593 591
 	}
594 592
 
595
-	private function serializeConstraintParameterException( ConstraintParameterException $cpe ): array {
593
+	private function serializeConstraintParameterException(ConstraintParameterException $cpe): array {
596 594
 		return [
597 595
 			'type' => ConstraintParameterException::class,
598
-			'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ),
596
+			'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()),
599 597
 		];
600 598
 	}
601 599
 
602
-	private function deserializeConstraintParameterException( array $serialization ): ConstraintParameterException {
600
+	private function deserializeConstraintParameterException(array $serialization): ConstraintParameterException {
603 601
 		$message = $this->violationMessageDeserializer->deserialize(
604 602
 			$serialization['violationMessage']
605 603
 		);
606
-		return new ConstraintParameterException( $message );
604
+		return new ConstraintParameterException($message);
607 605
 	}
608 606
 
609 607
 	/**
@@ -613,25 +611,25 @@  discard block
 block discarded – undo
613 611
 	 * @throws SparqlHelperException if the query times out or some other error occurs
614 612
 	 * @throws ConstraintParameterException if the $regex is invalid
615 613
 	 */
616
-	public function matchesRegularExpressionWithSparql( string $text, string $regex ): bool {
617
-		$textStringLiteral = $this->stringLiteral( $text );
618
-		$regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' );
614
+	public function matchesRegularExpressionWithSparql(string $text, string $regex): bool {
615
+		$textStringLiteral = $this->stringLiteral($text);
616
+		$regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$');
619 617
 
620 618
 		$query = <<<EOF
621 619
 SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {}
622 620
 EOF;
623 621
 
624
-		$result = $this->runQuery( $query, $this->primaryEndpoint, false );
622
+		$result = $this->runQuery($query, $this->primaryEndpoint, false);
625 623
 
626 624
 		$vars = $result->getArray()['results']['bindings'][0];
627
-		if ( array_key_exists( 'matches', $vars ) ) {
625
+		if (array_key_exists('matches', $vars)) {
628 626
 			// true or false ⇒ regex okay, text matches or not
629 627
 			return $vars['matches']['value'] === 'true';
630 628
 		} else {
631 629
 			// empty result: regex broken
632 630
 			throw new ConstraintParameterException(
633
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
634
-					->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE )
631
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
632
+					->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE)
635 633
 			);
636 634
 		}
637 635
 	}
@@ -639,14 +637,14 @@  discard block
 block discarded – undo
639 637
 	/**
640 638
 	 * Check whether the text content of an error response indicates a query timeout.
641 639
 	 */
642
-	public function isTimeout( string $responseContent ): bool {
643
-		$timeoutRegex = implode( '|', array_map(
644
-			static function ( $fqn ) {
645
-				return preg_quote( $fqn, '/' );
640
+	public function isTimeout(string $responseContent): bool {
641
+		$timeoutRegex = implode('|', array_map(
642
+			static function($fqn) {
643
+				return preg_quote($fqn, '/');
646 644
 			},
647 645
 			$this->timeoutExceptionClasses
648
-		) );
649
-		return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent );
646
+		));
647
+		return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent);
650 648
 	}
651 649
 
652 650
 	/**
@@ -658,17 +656,17 @@  discard block
 block discarded – undo
658 656
 	 * @return int|boolean the max-age (in seconds)
659 657
 	 * or a plain boolean if no max-age can be determined
660 658
 	 */
661
-	public function getCacheMaxAge( array $responseHeaders ) {
659
+	public function getCacheMaxAge(array $responseHeaders) {
662 660
 		if (
663
-			array_key_exists( 'x-cache-status', $responseHeaders ) &&
664
-			preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] )
661
+			array_key_exists('x-cache-status', $responseHeaders) &&
662
+			preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0])
665 663
 		) {
666 664
 			$maxage = [];
667 665
 			if (
668
-				array_key_exists( 'cache-control', $responseHeaders ) &&
669
-				preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage )
666
+				array_key_exists('cache-control', $responseHeaders) &&
667
+				preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage)
670 668
 			) {
671
-				return intval( $maxage[1] );
669
+				return intval($maxage[1]);
672 670
 			} else {
673 671
 				return true;
674 672
 			}
@@ -689,34 +687,34 @@  discard block
 block discarded – undo
689 687
 	 * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After
690 688
 	 * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format
691 689
 	 */
692
-	public function getThrottling( MWHttpRequest $request ) {
693
-		$retryAfterValue = $request->getResponseHeader( 'Retry-After' );
694
-		if ( $retryAfterValue === null ) {
690
+	public function getThrottling(MWHttpRequest $request) {
691
+		$retryAfterValue = $request->getResponseHeader('Retry-After');
692
+		if ($retryAfterValue === null) {
695 693
 			return self::NO_RETRY_AFTER;
696 694
 		}
697 695
 
698
-		$trimmedRetryAfterValue = trim( $retryAfterValue );
699
-		if ( $trimmedRetryAfterValue === '' ) {
696
+		$trimmedRetryAfterValue = trim($retryAfterValue);
697
+		if ($trimmedRetryAfterValue === '') {
700 698
 			return self::EMPTY_RETRY_AFTER;
701 699
 		}
702 700
 
703
-		if ( is_numeric( $trimmedRetryAfterValue ) ) {
704
-			$delaySeconds = (int)$trimmedRetryAfterValue;
705
-			if ( $delaySeconds >= 0 ) {
706
-				return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) );
701
+		if (is_numeric($trimmedRetryAfterValue)) {
702
+			$delaySeconds = (int) $trimmedRetryAfterValue;
703
+			if ($delaySeconds >= 0) {
704
+				return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S'));
707 705
 			}
708 706
 		} else {
709
-			$return = strtotime( $trimmedRetryAfterValue );
710
-			if ( $return !== false ) {
711
-				return new ConvertibleTimestamp( $return );
707
+			$return = strtotime($trimmedRetryAfterValue);
708
+			if ($return !== false) {
709
+				return new ConvertibleTimestamp($return);
712 710
 			}
713 711
 		}
714 712
 		return self::INVALID_RETRY_AFTER;
715 713
 	}
716 714
 
717
-	private function getTimestampInFuture( DateInterval $delta ) {
715
+	private function getTimestampInFuture(DateInterval $delta) {
718 716
 		$now = new ConvertibleTimestamp();
719
-		return new ConvertibleTimestamp( $now->timestamp->add( $delta ) );
717
+		return new ConvertibleTimestamp($now->timestamp->add($delta));
720 718
 	}
721 719
 
722 720
 	/**
@@ -731,64 +729,63 @@  discard block
 block discarded – undo
731 729
 	 *
732 730
 	 * @throws SparqlHelperException if the query times out or some other error occurs
733 731
 	 */
734
-	protected function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults {
735
-		if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) {
736
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
732
+	protected function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults {
733
+		if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) {
734
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
737 735
 			throw new TooManySparqlRequestsException();
738 736
 		}
739 737
 
740
-		if ( $this->sparqlHasWikibaseSupport ) {
738
+		if ($this->sparqlHasWikibaseSupport) {
741 739
 			$needsPrefixes = false;
742 740
 		}
743 741
 
744
-		if ( $needsPrefixes ) {
745
-			$query = $this->prefixes . $query;
742
+		if ($needsPrefixes) {
743
+			$query = $this->prefixes.$query;
746 744
 		}
747
-		$query = "#wbqc\n" . $query;
745
+		$query = "#wbqc\n".$query;
748 746
 
749
-		$url = $endpoint . '?' . http_build_query(
747
+		$url = $endpoint.'?'.http_build_query(
750 748
 			[
751 749
 				'query' => $query,
752 750
 				'format' => 'json',
753 751
 				'maxQueryTimeMillis' => $this->maxQueryTimeMillis,
754 752
 			],
755
-			'', ini_get( 'arg_separator.output' ),
753
+			'', ini_get('arg_separator.output'),
756 754
 			// encode spaces with %20, not +
757 755
 			PHP_QUERY_RFC3986
758 756
 		);
759 757
 
760 758
 		$options = [
761 759
 			'method' => 'GET',
762
-			'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ),
760
+			'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000),
763 761
 			'connectTimeout' => 'default',
764 762
 			'userAgent' => $this->defaultUserAgent,
765 763
 		];
766
-		$request = $this->requestFactory->create( $url, $options, __METHOD__ );
767
-		$startTime = microtime( true );
764
+		$request = $this->requestFactory->create($url, $options, __METHOD__);
765
+		$startTime = microtime(true);
768 766
 		$requestStatus = $request->execute();
769
-		$endTime = microtime( true );
767
+		$endTime = microtime(true);
770 768
 		$this->dataFactory->timing(
771 769
 			'wikibase.quality.constraints.sparql.timing',
772
-			( $endTime - $startTime ) * 1000
770
+			($endTime - $startTime) * 1000
773 771
 		);
774 772
 
775
-		$this->guardAgainstTooManyRequestsError( $request );
773
+		$this->guardAgainstTooManyRequestsError($request);
776 774
 
777
-		$maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() );
778
-		if ( $maxAge ) {
779
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' );
775
+		$maxAge = $this->getCacheMaxAge($request->getResponseHeaders());
776
+		if ($maxAge) {
777
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.cached');
780 778
 		}
781 779
 
782
-		if ( $requestStatus->isOK() ) {
780
+		if ($requestStatus->isOK()) {
783 781
 			$json = $request->getContent();
784
-			$jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC );
785
-			if ( $jsonStatus->isOK() ) {
782
+			$jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC);
783
+			if ($jsonStatus->isOK()) {
786 784
 				return new CachedQueryResults(
787 785
 					$jsonStatus->getValue(),
788 786
 					Metadata::ofCachingMetadata(
789 787
 						$maxAge ?
790
-							CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) :
791
-							CachingMetadata::fresh()
788
+							CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh()
792 789
 					)
793 790
 				);
794 791
 			} else {
@@ -805,9 +802,9 @@  discard block
 block discarded – undo
805 802
 			// fall through to general error handling
806 803
 		}
807 804
 
808
-		$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' );
805
+		$this->dataFactory->increment('wikibase.quality.constraints.sparql.error');
809 806
 
810
-		if ( $this->isTimeout( $request->getContent() ) ) {
807
+		if ($this->isTimeout($request->getContent())) {
811 808
 			$this->dataFactory->increment(
812 809
 				'wikibase.quality.constraints.sparql.error.timeout'
813 810
 			);
@@ -822,29 +819,29 @@  discard block
 block discarded – undo
822 819
 	 * @param MWHttpRequest $request
823 820
 	 * @throws TooManySparqlRequestsException
824 821
 	 */
825
-	private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void {
826
-		if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) {
822
+	private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void {
823
+		if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) {
827 824
 			return;
828 825
 		}
829 826
 
830 827
 		$fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration;
831 828
 
832
-		if ( $fallbackBlockDuration < 0 ) {
833
-			throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' .
834
-				$fallbackBlockDuration );
829
+		if ($fallbackBlockDuration < 0) {
830
+			throw new InvalidArgumentException('Fallback duration must be positive int but is: '.
831
+				$fallbackBlockDuration);
835 832
 		}
836 833
 
837
-		$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
838
-		$throttlingUntil = $this->getThrottling( $request );
839
-		if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) {
840
-			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request );
834
+		$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
835
+		$throttlingUntil = $this->getThrottling($request);
836
+		if (!($throttlingUntil instanceof ConvertibleTimestamp)) {
837
+			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request);
841 838
 			$this->throttlingLock->lock(
842 839
 				self::EXPIRY_LOCK_ID,
843
-				$this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) )
840
+				$this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S'))
844 841
 			);
845 842
 		} else {
846
-			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request );
847
-			$this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil );
843
+			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request);
844
+			$this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil);
848 845
 		}
849 846
 		throw new TooManySparqlRequestsException();
850 847
 	}
Please login to merge, or discard this patch.
src/ServiceWiring-Wikibase.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport;
6 6
 
@@ -11,16 +11,16 @@  discard block
 block discarded – undo
11 11
 use Wikibase\Repo\WikibaseRepo;
12 12
 
13 13
 return [
14
-	WikibaseServices::ENTITY_LOOKUP => static function ( MediaWikiServices $services ): EntityLookup {
14
+	WikibaseServices::ENTITY_LOOKUP => static function(MediaWikiServices $services): EntityLookup {
15 15
 		return new ExceptionIgnoringEntityLookup(
16
-			WikibaseRepo::getEntityLookup( $services )
16
+			WikibaseRepo::getEntityLookup($services)
17 17
 		);
18 18
 	},
19 19
 
20
-	WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function ( MediaWikiServices $services ): EntityLookup {
20
+	WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function(MediaWikiServices $services): EntityLookup {
21 21
 		return new ExceptionIgnoringEntityLookup(
22
-			WikibaseRepo::getStore( $services )
23
-				->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY )
22
+			WikibaseRepo::getStore($services)
23
+				->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY)
24 24
 		);
25 25
 	},
26 26
 ];
Please login to merge, or discard this patch.
src/ServiceWiring-ConstraintCheckers.php 1 patch
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -38,216 +38,216 @@
 block discarded – undo
38 38
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker;
39 39
 
40 40
 return [
41
-	ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function ( MediaWikiServices $services ): ConflictsWithChecker {
41
+	ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function(MediaWikiServices $services): ConflictsWithChecker {
42 42
 		return new ConflictsWithChecker(
43
-			ConstraintsServices::getConstraintParameterParser( $services ),
44
-			ConstraintsServices::getConnectionCheckerHelper( $services )
43
+			ConstraintsServices::getConstraintParameterParser($services),
44
+			ConstraintsServices::getConnectionCheckerHelper($services)
45 45
 		);
46 46
 	},
47 47
 
48
-	ConstraintCheckerServices::ITEM_CHECKER => static function ( MediaWikiServices $services ): ItemChecker {
48
+	ConstraintCheckerServices::ITEM_CHECKER => static function(MediaWikiServices $services): ItemChecker {
49 49
 		return new ItemChecker(
50
-			ConstraintsServices::getConstraintParameterParser( $services ),
51
-			ConstraintsServices::getConnectionCheckerHelper( $services )
50
+			ConstraintsServices::getConstraintParameterParser($services),
51
+			ConstraintsServices::getConnectionCheckerHelper($services)
52 52
 		);
53 53
 	},
54 54
 
55
-	ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function (
55
+	ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function(
56 56
 		MediaWikiServices $services
57 57
 	): TargetRequiredClaimChecker {
58 58
 		return new TargetRequiredClaimChecker(
59
-			WikibaseServices::getEntityLookup( $services ),
60
-			ConstraintsServices::getConstraintParameterParser( $services ),
61
-			ConstraintsServices::getConnectionCheckerHelper( $services )
59
+			WikibaseServices::getEntityLookup($services),
60
+			ConstraintsServices::getConstraintParameterParser($services),
61
+			ConstraintsServices::getConnectionCheckerHelper($services)
62 62
 		);
63 63
 	},
64 64
 
65
-	ConstraintCheckerServices::SYMMETRIC_CHECKER => static function ( MediaWikiServices $services ): SymmetricChecker {
65
+	ConstraintCheckerServices::SYMMETRIC_CHECKER => static function(MediaWikiServices $services): SymmetricChecker {
66 66
 		return new SymmetricChecker(
67
-			WikibaseServices::getEntityLookupWithoutCache( $services ),
68
-			ConstraintsServices::getConnectionCheckerHelper( $services )
67
+			WikibaseServices::getEntityLookupWithoutCache($services),
68
+			ConstraintsServices::getConnectionCheckerHelper($services)
69 69
 		);
70 70
 	},
71 71
 
72
-	ConstraintCheckerServices::INVERSE_CHECKER => static function ( MediaWikiServices $services ): InverseChecker {
72
+	ConstraintCheckerServices::INVERSE_CHECKER => static function(MediaWikiServices $services): InverseChecker {
73 73
 		return new InverseChecker(
74
-			WikibaseServices::getEntityLookup( $services ),
75
-			ConstraintsServices::getConstraintParameterParser( $services ),
76
-			ConstraintsServices::getConnectionCheckerHelper( $services )
74
+			WikibaseServices::getEntityLookup($services),
75
+			ConstraintsServices::getConstraintParameterParser($services),
76
+			ConstraintsServices::getConnectionCheckerHelper($services)
77 77
 		);
78 78
 	},
79 79
 
80
-	ConstraintCheckerServices::QUALIFIER_CHECKER => static function ( MediaWikiServices $services ): QualifierChecker {
80
+	ConstraintCheckerServices::QUALIFIER_CHECKER => static function(MediaWikiServices $services): QualifierChecker {
81 81
 		return new QualifierChecker();
82 82
 	},
83 83
 
84
-	ConstraintCheckerServices::QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ): QualifiersChecker {
84
+	ConstraintCheckerServices::QUALIFIERS_CHECKER => static function(MediaWikiServices $services): QualifiersChecker {
85 85
 		return new QualifiersChecker(
86
-			ConstraintsServices::getConstraintParameterParser( $services )
86
+			ConstraintsServices::getConstraintParameterParser($services)
87 87
 		);
88 88
 	},
89 89
 
90
-	ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function (
90
+	ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function(
91 91
 		MediaWikiServices $services
92 92
 	): MandatoryQualifiersChecker {
93 93
 		return new MandatoryQualifiersChecker(
94
-			ConstraintsServices::getConstraintParameterParser( $services )
94
+			ConstraintsServices::getConstraintParameterParser($services)
95 95
 		);
96 96
 	},
97 97
 
98
-	ConstraintCheckerServices::RANGE_CHECKER => static function ( MediaWikiServices $services ): RangeChecker {
98
+	ConstraintCheckerServices::RANGE_CHECKER => static function(MediaWikiServices $services): RangeChecker {
99 99
 		return new RangeChecker(
100
-			WikibaseRepo::getPropertyDataTypeLookup( $services ),
101
-			ConstraintsServices::getConstraintParameterParser( $services ),
102
-			ConstraintsServices::getRangeCheckerHelper( $services )
100
+			WikibaseRepo::getPropertyDataTypeLookup($services),
101
+			ConstraintsServices::getConstraintParameterParser($services),
102
+			ConstraintsServices::getRangeCheckerHelper($services)
103 103
 		);
104 104
 	},
105 105
 
106
-	ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function (
106
+	ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function(
107 107
 		MediaWikiServices $services
108 108
 	): DiffWithinRangeChecker {
109 109
 		return new DiffWithinRangeChecker(
110
-			ConstraintsServices::getConstraintParameterParser( $services ),
111
-			ConstraintsServices::getRangeCheckerHelper( $services ),
110
+			ConstraintsServices::getConstraintParameterParser($services),
111
+			ConstraintsServices::getRangeCheckerHelper($services),
112 112
 			$services->getMainConfig()
113 113
 		);
114 114
 	},
115 115
 
116
-	ConstraintCheckerServices::TYPE_CHECKER => static function ( MediaWikiServices $services ): TypeChecker {
116
+	ConstraintCheckerServices::TYPE_CHECKER => static function(MediaWikiServices $services): TypeChecker {
117 117
 		return new TypeChecker(
118
-			ConstraintsServices::getConstraintParameterParser( $services ),
119
-			ConstraintsServices::getTypeCheckerHelper( $services ),
118
+			ConstraintsServices::getConstraintParameterParser($services),
119
+			ConstraintsServices::getTypeCheckerHelper($services),
120 120
 			$services->getMainConfig()
121 121
 		);
122 122
 	},
123 123
 
124
-	ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function ( MediaWikiServices $services ): ValueTypeChecker {
124
+	ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function(MediaWikiServices $services): ValueTypeChecker {
125 125
 		return new ValueTypeChecker(
126
-			WikibaseServices::getEntityLookup( $services ),
127
-			ConstraintsServices::getConstraintParameterParser( $services ),
128
-			ConstraintsServices::getTypeCheckerHelper( $services ),
126
+			WikibaseServices::getEntityLookup($services),
127
+			ConstraintsServices::getConstraintParameterParser($services),
128
+			ConstraintsServices::getTypeCheckerHelper($services),
129 129
 			$services->getMainConfig()
130 130
 		);
131 131
 	},
132 132
 
133
-	ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function ( MediaWikiServices $services ): SingleValueChecker {
133
+	ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function(MediaWikiServices $services): SingleValueChecker {
134 134
 		return new SingleValueChecker(
135
-			ConstraintsServices::getConstraintParameterParser( $services )
135
+			ConstraintsServices::getConstraintParameterParser($services)
136 136
 		);
137 137
 	},
138 138
 
139
-	ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function ( MediaWikiServices $services ): MultiValueChecker {
139
+	ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function(MediaWikiServices $services): MultiValueChecker {
140 140
 		return new MultiValueChecker(
141
-			ConstraintsServices::getConstraintParameterParser( $services )
141
+			ConstraintsServices::getConstraintParameterParser($services)
142 142
 		);
143 143
 	},
144 144
 
145
-	ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function ( MediaWikiServices $services ): UniqueValueChecker {
145
+	ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function(MediaWikiServices $services): UniqueValueChecker {
146 146
 		// TODO return a different, dummy implementation if SPARQL is not available
147 147
 		return new UniqueValueChecker(
148
-			ConstraintsServices::getSparqlHelper( $services ),
149
-			ConstraintsServices::getConstraintParameterParser( $services )
148
+			ConstraintsServices::getSparqlHelper($services),
149
+			ConstraintsServices::getConstraintParameterParser($services)
150 150
 		);
151 151
 	},
152 152
 
153
-	ConstraintCheckerServices::FORMAT_CHECKER => static function ( MediaWikiServices $services ): FormatChecker {
153
+	ConstraintCheckerServices::FORMAT_CHECKER => static function(MediaWikiServices $services): FormatChecker {
154 154
 		// TODO return a different, dummy implementation if SPARQL is not available
155 155
 		return new FormatChecker(
156
-			ConstraintsServices::getConstraintParameterParser( $services ),
156
+			ConstraintsServices::getConstraintParameterParser($services),
157 157
 			$services->getMainConfig(),
158
-			ConstraintsServices::getSparqlHelper( $services ),
158
+			ConstraintsServices::getSparqlHelper($services),
159 159
 			$services->getShellboxClientFactory()
160 160
 		);
161 161
 	},
162 162
 
163
-	ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function ( MediaWikiServices $services ): CommonsLinkChecker {
163
+	ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function(MediaWikiServices $services): CommonsLinkChecker {
164 164
 		$pageNameNormalizer = new MediaWikiPageNameNormalizer();
165 165
 		return new CommonsLinkChecker(
166
-			ConstraintsServices::getConstraintParameterParser( $services ),
166
+			ConstraintsServices::getConstraintParameterParser($services),
167 167
 			$pageNameNormalizer,
168
-			WikibaseRepo::getPropertyDataTypeLookup( $services )
168
+			WikibaseRepo::getPropertyDataTypeLookup($services)
169 169
 		);
170 170
 	},
171 171
 
172
-	ConstraintCheckerServices::ONE_OF_CHECKER => static function ( MediaWikiServices $services ): OneOfChecker {
172
+	ConstraintCheckerServices::ONE_OF_CHECKER => static function(MediaWikiServices $services): OneOfChecker {
173 173
 		return new OneOfChecker(
174
-			ConstraintsServices::getConstraintParameterParser( $services )
174
+			ConstraintsServices::getConstraintParameterParser($services)
175 175
 		);
176 176
 	},
177 177
 
178
-	ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function ( MediaWikiServices $services ): ValueOnlyChecker {
178
+	ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function(MediaWikiServices $services): ValueOnlyChecker {
179 179
 		return new ValueOnlyChecker();
180 180
 	},
181 181
 
182
-	ConstraintCheckerServices::REFERENCE_CHECKER => static function ( MediaWikiServices $services ): ReferenceChecker {
182
+	ConstraintCheckerServices::REFERENCE_CHECKER => static function(MediaWikiServices $services): ReferenceChecker {
183 183
 		return new ReferenceChecker();
184 184
 	},
185 185
 
186
-	ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function ( MediaWikiServices $services ): NoBoundsChecker {
186
+	ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function(MediaWikiServices $services): NoBoundsChecker {
187 187
 		return new NoBoundsChecker();
188 188
 	},
189 189
 
190
-	ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function ( MediaWikiServices $services ): AllowedUnitsChecker {
190
+	ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function(MediaWikiServices $services): AllowedUnitsChecker {
191 191
 		return new AllowedUnitsChecker(
192
-			ConstraintsServices::getConstraintParameterParser( $services ),
193
-			WikibaseRepo::getUnitConverter( $services )
192
+			ConstraintsServices::getConstraintParameterParser($services),
193
+			WikibaseRepo::getUnitConverter($services)
194 194
 		);
195 195
 	},
196 196
 
197
-	ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function (
197
+	ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function(
198 198
 		MediaWikiServices $services
199 199
 	): SingleBestValueChecker {
200 200
 		return new SingleBestValueChecker(
201
-			ConstraintsServices::getConstraintParameterParser( $services )
201
+			ConstraintsServices::getConstraintParameterParser($services)
202 202
 		);
203 203
 	},
204 204
 
205
-	ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function ( MediaWikiServices $services ): EntityTypeChecker {
205
+	ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function(MediaWikiServices $services): EntityTypeChecker {
206 206
 		return new EntityTypeChecker(
207
-			ConstraintsServices::getConstraintParameterParser( $services )
207
+			ConstraintsServices::getConstraintParameterParser($services)
208 208
 		);
209 209
 	},
210 210
 
211
-	ConstraintCheckerServices::NONE_OF_CHECKER => static function ( MediaWikiServices $services ): NoneOfChecker {
211
+	ConstraintCheckerServices::NONE_OF_CHECKER => static function(MediaWikiServices $services): NoneOfChecker {
212 212
 		return new NoneOfChecker(
213
-			ConstraintsServices::getConstraintParameterParser( $services )
213
+			ConstraintsServices::getConstraintParameterParser($services)
214 214
 		);
215 215
 	},
216 216
 
217
-	ConstraintCheckerServices::INTEGER_CHECKER => static function ( MediaWikiServices $services ): IntegerChecker {
217
+	ConstraintCheckerServices::INTEGER_CHECKER => static function(MediaWikiServices $services): IntegerChecker {
218 218
 		return new IntegerChecker();
219 219
 	},
220 220
 
221
-	ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function ( MediaWikiServices $services ): CitationNeededChecker {
221
+	ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function(MediaWikiServices $services): CitationNeededChecker {
222 222
 		return new CitationNeededChecker();
223 223
 	},
224 224
 
225
-	ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function ( MediaWikiServices $services ): PropertyScopeChecker {
225
+	ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function(MediaWikiServices $services): PropertyScopeChecker {
226 226
 		return new PropertyScopeChecker(
227
-			ConstraintsServices::getConstraintParameterParser( $services )
227
+			ConstraintsServices::getConstraintParameterParser($services)
228 228
 		);
229 229
 	},
230 230
 
231
-	ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function ( MediaWikiServices $services ): ContemporaryChecker {
231
+	ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function(MediaWikiServices $services): ContemporaryChecker {
232 232
 		return new ContemporaryChecker(
233
-			WikibaseServices::getEntityLookup( $services ),
234
-			ConstraintsServices::getRangeCheckerHelper( $services ),
233
+			WikibaseServices::getEntityLookup($services),
234
+			ConstraintsServices::getRangeCheckerHelper($services),
235 235
 			$services->getMainConfig()
236 236
 		);
237 237
 	},
238 238
 
239
-	ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ): LanguageChecker {
239
+	ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function(MediaWikiServices $services): LanguageChecker {
240 240
 		return new LanguageChecker(
241
-			ConstraintsServices::getConstraintParameterParser( $services ),
242
-			WikibaseServices::getEntityLookup( $services )
241
+			ConstraintsServices::getConstraintParameterParser($services),
242
+			WikibaseServices::getEntityLookup($services)
243 243
 		);
244 244
 	},
245 245
 
246
-	ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function (
246
+	ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function(
247 247
 		MediaWikiServices $services
248 248
 	): LabelInLanguageChecker {
249 249
 		return new LabelInLanguageChecker(
250
-			ConstraintsServices::getConstraintParameterParser( $services )
250
+			ConstraintsServices::getConstraintParameterParser($services)
251 251
 		);
252 252
 	},
253 253
 ];
Please login to merge, or discard this patch.
src/WikibaseServices.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport;
6 6
 
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
 	public const ENTITY_LOOKUP = 'WBQC_EntityLookup';
26 26
 	public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache';
27 27
 
28
-	private static function getService( ?MediaWikiServices $services, $name ) {
28
+	private static function getService(?MediaWikiServices $services, $name) {
29 29
 		$services ??= MediaWikiServices::getInstance();
30
-		return $services->getService( $name );
30
+		return $services->getService($name);
31 31
 	}
32 32
 
33 33
 	/**
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	 * this lookup ignores exceptions (such as unresolved redirects, T93273),
38 38
 	 * as it is more convenient to treat them all as missing entities in WBQC.
39 39
 	 */
40
-	public static function getEntityLookup( ?MediaWikiServices $services = null ): EntityLookup {
41
-		return self::getService( $services, self::ENTITY_LOOKUP );
40
+	public static function getEntityLookup(?MediaWikiServices $services = null): EntityLookup {
41
+		return self::getService($services, self::ENTITY_LOOKUP);
42 42
 	}
43 43
 
44 44
 	/**
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 	 * were exceeding the request memory limit when they were all added to the cache (T227450).
49 49
 	 * Also, like {@link self::getEntityLookup()}, this lookup ignores exceptions.
50 50
 	 */
51
-	public static function getEntityLookupWithoutCache( ?MediaWikiServices $services = null ): EntityLookup {
52
-		return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE );
51
+	public static function getEntityLookupWithoutCache(?MediaWikiServices $services = null): EntityLookup {
52
+		return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE);
53 53
 	}
54 54
 
55 55
 }
Please login to merge, or discard this patch.
src/ConstraintCheckerServices.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -44,257 +44,257 @@
 block discarded – undo
44 44
 	public const LEXEME_LANGUAGE_CHECKER = 'WBQC_Lexeme_LanguageChecker';
45 45
 	public const LABEL_IN_LANGUAGE_CHECKER = 'WBQC_LabelInLanguageChecker';
46 46
 
47
-	private static function getService( ?MediaWikiServices $services, $name ) {
47
+	private static function getService(?MediaWikiServices $services, $name) {
48 48
 		$services ??= MediaWikiServices::getInstance();
49
-		return $services->getService( $name );
49
+		return $services->getService($name);
50 50
 	}
51 51
 
52 52
 	/**
53 53
 	 * @param MediaWikiServices|null $services
54 54
 	 * @return ConstraintChecker
55 55
 	 */
56
-	public static function getConflictsWithChecker( ?MediaWikiServices $services = null ) {
57
-		return self::getService( $services, self::CONFLICTS_WITH_CHECKER );
56
+	public static function getConflictsWithChecker(?MediaWikiServices $services = null) {
57
+		return self::getService($services, self::CONFLICTS_WITH_CHECKER);
58 58
 	}
59 59
 
60 60
 	/**
61 61
 	 * @param MediaWikiServices|null $services
62 62
 	 * @return ConstraintChecker
63 63
 	 */
64
-	public static function getItemChecker( ?MediaWikiServices $services = null ) {
65
-		return self::getService( $services, self::ITEM_CHECKER );
64
+	public static function getItemChecker(?MediaWikiServices $services = null) {
65
+		return self::getService($services, self::ITEM_CHECKER);
66 66
 	}
67 67
 
68 68
 	/**
69 69
 	 * @param MediaWikiServices|null $services
70 70
 	 * @return ConstraintChecker
71 71
 	 */
72
-	public static function getTargetRequiredClaimChecker( ?MediaWikiServices $services = null ) {
73
-		return self::getService( $services, self::TARGET_REQUIRED_CLAIM_CHECKER );
72
+	public static function getTargetRequiredClaimChecker(?MediaWikiServices $services = null) {
73
+		return self::getService($services, self::TARGET_REQUIRED_CLAIM_CHECKER);
74 74
 	}
75 75
 
76 76
 	/**
77 77
 	 * @param MediaWikiServices|null $services
78 78
 	 * @return ConstraintChecker
79 79
 	 */
80
-	public static function getSymmetricChecker( ?MediaWikiServices $services = null ) {
81
-		return self::getService( $services, self::SYMMETRIC_CHECKER );
80
+	public static function getSymmetricChecker(?MediaWikiServices $services = null) {
81
+		return self::getService($services, self::SYMMETRIC_CHECKER);
82 82
 	}
83 83
 
84 84
 	/**
85 85
 	 * @param MediaWikiServices|null $services
86 86
 	 * @return ConstraintChecker
87 87
 	 */
88
-	public static function getInverseChecker( ?MediaWikiServices $services = null ) {
89
-		return self::getService( $services, self::INVERSE_CHECKER );
88
+	public static function getInverseChecker(?MediaWikiServices $services = null) {
89
+		return self::getService($services, self::INVERSE_CHECKER);
90 90
 	}
91 91
 
92 92
 	/**
93 93
 	 * @param MediaWikiServices|null $services
94 94
 	 * @return ConstraintChecker
95 95
 	 */
96
-	public static function getQualifierChecker( ?MediaWikiServices $services = null ) {
97
-		return self::getService( $services, self::QUALIFIER_CHECKER );
96
+	public static function getQualifierChecker(?MediaWikiServices $services = null) {
97
+		return self::getService($services, self::QUALIFIER_CHECKER);
98 98
 	}
99 99
 
100 100
 	/**
101 101
 	 * @param MediaWikiServices|null $services
102 102
 	 * @return ConstraintChecker
103 103
 	 */
104
-	public static function getQualifiersChecker( ?MediaWikiServices $services = null ) {
105
-		return self::getService( $services, self::QUALIFIERS_CHECKER );
104
+	public static function getQualifiersChecker(?MediaWikiServices $services = null) {
105
+		return self::getService($services, self::QUALIFIERS_CHECKER);
106 106
 	}
107 107
 
108 108
 	/**
109 109
 	 * @param MediaWikiServices|null $services
110 110
 	 * @return ConstraintChecker
111 111
 	 */
112
-	public static function getMandatoryQualifiersChecker( ?MediaWikiServices $services = null ) {
113
-		return self::getService( $services, self::MANDATORY_QUALIFIERS_CHECKER );
112
+	public static function getMandatoryQualifiersChecker(?MediaWikiServices $services = null) {
113
+		return self::getService($services, self::MANDATORY_QUALIFIERS_CHECKER);
114 114
 	}
115 115
 
116 116
 	/**
117 117
 	 * @param MediaWikiServices|null $services
118 118
 	 * @return ConstraintChecker
119 119
 	 */
120
-	public static function getRangeChecker( ?MediaWikiServices $services = null ) {
121
-		return self::getService( $services, self::RANGE_CHECKER );
120
+	public static function getRangeChecker(?MediaWikiServices $services = null) {
121
+		return self::getService($services, self::RANGE_CHECKER);
122 122
 	}
123 123
 
124 124
 	/**
125 125
 	 * @param MediaWikiServices|null $services
126 126
 	 * @return ConstraintChecker
127 127
 	 */
128
-	public static function getDiffWithinRangeChecker( ?MediaWikiServices $services = null ) {
129
-		return self::getService( $services, self::DIFF_WITHIN_RANGE_CHECKER );
128
+	public static function getDiffWithinRangeChecker(?MediaWikiServices $services = null) {
129
+		return self::getService($services, self::DIFF_WITHIN_RANGE_CHECKER);
130 130
 	}
131 131
 
132 132
 	/**
133 133
 	 * @param MediaWikiServices|null $services
134 134
 	 * @return ConstraintChecker
135 135
 	 */
136
-	public static function getTypeChecker( ?MediaWikiServices $services = null ) {
137
-		return self::getService( $services, self::TYPE_CHECKER );
136
+	public static function getTypeChecker(?MediaWikiServices $services = null) {
137
+		return self::getService($services, self::TYPE_CHECKER);
138 138
 	}
139 139
 
140 140
 	/**
141 141
 	 * @param MediaWikiServices|null $services
142 142
 	 * @return ConstraintChecker
143 143
 	 */
144
-	public static function getValueTypeChecker( ?MediaWikiServices $services = null ) {
145
-		return self::getService( $services, self::VALUE_TYPE_CHECKER );
144
+	public static function getValueTypeChecker(?MediaWikiServices $services = null) {
145
+		return self::getService($services, self::VALUE_TYPE_CHECKER);
146 146
 	}
147 147
 
148 148
 	/**
149 149
 	 * @param MediaWikiServices|null $services
150 150
 	 * @return ConstraintChecker
151 151
 	 */
152
-	public static function getSingleValueChecker( ?MediaWikiServices $services = null ) {
153
-		return self::getService( $services, self::SINGLE_VALUE_CHECKER );
152
+	public static function getSingleValueChecker(?MediaWikiServices $services = null) {
153
+		return self::getService($services, self::SINGLE_VALUE_CHECKER);
154 154
 	}
155 155
 
156 156
 	/**
157 157
 	 * @param MediaWikiServices|null $services
158 158
 	 * @return ConstraintChecker
159 159
 	 */
160
-	public static function getMultiValueChecker( ?MediaWikiServices $services = null ) {
161
-		return self::getService( $services, self::MULTI_VALUE_CHECKER );
160
+	public static function getMultiValueChecker(?MediaWikiServices $services = null) {
161
+		return self::getService($services, self::MULTI_VALUE_CHECKER);
162 162
 	}
163 163
 
164 164
 	/**
165 165
 	 * @param MediaWikiServices|null $services
166 166
 	 * @return ConstraintChecker
167 167
 	 */
168
-	public static function getUniqueValueChecker( ?MediaWikiServices $services = null ) {
169
-		return self::getService( $services, self::UNIQUE_VALUE_CHECKER );
168
+	public static function getUniqueValueChecker(?MediaWikiServices $services = null) {
169
+		return self::getService($services, self::UNIQUE_VALUE_CHECKER);
170 170
 	}
171 171
 
172 172
 	/**
173 173
 	 * @param MediaWikiServices|null $services
174 174
 	 * @return ConstraintChecker
175 175
 	 */
176
-	public static function getFormatChecker( ?MediaWikiServices $services = null ) {
177
-		return self::getService( $services, self::FORMAT_CHECKER );
176
+	public static function getFormatChecker(?MediaWikiServices $services = null) {
177
+		return self::getService($services, self::FORMAT_CHECKER);
178 178
 	}
179 179
 
180 180
 	/**
181 181
 	 * @param MediaWikiServices|null $services
182 182
 	 * @return ConstraintChecker
183 183
 	 */
184
-	public static function getCommonsLinkChecker( ?MediaWikiServices $services = null ) {
185
-		return self::getService( $services, self::COMMONS_LINK_CHECKER );
184
+	public static function getCommonsLinkChecker(?MediaWikiServices $services = null) {
185
+		return self::getService($services, self::COMMONS_LINK_CHECKER);
186 186
 	}
187 187
 
188 188
 	/**
189 189
 	 * @param MediaWikiServices|null $services
190 190
 	 * @return ConstraintChecker
191 191
 	 */
192
-	public static function getOneOfChecker( ?MediaWikiServices $services = null ) {
193
-		return self::getService( $services, self::ONE_OF_CHECKER );
192
+	public static function getOneOfChecker(?MediaWikiServices $services = null) {
193
+		return self::getService($services, self::ONE_OF_CHECKER);
194 194
 	}
195 195
 
196 196
 	/**
197 197
 	 * @param MediaWikiServices|null $services
198 198
 	 * @return ConstraintChecker
199 199
 	 */
200
-	public static function getValueOnlyChecker( ?MediaWikiServices $services = null ) {
201
-		return self::getService( $services, self::VALUE_ONLY_CHECKER );
200
+	public static function getValueOnlyChecker(?MediaWikiServices $services = null) {
201
+		return self::getService($services, self::VALUE_ONLY_CHECKER);
202 202
 	}
203 203
 
204 204
 	/**
205 205
 	 * @param MediaWikiServices|null $services
206 206
 	 * @return ConstraintChecker
207 207
 	 */
208
-	public static function getReferenceChecker( ?MediaWikiServices $services = null ) {
209
-		return self::getService( $services, self::REFERENCE_CHECKER );
208
+	public static function getReferenceChecker(?MediaWikiServices $services = null) {
209
+		return self::getService($services, self::REFERENCE_CHECKER);
210 210
 	}
211 211
 
212 212
 	/**
213 213
 	 * @param MediaWikiServices|null $services
214 214
 	 * @return ConstraintChecker
215 215
 	 */
216
-	public static function getNoBoundsChecker( ?MediaWikiServices $services = null ) {
217
-		return self::getService( $services, self::NO_BOUNDS_CHECKER );
216
+	public static function getNoBoundsChecker(?MediaWikiServices $services = null) {
217
+		return self::getService($services, self::NO_BOUNDS_CHECKER);
218 218
 	}
219 219
 
220 220
 	/**
221 221
 	 * @param MediaWikiServices|null $services
222 222
 	 * @return ConstraintChecker
223 223
 	 */
224
-	public static function getAllowedUnitsChecker( ?MediaWikiServices $services = null ) {
225
-		return self::getService( $services, self::ALLOWED_UNITS_CHECKER );
224
+	public static function getAllowedUnitsChecker(?MediaWikiServices $services = null) {
225
+		return self::getService($services, self::ALLOWED_UNITS_CHECKER);
226 226
 	}
227 227
 
228 228
 	/**
229 229
 	 * @param MediaWikiServices|null $services
230 230
 	 * @return ConstraintChecker
231 231
 	 */
232
-	public static function getSingleBestValueChecker( ?MediaWikiServices $services = null ) {
233
-		return self::getService( $services, self::SINGLE_BEST_VALUE_CHECKER );
232
+	public static function getSingleBestValueChecker(?MediaWikiServices $services = null) {
233
+		return self::getService($services, self::SINGLE_BEST_VALUE_CHECKER);
234 234
 	}
235 235
 
236 236
 	/**
237 237
 	 * @param MediaWikiServices|null $services
238 238
 	 * @return ConstraintChecker
239 239
 	 */
240
-	public static function getEntityTypeChecker( ?MediaWikiServices $services = null ) {
241
-		return self::getService( $services, self::ENTITY_TYPE_CHECKER );
240
+	public static function getEntityTypeChecker(?MediaWikiServices $services = null) {
241
+		return self::getService($services, self::ENTITY_TYPE_CHECKER);
242 242
 	}
243 243
 
244 244
 	/**
245 245
 	 * @param MediaWikiServices|null $services
246 246
 	 * @return ConstraintChecker
247 247
 	 */
248
-	public static function getNoneOfChecker( ?MediaWikiServices $services = null ) {
249
-		return self::getService( $services, self::NONE_OF_CHECKER );
248
+	public static function getNoneOfChecker(?MediaWikiServices $services = null) {
249
+		return self::getService($services, self::NONE_OF_CHECKER);
250 250
 	}
251 251
 
252 252
 	/**
253 253
 	 * @param MediaWikiServices|null $services
254 254
 	 * @return ConstraintChecker
255 255
 	 */
256
-	public static function getIntegerChecker( ?MediaWikiServices $services = null ) {
257
-		return self::getService( $services, self::INTEGER_CHECKER );
256
+	public static function getIntegerChecker(?MediaWikiServices $services = null) {
257
+		return self::getService($services, self::INTEGER_CHECKER);
258 258
 	}
259 259
 
260 260
 	/**
261 261
 	 * @param MediaWikiServices|null $services
262 262
 	 * @return ConstraintChecker
263 263
 	 */
264
-	public static function getCitationNeededChecker( ?MediaWikiServices $services = null ) {
265
-		return self::getService( $services, self::CITATION_NEEDED_CHECKER );
264
+	public static function getCitationNeededChecker(?MediaWikiServices $services = null) {
265
+		return self::getService($services, self::CITATION_NEEDED_CHECKER);
266 266
 	}
267 267
 
268 268
 	/**
269 269
 	 * @param MediaWikiServices|null $services
270 270
 	 * @return ConstraintChecker
271 271
 	 */
272
-	public static function getPropertyScopeChecker( ?MediaWikiServices $services = null ) {
273
-		return self::getService( $services, self::PROPERTY_SCOPE_CHECKER );
272
+	public static function getPropertyScopeChecker(?MediaWikiServices $services = null) {
273
+		return self::getService($services, self::PROPERTY_SCOPE_CHECKER);
274 274
 	}
275 275
 
276 276
 	/**
277 277
 	 * @param MediaWikiServices|null $services
278 278
 	 * @return ConstraintChecker
279 279
 	 */
280
-	public static function getContemporaryChecker( ?MediaWikiServices $services = null ) {
281
-		return self::getService( $services, self::CONTEMPORARY_CHECKER );
280
+	public static function getContemporaryChecker(?MediaWikiServices $services = null) {
281
+		return self::getService($services, self::CONTEMPORARY_CHECKER);
282 282
 	}
283 283
 
284 284
 	/**
285 285
 	 * @param MediaWikiServices|null $services
286 286
 	 * @return LanguageChecker
287 287
 	 */
288
-	public static function getLexemeLanguageChecker( ?MediaWikiServices $services = null ) {
289
-		return self::getService( $services, self::LEXEME_LANGUAGE_CHECKER );
288
+	public static function getLexemeLanguageChecker(?MediaWikiServices $services = null) {
289
+		return self::getService($services, self::LEXEME_LANGUAGE_CHECKER);
290 290
 	}
291 291
 
292 292
 	/**
293 293
 	 * @param MediaWikiServices|null $services
294 294
 	 * @return LabelInLanguageChecker
295 295
 	 */
296
-	public static function getLabelInLanguageChecker( ?MediaWikiServices $services = null ) {
297
-		return self::getService( $services, self::LABEL_IN_LANGUAGE_CHECKER );
296
+	public static function getLabelInLanguageChecker(?MediaWikiServices $services = null) {
297
+		return self::getService($services, self::LABEL_IN_LANGUAGE_CHECKER);
298 298
 	}
299 299
 
300 300
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/DelegatingConstraintChecker.php 1 patch
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck;
6 6
 
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
 		?callable $defaultResultsPerEntity = null
124 124
 	): array {
125 125
 		$checkResults = [];
126
-		$entity = $this->entityLookup->getEntity( $entityId );
126
+		$entity = $this->entityLookup->getEntity($entityId);
127 127
 
128
-		if ( $entity instanceof StatementListProvidingEntity ) {
129
-			$startTime = microtime( true );
128
+		if ($entity instanceof StatementListProvidingEntity) {
129
+			$startTime = microtime(true);
130 130
 
131 131
 			$checkResults = $this->checkEveryStatement(
132 132
 				$entity,
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 				$defaultResultsPerContext
135 135
 			);
136 136
 
137
-			$endTime = microtime( true );
137
+			$endTime = microtime(true);
138 138
 
139
-			if ( $constraintIds === null ) { // only log full constraint checks
139
+			if ($constraintIds === null) { // only log full constraint checks
140 140
 				$this->loggingHelper->logConstraintCheckOnEntity(
141 141
 					$entityId,
142 142
 					$checkResults,
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 			}
147 147
 		}
148 148
 
149
-		if ( $defaultResultsPerEntity !== null ) {
150
-			$checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults );
149
+		if ($defaultResultsPerEntity !== null) {
150
+			$checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults);
151 151
 		}
152 152
 
153
-		return $this->sortResult( $checkResults );
153
+		return $this->sortResult($checkResults);
154 154
 	}
155 155
 
156 156
 	/**
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
 		?callable $defaultResults = null
173 173
 	): array {
174 174
 
175
-		$parsedGuid = $this->statementGuidParser->parse( $guid );
175
+		$parsedGuid = $this->statementGuidParser->parse($guid);
176 176
 		$entityId = $parsedGuid->getEntityId();
177
-		$entity = $this->entityLookup->getEntity( $entityId );
178
-		if ( $entity instanceof StatementListProvidingEntity ) {
179
-			$statement = $entity->getStatements()->getFirstStatementWithGuid( $guid );
180
-			if ( $statement ) {
177
+		$entity = $this->entityLookup->getEntity($entityId);
178
+		if ($entity instanceof StatementListProvidingEntity) {
179
+			$statement = $entity->getStatements()->getFirstStatementWithGuid($guid);
180
+			if ($statement) {
181 181
 				$result = $this->checkStatement(
182 182
 					$entity,
183 183
 					$statement,
184 184
 					$constraintIds,
185 185
 					$defaultResults
186 186
 				);
187
-				$output = $this->sortResult( $result );
187
+				$output = $this->sortResult($result);
188 188
 				return $output;
189 189
 			}
190 190
 		}
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
 		return [];
193 193
 	}
194 194
 
195
-	private function getValidContextTypes( Constraint $constraint ): array {
196
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
195
+	private function getValidContextTypes(Constraint $constraint): array {
196
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
197 197
 			return [
198 198
 				Context::TYPE_STATEMENT,
199 199
 				Context::TYPE_QUALIFIER,
@@ -201,21 +201,21 @@  discard block
 block discarded – undo
201 201
 			];
202 202
 		}
203 203
 
204
-		return array_keys( array_filter(
204
+		return array_keys(array_filter(
205 205
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(),
206
-			static fn ( $status ) => $status !== CheckResult::STATUS_NOT_IN_SCOPE
207
-		) );
206
+			static fn ($status) => $status !== CheckResult::STATUS_NOT_IN_SCOPE
207
+		));
208 208
 	}
209 209
 
210
-	private function getValidEntityTypes( Constraint $constraint ): array {
211
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
212
-			return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED );
210
+	private function getValidEntityTypes(Constraint $constraint): array {
211
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
212
+			return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED);
213 213
 		}
214 214
 
215
-		return array_keys( array_filter(
215
+		return array_keys(array_filter(
216 216
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(),
217
-			static fn ( $status ) => $status !== CheckResult::STATUS_NOT_IN_SCOPE
218
-		) );
217
+			static fn ($status) => $status !== CheckResult::STATUS_NOT_IN_SCOPE
218
+		));
219 219
 	}
220 220
 
221 221
 	/**
@@ -226,38 +226,38 @@  discard block
 block discarded – undo
226 226
 	 *
227 227
 	 * @return ConstraintParameterException[]
228 228
 	 */
229
-	private function checkCommonConstraintParameters( Constraint $constraint ): array {
229
+	private function checkCommonConstraintParameters(Constraint $constraint): array {
230 230
 		$constraintParameters = $constraint->getConstraintParameters();
231 231
 		try {
232
-			$this->constraintParameterParser->checkError( $constraintParameters );
233
-		} catch ( ConstraintParameterException $e ) {
234
-			return [ $e ];
232
+			$this->constraintParameterParser->checkError($constraintParameters);
233
+		} catch (ConstraintParameterException $e) {
234
+			return [$e];
235 235
 		}
236 236
 
237 237
 		$problems = [];
238 238
 		try {
239
-			$this->constraintParameterParser->parseExceptionParameter( $constraintParameters );
240
-		} catch ( ConstraintParameterException $e ) {
239
+			$this->constraintParameterParser->parseExceptionParameter($constraintParameters);
240
+		} catch (ConstraintParameterException $e) {
241 241
 			$problems[] = $e;
242 242
 		}
243 243
 		try {
244
-			$this->constraintParameterParser->parseConstraintClarificationParameter( $constraintParameters );
245
-		} catch ( ConstraintParameterException $e ) {
244
+			$this->constraintParameterParser->parseConstraintClarificationParameter($constraintParameters);
245
+		} catch (ConstraintParameterException $e) {
246 246
 			$problems[] = $e;
247 247
 		}
248 248
 		try {
249
-			$this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters );
250
-		} catch ( ConstraintParameterException $e ) {
249
+			$this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters);
250
+		} catch (ConstraintParameterException $e) {
251 251
 			$problems[] = $e;
252 252
 		}
253 253
 		try {
254 254
 			$this->constraintParameterParser->parseConstraintScopeParameters(
255 255
 				$constraintParameters,
256 256
 				$constraint->getConstraintTypeItemId(),
257
-				$this->getValidContextTypes( $constraint ),
258
-				$this->getValidEntityTypes( $constraint )
257
+				$this->getValidContextTypes($constraint),
258
+				$this->getValidEntityTypes($constraint)
259 259
 			);
260
-		} catch ( ConstraintParameterException $e ) {
260
+		} catch (ConstraintParameterException $e) {
261 261
 			$problems[] = $e;
262 262
 		}
263 263
 		return $problems;
@@ -270,16 +270,16 @@  discard block
 block discarded – undo
270 270
 	 * @return ConstraintParameterException[][] first level indexed by constraint ID,
271 271
 	 * second level like checkConstraintParametersOnConstraintId (but without possibility of null)
272 272
 	 */
273
-	public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ): array {
274
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
273
+	public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId): array {
274
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
275 275
 		$result = [];
276 276
 
277
-		foreach ( $constraints as $constraint ) {
278
-			$problems = $this->checkCommonConstraintParameters( $constraint );
277
+		foreach ($constraints as $constraint) {
278
+			$problems = $this->checkCommonConstraintParameters($constraint);
279 279
 
280
-			if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
280
+			if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
281 281
 				$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
282
-				$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
282
+				$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
283 283
 			}
284 284
 
285 285
 			$result[$constraint->getConstraintId()] = $problems;
@@ -296,18 +296,18 @@  discard block
 block discarded – undo
296 296
 	 * @return ConstraintParameterException[]|null list of constraint parameter exceptions
297 297
 	 * (empty means all parameters okay), or null if constraint is not found
298 298
 	 */
299
-	public function checkConstraintParametersOnConstraintId( string $constraintId ): ?array {
300
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
299
+	public function checkConstraintParametersOnConstraintId(string $constraintId): ?array {
300
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
301 301
 		'@phan-var NumericPropertyId $propertyId';
302
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
302
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
303 303
 
304
-		foreach ( $constraints as $constraint ) {
305
-			if ( $constraint->getConstraintId() === $constraintId ) {
306
-				$problems = $this->checkCommonConstraintParameters( $constraint );
304
+		foreach ($constraints as $constraint) {
305
+			if ($constraint->getConstraintId() === $constraintId) {
306
+				$problems = $this->checkCommonConstraintParameters($constraint);
307 307
 
308
-				if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
308
+				if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
309 309
 					$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
310
-					$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
310
+					$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
311 311
 				}
312 312
 
313 313
 				return $problems;
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
 		$result = [];
333 333
 
334 334
 		/** @var Statement $statement */
335
-		foreach ( $entity->getStatements() as $statement ) {
336
-			$result = array_merge( $result,
335
+		foreach ($entity->getStatements() as $statement) {
336
+			$result = array_merge($result,
337 337
 				$this->checkStatement(
338 338
 					$entity,
339 339
 					$statement,
340 340
 					$constraintIds,
341 341
 					$defaultResultsPerContext
342
-				) );
342
+				));
343 343
 		}
344 344
 
345 345
 		return $result;
@@ -361,32 +361,32 @@  discard block
 block discarded – undo
361 361
 	): array {
362 362
 		$result = [];
363 363
 
364
-		$result = array_merge( $result,
364
+		$result = array_merge($result,
365 365
 			$this->checkConstraintsForMainSnak(
366 366
 				$entity,
367 367
 				$statement,
368 368
 				$constraintIds,
369 369
 				$defaultResultsPerContext
370
-			) );
370
+			));
371 371
 
372
-		if ( $this->checkQualifiers ) {
373
-			$result = array_merge( $result,
372
+		if ($this->checkQualifiers) {
373
+			$result = array_merge($result,
374 374
 				$this->checkConstraintsForQualifiers(
375 375
 					$entity,
376 376
 					$statement,
377 377
 					$constraintIds,
378 378
 					$defaultResultsPerContext
379
-				) );
379
+				));
380 380
 		}
381 381
 
382
-		if ( $this->checkReferences ) {
383
-			$result = array_merge( $result,
382
+		if ($this->checkReferences) {
383
+			$result = array_merge($result,
384 384
 				$this->checkConstraintsForReferences(
385 385
 					$entity,
386 386
 					$statement,
387 387
 					$constraintIds,
388 388
 					$defaultResultsPerContext
389
-				) );
389
+				));
390 390
 		}
391 391
 
392 392
 		return $result;
@@ -401,17 +401,17 @@  discard block
 block discarded – undo
401 401
 	 * @param string[]|null $constraintIds
402 402
 	 * @return Constraint[]
403 403
 	 */
404
-	private function getConstraintsToUse( PropertyId $propertyId, ?array $constraintIds ): array {
405
-		if ( !( $propertyId instanceof NumericPropertyId ) ) {
404
+	private function getConstraintsToUse(PropertyId $propertyId, ?array $constraintIds): array {
405
+		if (!($propertyId instanceof NumericPropertyId)) {
406 406
 			throw new InvalidArgumentException(
407
-				'Non-numeric property ID not supported:' . $propertyId->getSerialization()
407
+				'Non-numeric property ID not supported:'.$propertyId->getSerialization()
408 408
 			);
409 409
 		}
410
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
411
-		if ( $constraintIds !== null ) {
410
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
411
+		if ($constraintIds !== null) {
412 412
 			$constraintsToUse = [];
413
-			foreach ( $constraints as $constraint ) {
414
-				if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) {
413
+			foreach ($constraints as $constraint) {
414
+				if (in_array($constraint->getConstraintId(), $constraintIds)) {
415 415
 					$constraintsToUse[] = $constraint;
416 416
 				}
417 417
 			}
@@ -435,18 +435,18 @@  discard block
 block discarded – undo
435 435
 		?array $constraintIds,
436 436
 		?callable $defaultResults
437 437
 	): array {
438
-		$context = new MainSnakContext( $entity, $statement );
438
+		$context = new MainSnakContext($entity, $statement);
439 439
 		$constraints = $this->getConstraintsToUse(
440 440
 			$statement->getPropertyId(),
441 441
 			$constraintIds
442 442
 		);
443
-		$result = $defaultResults !== null ? $defaultResults( $context ) : [];
443
+		$result = $defaultResults !== null ? $defaultResults($context) : [];
444 444
 
445
-		foreach ( $constraints as $constraint ) {
445
+		foreach ($constraints as $constraint) {
446 446
 			$parameters = $constraint->getConstraintParameters();
447 447
 			try {
448
-				$exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters );
449
-			} catch ( ConstraintParameterException $e ) {
448
+				$exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters);
449
+			} catch (ConstraintParameterException $e) {
450 450
 				$result[] = new CheckResult(
451 451
 					$context,
452 452
 					$constraint,
@@ -456,13 +456,13 @@  discard block
 block discarded – undo
456 456
 				continue;
457 457
 			}
458 458
 
459
-			if ( in_array( $entity->getId(), $exceptions ) ) {
460
-				$message = new ViolationMessage( 'wbqc-violation-message-exception' );
461
-				$result[] = new CheckResult( $context, $constraint, CheckResult::STATUS_EXCEPTION, $message );
459
+			if (in_array($entity->getId(), $exceptions)) {
460
+				$message = new ViolationMessage('wbqc-violation-message-exception');
461
+				$result[] = new CheckResult($context, $constraint, CheckResult::STATUS_EXCEPTION, $message);
462 462
 				continue;
463 463
 			}
464 464
 
465
-			$result[] = $this->getCheckResultFor( $context, $constraint );
465
+			$result[] = $this->getCheckResultFor($context, $constraint);
466 466
 		}
467 467
 
468 468
 		return $result;
@@ -484,24 +484,24 @@  discard block
 block discarded – undo
484 484
 	): array {
485 485
 		$result = [];
486 486
 
487
-		if ( in_array(
487
+		if (in_array(
488 488
 			$statement->getPropertyId()->getSerialization(),
489 489
 			$this->propertiesWithViolatingQualifiers
490
-		) ) {
490
+		)) {
491 491
 			return $result;
492 492
 		}
493 493
 
494
-		foreach ( $statement->getQualifiers() as $qualifier ) {
495
-			$qualifierContext = new QualifierContext( $entity, $statement, $qualifier );
496
-			if ( $defaultResultsPerContext !== null ) {
497
-				$result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) );
494
+		foreach ($statement->getQualifiers() as $qualifier) {
495
+			$qualifierContext = new QualifierContext($entity, $statement, $qualifier);
496
+			if ($defaultResultsPerContext !== null) {
497
+				$result = array_merge($result, $defaultResultsPerContext($qualifierContext));
498 498
 			}
499 499
 			$qualifierConstraints = $this->getConstraintsToUse(
500 500
 				$qualifierContext->getSnak()->getPropertyId(),
501 501
 				$constraintIds
502 502
 			);
503
-			foreach ( $qualifierConstraints as $qualifierConstraint ) {
504
-				$result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint );
503
+			foreach ($qualifierConstraints as $qualifierConstraint) {
504
+				$result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint);
505 505
 			}
506 506
 		}
507 507
 
@@ -525,19 +525,19 @@  discard block
 block discarded – undo
525 525
 		$result = [];
526 526
 
527 527
 		/** @var Reference $reference */
528
-		foreach ( $statement->getReferences() as $reference ) {
529
-			foreach ( $reference->getSnaks() as $snak ) {
528
+		foreach ($statement->getReferences() as $reference) {
529
+			foreach ($reference->getSnaks() as $snak) {
530 530
 				$referenceContext = new ReferenceContext(
531 531
 					$entity, $statement, $reference, $snak
532 532
 				);
533
-				if ( $defaultResultsPerContext !== null ) {
534
-					$result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) );
533
+				if ($defaultResultsPerContext !== null) {
534
+					$result = array_merge($result, $defaultResultsPerContext($referenceContext));
535 535
 				}
536 536
 				$referenceConstraints = $this->getConstraintsToUse(
537 537
 					$referenceContext->getSnak()->getPropertyId(),
538 538
 					$constraintIds
539 539
 				);
540
-				foreach ( $referenceConstraints as $referenceConstraint ) {
540
+				foreach ($referenceConstraints as $referenceConstraint) {
541 541
 					$result[] = $this->getCheckResultFor(
542 542
 						$referenceContext,
543 543
 						$referenceConstraint
@@ -549,50 +549,50 @@  discard block
 block discarded – undo
549 549
 		return $result;
550 550
 	}
551 551
 
552
-	private function getCheckResultFor( Context $context, Constraint $constraint ): CheckResult {
553
-		if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
552
+	private function getCheckResultFor(Context $context, Constraint $constraint): CheckResult {
553
+		if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
554 554
 			$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
555
-			$result = $this->handleScope( $checker, $context, $constraint );
555
+			$result = $this->handleScope($checker, $context, $constraint);
556 556
 
557
-			if ( $result !== null ) {
558
-				$this->addMetadata( $context, $result );
557
+			if ($result !== null) {
558
+				$this->addMetadata($context, $result);
559 559
 				return $result;
560 560
 			}
561 561
 
562
-			$startTime = microtime( true );
562
+			$startTime = microtime(true);
563 563
 			try {
564
-				$result = $checker->checkConstraint( $context, $constraint );
565
-			} catch ( ConstraintParameterException $e ) {
564
+				$result = $checker->checkConstraint($context, $constraint);
565
+			} catch (ConstraintParameterException $e) {
566 566
 				$result = new CheckResult(
567 567
 					$context,
568 568
 					$constraint,
569 569
 					CheckResult::STATUS_BAD_PARAMETERS,
570 570
 					$e->getViolationMessage()
571 571
 				);
572
-			} catch ( SparqlHelperException $e ) {
573
-				$message = new ViolationMessage( 'wbqc-violation-message-sparql-error' );
574
-				$result = new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, $message );
572
+			} catch (SparqlHelperException $e) {
573
+				$message = new ViolationMessage('wbqc-violation-message-sparql-error');
574
+				$result = new CheckResult($context, $constraint, CheckResult::STATUS_TODO, $message);
575 575
 			}
576
-			$endTime = microtime( true );
576
+			$endTime = microtime(true);
577 577
 
578
-			$this->addMetadata( $context, $result );
578
+			$this->addMetadata($context, $result);
579 579
 
580
-			$this->addConstraintClarification( $result );
580
+			$this->addConstraintClarification($result);
581 581
 
582
-			$this->downgradeResultStatus( $result );
582
+			$this->downgradeResultStatus($result);
583 583
 
584 584
 			$this->loggingHelper->logConstraintCheck(
585 585
 				$context,
586 586
 				$constraint,
587 587
 				$result,
588
-				get_class( $checker ),
588
+				get_class($checker),
589 589
 				$endTime - $startTime,
590 590
 				__METHOD__
591 591
 			);
592 592
 
593 593
 			return $result;
594 594
 		} else {
595
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null );
595
+			return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null);
596 596
 		}
597 597
 	}
598 598
 
@@ -601,87 +601,87 @@  discard block
 block discarded – undo
601 601
 		Context $context,
602 602
 		Constraint $constraint
603 603
 	): ?CheckResult {
604
-		$validContextTypes = $this->getValidContextTypes( $constraint );
605
-		$validEntityTypes = $this->getValidEntityTypes( $constraint );
604
+		$validContextTypes = $this->getValidContextTypes($constraint);
605
+		$validEntityTypes = $this->getValidEntityTypes($constraint);
606 606
 		try {
607
-			[ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters(
607
+			[$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters(
608 608
 				$constraint->getConstraintParameters(),
609 609
 				$constraint->getConstraintTypeItemId(),
610 610
 				$validContextTypes,
611 611
 				$validEntityTypes
612 612
 			);
613
-		} catch ( ConstraintParameterException $e ) {
614
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
613
+		} catch (ConstraintParameterException $e) {
614
+			return new CheckResult($context, $constraint, CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
615 615
 		}
616 616
 
617 617
 		$checkedContextTypes ??= $checker->getDefaultContextTypes();
618 618
 		$contextType = $context->getType();
619
-		if ( !in_array( $contextType, $checkedContextTypes ) ) {
620
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null );
619
+		if (!in_array($contextType, $checkedContextTypes)) {
620
+			return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null);
621 621
 		}
622
-		if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) {
623
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null );
622
+		if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) {
623
+			return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null);
624 624
 		}
625 625
 
626 626
 		$checkedEntityTypes ??= $validEntityTypes;
627 627
 		$entityType = $context->getEntity()->getType();
628
-		if ( !in_array( $entityType, $checkedEntityTypes ) ) {
629
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null );
628
+		if (!in_array($entityType, $checkedEntityTypes)) {
629
+			return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null);
630 630
 		}
631
-		if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) {
632
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null );
631
+		if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) {
632
+			return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null);
633 633
 		}
634 634
 
635 635
 		return null;
636 636
 	}
637 637
 
638
-	private function addMetadata( Context $context, CheckResult $result ): void {
639
-		$result->withMetadata( Metadata::merge( [
638
+	private function addMetadata(Context $context, CheckResult $result): void {
639
+		$result->withMetadata(Metadata::merge([
640 640
 			$result->getMetadata(),
641
-			Metadata::ofDependencyMetadata( DependencyMetadata::merge( [
642
-				DependencyMetadata::ofEntityId( $context->getEntity()->getId() ),
643
-				DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ),
644
-			] ) ),
645
-		] ) );
641
+			Metadata::ofDependencyMetadata(DependencyMetadata::merge([
642
+				DependencyMetadata::ofEntityId($context->getEntity()->getId()),
643
+				DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()),
644
+			])),
645
+		]));
646 646
 	}
647 647
 
648
-	private function addConstraintClarification( CheckResult $result ): void {
648
+	private function addConstraintClarification(CheckResult $result): void {
649 649
 		$constraint = $result->getConstraint();
650 650
 		try {
651 651
 			$constraintClarification = $this->constraintParameterParser
652
-				->parseConstraintClarificationParameter( $constraint->getConstraintParameters() );
653
-			$result->setConstraintClarification( $constraintClarification );
654
-		} catch ( ConstraintParameterException $e ) {
655
-			$result->setStatus( CheckResult::STATUS_BAD_PARAMETERS );
656
-			$result->setMessage( $e->getViolationMessage() );
652
+				->parseConstraintClarificationParameter($constraint->getConstraintParameters());
653
+			$result->setConstraintClarification($constraintClarification);
654
+		} catch (ConstraintParameterException $e) {
655
+			$result->setStatus(CheckResult::STATUS_BAD_PARAMETERS);
656
+			$result->setMessage($e->getViolationMessage());
657 657
 		}
658 658
 	}
659 659
 
660
-	private function downgradeResultStatus( CheckResult $result ): void {
660
+	private function downgradeResultStatus(CheckResult $result): void {
661 661
 		$constraint = $result->getConstraint();
662 662
 		try {
663 663
 			$constraintStatus = $this->constraintParameterParser
664
-				->parseConstraintStatusParameter( $constraint->getConstraintParameters() );
665
-		} catch ( ConstraintParameterException $e ) {
666
-			$result->setStatus( CheckResult::STATUS_BAD_PARAMETERS );
667
-			$result->setMessage( $e->getViolationMessage() );
664
+				->parseConstraintStatusParameter($constraint->getConstraintParameters());
665
+		} catch (ConstraintParameterException $e) {
666
+			$result->setStatus(CheckResult::STATUS_BAD_PARAMETERS);
667
+			$result->setMessage($e->getViolationMessage());
668 668
 			return;
669 669
 		}
670
-		if ( $constraintStatus === null ) {
670
+		if ($constraintStatus === null) {
671 671
 			// downgrade violation to warning
672
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
673
-				$result->setStatus( CheckResult::STATUS_WARNING );
672
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
673
+				$result->setStatus(CheckResult::STATUS_WARNING);
674 674
 			}
675
-		} elseif ( $constraintStatus === 'suggestion' ) {
675
+		} elseif ($constraintStatus === 'suggestion') {
676 676
 			// downgrade violation to suggestion
677
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
678
-				$result->setStatus( CheckResult::STATUS_SUGGESTION );
677
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
678
+				$result->setStatus(CheckResult::STATUS_SUGGESTION);
679 679
 			}
680 680
 		} else {
681
-			if ( $constraintStatus !== 'mandatory' ) {
681
+			if ($constraintStatus !== 'mandatory') {
682 682
 				// @codeCoverageIgnoreStart
683 683
 				throw new LogicException(
684
-					"Unknown constraint status '$constraintStatus', " .
684
+					"Unknown constraint status '$constraintStatus', ".
685 685
 					"only known statuses are 'mandatory' and 'suggestion'"
686 686
 				);
687 687
 				// @codeCoverageIgnoreEnd
@@ -694,12 +694,12 @@  discard block
 block discarded – undo
694 694
 	 *
695 695
 	 * @return CheckResult[]
696 696
 	 */
697
-	private function sortResult( array $result ): array {
698
-		if ( count( $result ) < 2 ) {
697
+	private function sortResult(array $result): array {
698
+		if (count($result) < 2) {
699 699
 			return $result;
700 700
 		}
701 701
 
702
-		$sortFunction = static function ( CheckResult $a, CheckResult $b ) {
702
+		$sortFunction = static function(CheckResult $a, CheckResult $b) {
703 703
 			$orderNum = 0;
704 704
 			$order = [
705 705
 				CheckResult::STATUS_BAD_PARAMETERS => $orderNum++,
@@ -716,55 +716,55 @@  discard block
 block discarded – undo
716 716
 			$statusA = $a->getStatus();
717 717
 			$statusB = $b->getStatus();
718 718
 
719
-			$orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ];
720
-			$orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ];
719
+			$orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other'];
720
+			$orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other'];
721 721
 
722
-			if ( $orderA === $orderB ) {
722
+			if ($orderA === $orderB) {
723 723
 				$cursorA = $a->getContextCursor();
724 724
 				$cursorB = $b->getContextCursor();
725 725
 
726
-				if ( $cursorA instanceof EntityContextCursor ) {
726
+				if ($cursorA instanceof EntityContextCursor) {
727 727
 					return $cursorB instanceof EntityContextCursor ? 0 : -1;
728 728
 				}
729
-				if ( $cursorB instanceof EntityContextCursor ) {
729
+				if ($cursorB instanceof EntityContextCursor) {
730 730
 					return $cursorA instanceof EntityContextCursor ? 0 : 1;
731 731
 				}
732 732
 
733 733
 				$pidA = $cursorA->getSnakPropertyId();
734 734
 				$pidB = $cursorB->getSnakPropertyId();
735 735
 
736
-				if ( $pidA === $pidB ) {
736
+				if ($pidA === $pidB) {
737 737
 					$hashA = $cursorA->getSnakHash();
738 738
 					$hashB = $cursorB->getSnakHash();
739 739
 
740
-					if ( $hashA === $hashB ) {
741
-						if ( $a instanceof NullResult ) {
740
+					if ($hashA === $hashB) {
741
+						if ($a instanceof NullResult) {
742 742
 							return $b instanceof NullResult ? 0 : -1;
743 743
 						}
744
-						if ( $b instanceof NullResult ) {
744
+						if ($b instanceof NullResult) {
745 745
 							return $a instanceof NullResult ? 0 : 1;
746 746
 						}
747 747
 
748 748
 						$typeA = $a->getConstraint()->getConstraintTypeItemId();
749 749
 						$typeB = $b->getConstraint()->getConstraintTypeItemId();
750 750
 
751
-						if ( $typeA == $typeB ) {
751
+						if ($typeA == $typeB) {
752 752
 							return 0;
753 753
 						} else {
754
-							return ( $typeA > $typeB ) ? 1 : -1;
754
+							return ($typeA > $typeB) ? 1 : -1;
755 755
 						}
756 756
 					} else {
757
-						return ( $hashA > $hashB ) ? 1 : -1;
757
+						return ($hashA > $hashB) ? 1 : -1;
758 758
 					}
759 759
 				} else {
760
-					return ( $pidA > $pidB ) ? 1 : -1;
760
+					return ($pidA > $pidB) ? 1 : -1;
761 761
 				}
762 762
 			} else {
763
-				return ( $orderA > $orderB ) ? 1 : -1;
763
+				return ($orderA > $orderB) ? 1 : -1;
764 764
 			}
765 765
 		};
766 766
 
767
-		uasort( $result, $sortFunction );
767
+		uasort($result, $sortFunction);
768 768
 
769 769
 		return $result;
770 770
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/ConstraintParameterParser.php 1 patch
Spacing   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper;
6 6
 
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 	 * Check if any errors are recorded in the constraint parameters.
69 69
 	 * @throws ConstraintParameterException
70 70
 	 */
71
-	public function checkError( array $parameters ): void {
72
-		if ( array_key_exists( '@error', $parameters ) ) {
71
+	public function checkError(array $parameters): void {
72
+		if (array_key_exists('@error', $parameters)) {
73 73
 			$error = $parameters['@error'];
74
-			if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) {
74
+			if (array_key_exists('toolong', $error) && $error['toolong']) {
75 75
 				$msg = 'wbqc-violation-message-parameters-error-toolong';
76 76
 			} else {
77 77
 				$msg = 'wbqc-violation-message-parameters-error-unknown';
78 78
 			}
79
-			throw new ConstraintParameterException( new ViolationMessage( $msg ) );
79
+			throw new ConstraintParameterException(new ViolationMessage($msg));
80 80
 		}
81 81
 	}
82 82
 
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
 	 * Require that $parameters contains exactly one $parameterId parameter.
85 85
 	 * @throws ConstraintParameterException
86 86
 	 */
87
-	private function requireSingleParameter( array $parameters, string $parameterId ): void {
88
-		if ( count( $parameters[$parameterId] ) !== 1 ) {
87
+	private function requireSingleParameter(array $parameters, string $parameterId): void {
88
+		if (count($parameters[$parameterId]) !== 1) {
89 89
 			throw new ConstraintParameterException(
90
-				( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) )
91
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
90
+				(new ViolationMessage('wbqc-violation-message-parameter-single'))
91
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
92 92
 			);
93 93
 		}
94 94
 	}
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * Require that $snak is a {@link PropertyValueSnak}.
98 98
 	 * @throws ConstraintParameterException
99 99
 	 */
100
-	private function requireValueParameter( Snak $snak, string $parameterId ): void {
101
-		if ( !( $snak instanceof PropertyValueSnak ) ) {
100
+	private function requireValueParameter(Snak $snak, string $parameterId): void {
101
+		if (!($snak instanceof PropertyValueSnak)) {
102 102
 			throw new ConstraintParameterException(
103
-				( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) )
104
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
103
+				(new ViolationMessage('wbqc-violation-message-parameter-value'))
104
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
105 105
 			);
106 106
 		}
107 107
 	}
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
 	 * Parse a single entity ID parameter.
111 111
 	 * @throws ConstraintParameterException
112 112
 	 */
113
-	private function parseEntityIdParameter( array $snakSerialization, string $parameterId ): EntityId {
114
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
115
-		$this->requireValueParameter( $snak, $parameterId );
113
+	private function parseEntityIdParameter(array $snakSerialization, string $parameterId): EntityId {
114
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
115
+		$this->requireValueParameter($snak, $parameterId);
116 116
 		$value = $snak->getDataValue();
117
-		if ( $value instanceof EntityIdValue ) {
117
+		if ($value instanceof EntityIdValue) {
118 118
 			return $value->getEntityId();
119 119
 		} else {
120 120
 			throw new ConstraintParameterException(
121
-				( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) )
122
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
123
-					->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
121
+				(new ViolationMessage('wbqc-violation-message-parameter-entity'))
122
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
123
+					->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
124 124
 			);
125 125
 		}
126 126
 	}
@@ -131,20 +131,20 @@  discard block
 block discarded – undo
131 131
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
132 132
 	 * @return string[] class entity ID serializations
133 133
 	 */
134
-	public function parseClassParameter( array $constraintParameters, string $constraintTypeItemId ): array {
135
-		$this->checkError( $constraintParameters );
136
-		$classId = $this->config->get( 'WBQualityConstraintsClassId' );
137
-		if ( !array_key_exists( $classId, $constraintParameters ) ) {
134
+	public function parseClassParameter(array $constraintParameters, string $constraintTypeItemId): array {
135
+		$this->checkError($constraintParameters);
136
+		$classId = $this->config->get('WBQualityConstraintsClassId');
137
+		if (!array_key_exists($classId, $constraintParameters)) {
138 138
 			throw new ConstraintParameterException(
139
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
140
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
141
-					->withEntityId( new NumericPropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
139
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
140
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
141
+					->withEntityId(new NumericPropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY)
142 142
 			);
143 143
 		}
144 144
 
145 145
 		$classes = [];
146
-		foreach ( $constraintParameters[$classId] as $class ) {
147
-			$classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization();
146
+		foreach ($constraintParameters[$classId] as $class) {
147
+			$classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization();
148 148
 		}
149 149
 		return $classes;
150 150
 	}
@@ -155,31 +155,31 @@  discard block
 block discarded – undo
155 155
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
156 156
 	 * @return string 'instance', 'subclass', or 'instanceOrSubclass'
157 157
 	 */
158
-	public function parseRelationParameter( array $constraintParameters, string $constraintTypeItemId ): string {
159
-		$this->checkError( $constraintParameters );
160
-		$relationId = $this->config->get( 'WBQualityConstraintsRelationId' );
161
-		if ( !array_key_exists( $relationId, $constraintParameters ) ) {
158
+	public function parseRelationParameter(array $constraintParameters, string $constraintTypeItemId): string {
159
+		$this->checkError($constraintParameters);
160
+		$relationId = $this->config->get('WBQualityConstraintsRelationId');
161
+		if (!array_key_exists($relationId, $constraintParameters)) {
162 162
 			throw new ConstraintParameterException(
163
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
164
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
165
-					->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
163
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
164
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
165
+					->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY)
166 166
 			);
167 167
 		}
168 168
 
169
-		$this->requireSingleParameter( $constraintParameters, $relationId );
170
-		$relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId );
171
-		if ( !( $relationEntityId instanceof ItemId ) ) {
169
+		$this->requireSingleParameter($constraintParameters, $relationId);
170
+		$relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId);
171
+		if (!($relationEntityId instanceof ItemId)) {
172 172
 			throw new ConstraintParameterException(
173
-				( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) )
174
-					->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
175
-					->withDataValue( new EntityIdValue( $relationEntityId ), Role::CONSTRAINT_PARAMETER_VALUE )
173
+				(new ViolationMessage('wbqc-violation-message-parameter-item'))
174
+					->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY)
175
+					->withDataValue(new EntityIdValue($relationEntityId), Role::CONSTRAINT_PARAMETER_VALUE)
176 176
 			);
177 177
 		}
178
-		return $this->mapItemId( $relationEntityId, [
179
-			$this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ) => 'instance',
180
-			$this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ) => 'subclass',
181
-			$this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ) => 'instanceOrSubclass',
182
-		], $relationId );
178
+		return $this->mapItemId($relationEntityId, [
179
+			$this->config->get('WBQualityConstraintsInstanceOfRelationId') => 'instance',
180
+			$this->config->get('WBQualityConstraintsSubclassOfRelationId') => 'subclass',
181
+			$this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId') => 'instanceOrSubclass',
182
+		], $relationId);
183 183
 	}
184 184
 
185 185
 	/**
@@ -189,20 +189,20 @@  discard block
 block discarded – undo
189 189
 	 * @throws ConstraintParameterException
190 190
 	 * @return PropertyId
191 191
 	 */
192
-	private function parsePropertyIdParameter( array $snakSerialization, string $parameterId ): PropertyId {
193
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
194
-		$this->requireValueParameter( $snak, $parameterId );
192
+	private function parsePropertyIdParameter(array $snakSerialization, string $parameterId): PropertyId {
193
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
194
+		$this->requireValueParameter($snak, $parameterId);
195 195
 		$value = $snak->getDataValue();
196
-		if ( $value instanceof EntityIdValue ) {
196
+		if ($value instanceof EntityIdValue) {
197 197
 			$id = $value->getEntityId();
198
-			if ( $id instanceof PropertyId ) {
198
+			if ($id instanceof PropertyId) {
199 199
 				return $id;
200 200
 			}
201 201
 		}
202 202
 		throw new ConstraintParameterException(
203
-			( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) )
204
-				->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
205
-				->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
203
+			(new ViolationMessage('wbqc-violation-message-parameter-property'))
204
+				->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
205
+				->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
206 206
 		);
207 207
 	}
208 208
 
@@ -213,33 +213,33 @@  discard block
 block discarded – undo
213 213
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
214 214
 	 * @return PropertyId
215 215
 	 */
216
-	public function parsePropertyParameter( array $constraintParameters, string $constraintTypeItemId ): PropertyId {
217
-		$this->checkError( $constraintParameters );
218
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
219
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
216
+	public function parsePropertyParameter(array $constraintParameters, string $constraintTypeItemId): PropertyId {
217
+		$this->checkError($constraintParameters);
218
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
219
+		if (!array_key_exists($propertyId, $constraintParameters)) {
220 220
 			throw new ConstraintParameterException(
221
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
222
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
223
-					->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
221
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
222
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
223
+					->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
224 224
 			);
225 225
 		}
226 226
 
227
-		$this->requireSingleParameter( $constraintParameters, $propertyId );
228
-		return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId );
227
+		$this->requireSingleParameter($constraintParameters, $propertyId);
228
+		return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId);
229 229
 	}
230 230
 
231
-	private function parseItemIdParameter( PropertyValueSnak $snak, string $parameterId ): ItemIdSnakValue {
231
+	private function parseItemIdParameter(PropertyValueSnak $snak, string $parameterId): ItemIdSnakValue {
232 232
 		$dataValue = $snak->getDataValue();
233
-		if ( $dataValue instanceof EntityIdValue ) {
233
+		if ($dataValue instanceof EntityIdValue) {
234 234
 			$entityId = $dataValue->getEntityId();
235
-			if ( $entityId instanceof ItemId ) {
236
-				return ItemIdSnakValue::fromItemId( $entityId );
235
+			if ($entityId instanceof ItemId) {
236
+				return ItemIdSnakValue::fromItemId($entityId);
237 237
 			}
238 238
 		}
239 239
 		throw new ConstraintParameterException(
240
-			( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) )
241
-				->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
242
-				->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
240
+			(new ViolationMessage('wbqc-violation-message-parameter-item'))
241
+				->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
242
+				->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
243 243
 		);
244 244
 	}
245 245
 
@@ -257,14 +257,14 @@  discard block
 block discarded – undo
257 257
 		bool $required,
258 258
 		?string $parameterId = null
259 259
 	): array {
260
-		$this->checkError( $constraintParameters );
261
-		$parameterId ??= $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
262
-		if ( !array_key_exists( $parameterId, $constraintParameters ) ) {
263
-			if ( $required ) {
260
+		$this->checkError($constraintParameters);
261
+		$parameterId ??= $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
262
+		if (!array_key_exists($parameterId, $constraintParameters)) {
263
+			if ($required) {
264 264
 				throw new ConstraintParameterException(
265
-					( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
266
-						->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
267
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
265
+					(new ViolationMessage('wbqc-violation-message-parameter-needed'))
266
+						->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
267
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
268 268
 				);
269 269
 			} else {
270 270
 				return [];
@@ -272,11 +272,11 @@  discard block
 block discarded – undo
272 272
 		}
273 273
 
274 274
 		$values = [];
275
-		foreach ( $constraintParameters[$parameterId] as $parameter ) {
276
-			$snak = $this->snakDeserializer->deserialize( $parameter );
277
-			switch ( true ) {
275
+		foreach ($constraintParameters[$parameterId] as $parameter) {
276
+			$snak = $this->snakDeserializer->deserialize($parameter);
277
+			switch (true) {
278 278
 				case $snak instanceof PropertyValueSnak:
279
-					$values[] = $this->parseItemIdParameter( $snak, $parameterId );
279
+					$values[] = $this->parseItemIdParameter($snak, $parameterId);
280 280
 					break;
281 281
 				case $snak instanceof PropertySomeValueSnak:
282 282
 					$values[] = ItemIdSnakValue::someValue();
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
 		bool $required,
305 305
 		string $parameterId
306 306
 	): array {
307
-		return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId {
308
-			if ( $value->isValue() ) {
307
+		return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId {
308
+			if ($value->isValue()) {
309 309
 				return $value->getItemId();
310 310
 			} else {
311 311
 				throw new ConstraintParameterException(
312
-					( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) )
313
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
312
+					(new ViolationMessage('wbqc-violation-message-parameter-value'))
313
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
314 314
 				);
315 315
 			}
316 316
 		}, $this->parseItemsParameter(
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 			$constraintTypeItemId,
319 319
 			$required,
320 320
 			$parameterId
321
-		) );
321
+		));
322 322
 	}
323 323
 
324 324
 	/**
@@ -326,18 +326,18 @@  discard block
 block discarded – undo
326 326
 	 * @throws ConstraintParameterException
327 327
 	 * @return mixed elements of $mapping
328 328
 	 */
329
-	private function mapItemId( ItemId $itemId, array $mapping, string $parameterId ) {
329
+	private function mapItemId(ItemId $itemId, array $mapping, string $parameterId) {
330 330
 		$serialization = $itemId->getSerialization();
331
-		if ( array_key_exists( $serialization, $mapping ) ) {
331
+		if (array_key_exists($serialization, $mapping)) {
332 332
 			return $mapping[$serialization];
333 333
 		} else {
334
-			$allowed = array_map( static function ( $id ) {
335
-				return new ItemId( $id );
336
-			}, array_keys( $mapping ) );
334
+			$allowed = array_map(static function($id) {
335
+				return new ItemId($id);
336
+			}, array_keys($mapping));
337 337
 			throw new ConstraintParameterException(
338
-				( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
339
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
340
-					->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE )
338
+				(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
339
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
340
+					->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE)
341 341
 			);
342 342
 		}
343 343
 	}
@@ -348,27 +348,27 @@  discard block
 block discarded – undo
348 348
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
349 349
 	 * @return PropertyId[]
350 350
 	 */
351
-	public function parsePropertiesParameter( array $constraintParameters, string $constraintTypeItemId ): array {
352
-		$this->checkError( $constraintParameters );
353
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
354
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
351
+	public function parsePropertiesParameter(array $constraintParameters, string $constraintTypeItemId): array {
352
+		$this->checkError($constraintParameters);
353
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
354
+		if (!array_key_exists($propertyId, $constraintParameters)) {
355 355
 			throw new ConstraintParameterException(
356
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
357
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
358
-					->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
356
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
357
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
358
+					->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
359 359
 			);
360 360
 		}
361 361
 
362 362
 		$parameters = $constraintParameters[$propertyId];
363
-		if ( count( $parameters ) === 1 &&
364
-			$this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak
363
+		if (count($parameters) === 1 &&
364
+			$this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak
365 365
 		) {
366 366
 			return [];
367 367
 		}
368 368
 
369 369
 		$properties = [];
370
-		foreach ( $parameters as $parameter ) {
371
-			$properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId );
370
+		foreach ($parameters as $parameter) {
371
+			$properties[] = $this->parsePropertyIdParameter($parameter, $propertyId);
372 372
 		}
373 373
 		return $properties;
374 374
 	}
@@ -376,24 +376,24 @@  discard block
 block discarded – undo
376 376
 	/**
377 377
 	 * @throws ConstraintParameterException
378 378
 	 */
379
-	private function parseValueOrNoValueParameter( array $snakSerialization, string $parameterId ): ?DataValue {
380
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
381
-		if ( $snak instanceof PropertyValueSnak ) {
379
+	private function parseValueOrNoValueParameter(array $snakSerialization, string $parameterId): ?DataValue {
380
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
381
+		if ($snak instanceof PropertyValueSnak) {
382 382
 			return $snak->getDataValue();
383
-		} elseif ( $snak instanceof PropertyNoValueSnak ) {
383
+		} elseif ($snak instanceof PropertyNoValueSnak) {
384 384
 			return null;
385 385
 		} else {
386 386
 			throw new ConstraintParameterException(
387
-				( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) )
388
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
387
+				(new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue'))
388
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
389 389
 			);
390 390
 		}
391 391
 	}
392 392
 
393
-	private function parseValueOrNoValueOrNowParameter( array $snakSerialization, string $parameterId ): ?DataValue {
393
+	private function parseValueOrNoValueOrNowParameter(array $snakSerialization, string $parameterId): ?DataValue {
394 394
 		try {
395
-			return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId );
396
-		} catch ( ConstraintParameterException $e ) {
395
+			return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId);
396
+		} catch (ConstraintParameterException $e) {
397 397
 			// unknown value means “now”
398 398
 			return new NowValue();
399 399
 		}
@@ -402,14 +402,14 @@  discard block
 block discarded – undo
402 402
 	/**
403 403
 	 * Checks whether there is exactly one non-null quantity with the given unit.
404 404
 	 */
405
-	private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, string $unit ): bool {
406
-		if ( !( $min instanceof UnboundedQuantityValue ) ||
407
-			!( $max instanceof UnboundedQuantityValue )
405
+	private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, string $unit): bool {
406
+		if (!($min instanceof UnboundedQuantityValue) ||
407
+			!($max instanceof UnboundedQuantityValue)
408 408
 		) {
409 409
 			return false;
410 410
 		}
411 411
 
412
-		return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit );
412
+		return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit);
413 413
 	}
414 414
 
415 415
 	/**
@@ -429,42 +429,42 @@  discard block
 block discarded – undo
429 429
 		string $constraintTypeItemId,
430 430
 		string $type
431 431
 	): array {
432
-		$this->checkError( $constraintParameters );
433
-		if ( !array_key_exists( $minimumId, $constraintParameters ) ||
434
-			!array_key_exists( $maximumId, $constraintParameters )
432
+		$this->checkError($constraintParameters);
433
+		if (!array_key_exists($minimumId, $constraintParameters) ||
434
+			!array_key_exists($maximumId, $constraintParameters)
435 435
 		) {
436 436
 			throw new ConstraintParameterException(
437
-				( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) )
438
-					->withDataValueType( $type )
439
-					->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
440
-					->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
441
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
437
+				(new ViolationMessage('wbqc-violation-message-range-parameters-needed'))
438
+					->withDataValueType($type)
439
+					->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
440
+					->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
441
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
442 442
 			);
443 443
 		}
444 444
 
445
-		$this->requireSingleParameter( $constraintParameters, $minimumId );
446
-		$this->requireSingleParameter( $constraintParameters, $maximumId );
445
+		$this->requireSingleParameter($constraintParameters, $minimumId);
446
+		$this->requireSingleParameter($constraintParameters, $maximumId);
447 447
 		$parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter';
448
-		$min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId );
449
-		$max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId );
448
+		$min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId);
449
+		$max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId);
450 450
 
451
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
452
-		if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) {
451
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
452
+		if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) {
453 453
 			throw new ConstraintParameterException(
454
-				new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' )
454
+				new ViolationMessage('wbqc-violation-message-range-parameters-one-year')
455 455
 			);
456 456
 		}
457
-		if ( ( $min === null && $max === null ) ||
458
-			( $min !== null && $max !== null && $min->equals( $max ) )
457
+		if (($min === null && $max === null) ||
458
+			($min !== null && $max !== null && $min->equals($max))
459 459
 		) {
460 460
 			throw new ConstraintParameterException(
461
-				( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) )
462
-					->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
463
-					->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
461
+				(new ViolationMessage('wbqc-violation-message-range-parameters-same'))
462
+					->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
463
+					->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
464 464
 			);
465 465
 		}
466 466
 
467
-		return [ $min, $max ];
467
+		return [$min, $max];
468 468
 	}
469 469
 
470 470
 	/**
@@ -474,11 +474,11 @@  discard block
 block discarded – undo
474 474
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
475 475
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
476 476
 	 */
477
-	public function parseQuantityRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
477
+	public function parseQuantityRangeParameter(array $constraintParameters, string $constraintTypeItemId): array {
478 478
 		return $this->parseRangeParameter(
479 479
 			$constraintParameters,
480
-			$this->config->get( 'WBQualityConstraintsMinimumQuantityId' ),
481
-			$this->config->get( 'WBQualityConstraintsMaximumQuantityId' ),
480
+			$this->config->get('WBQualityConstraintsMinimumQuantityId'),
481
+			$this->config->get('WBQualityConstraintsMaximumQuantityId'),
482 482
 			$constraintTypeItemId,
483 483
 			'quantity'
484 484
 		);
@@ -491,11 +491,11 @@  discard block
 block discarded – undo
491 491
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
492 492
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
493 493
 	 */
494
-	public function parseTimeRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
494
+	public function parseTimeRangeParameter(array $constraintParameters, string $constraintTypeItemId): array {
495 495
 		return $this->parseRangeParameter(
496 496
 			$constraintParameters,
497
-			$this->config->get( 'WBQualityConstraintsMinimumDateId' ),
498
-			$this->config->get( 'WBQualityConstraintsMaximumDateId' ),
497
+			$this->config->get('WBQualityConstraintsMinimumDateId'),
498
+			$this->config->get('WBQualityConstraintsMaximumDateId'),
499 499
 			$constraintTypeItemId,
500 500
 			'time'
501 501
 		);
@@ -508,20 +508,20 @@  discard block
 block discarded – undo
508 508
 	 * @throws ConstraintParameterException
509 509
 	 * @return string[]
510 510
 	 */
511
-	public function parseLanguageParameter( array $constraintParameters, string $constraintTypeItemId ): array {
512
-		$this->checkError( $constraintParameters );
513
-		$languagePropertyId = $this->config->get( 'WBQualityConstraintsLanguagePropertyId' );
514
-		if ( !array_key_exists( $languagePropertyId, $constraintParameters ) ) {
511
+	public function parseLanguageParameter(array $constraintParameters, string $constraintTypeItemId): array {
512
+		$this->checkError($constraintParameters);
513
+		$languagePropertyId = $this->config->get('WBQualityConstraintsLanguagePropertyId');
514
+		if (!array_key_exists($languagePropertyId, $constraintParameters)) {
515 515
 			throw new ConstraintParameterException(
516
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
517
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
518
-					->withEntityId( new NumericPropertyId( $languagePropertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
516
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
517
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
518
+					->withEntityId(new NumericPropertyId($languagePropertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
519 519
 			);
520 520
 		}
521 521
 
522 522
 		$languages = [];
523
-		foreach ( $constraintParameters[$languagePropertyId] as $snak ) {
524
-			$languages[] = $this->parseStringParameter( $snak, $languagePropertyId );
523
+		foreach ($constraintParameters[$languagePropertyId] as $snak) {
524
+			$languages[] = $this->parseStringParameter($snak, $languagePropertyId);
525 525
 		}
526 526
 		return $languages;
527 527
 	}
@@ -530,17 +530,17 @@  discard block
 block discarded – undo
530 530
 	 * Parse a single string parameter.
531 531
 	 * @throws ConstraintParameterException
532 532
 	 */
533
-	private function parseStringParameter( array $snakSerialization, string $parameterId ): string {
534
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
535
-		$this->requireValueParameter( $snak, $parameterId );
533
+	private function parseStringParameter(array $snakSerialization, string $parameterId): string {
534
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
535
+		$this->requireValueParameter($snak, $parameterId);
536 536
 		$value = $snak->getDataValue();
537
-		if ( $value instanceof StringValue ) {
537
+		if ($value instanceof StringValue) {
538 538
 			return $value->getValue();
539 539
 		} else {
540 540
 			throw new ConstraintParameterException(
541
-				( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) )
542
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
543
-					->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
541
+				(new ViolationMessage('wbqc-violation-message-parameter-string'))
542
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
543
+					->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
544 544
 			);
545 545
 		}
546 546
 	}
@@ -551,15 +551,15 @@  discard block
 block discarded – undo
551 551
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
552 552
 	 * @return string
553 553
 	 */
554
-	public function parseNamespaceParameter( array $constraintParameters, string $constraintTypeItemId ): string {
555
-		$this->checkError( $constraintParameters );
556
-		$namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' );
557
-		if ( !array_key_exists( $namespaceId, $constraintParameters ) ) {
554
+	public function parseNamespaceParameter(array $constraintParameters, string $constraintTypeItemId): string {
555
+		$this->checkError($constraintParameters);
556
+		$namespaceId = $this->config->get('WBQualityConstraintsNamespaceId');
557
+		if (!array_key_exists($namespaceId, $constraintParameters)) {
558 558
 			return '';
559 559
 		}
560 560
 
561
-		$this->requireSingleParameter( $constraintParameters, $namespaceId );
562
-		return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId );
561
+		$this->requireSingleParameter($constraintParameters, $namespaceId);
562
+		return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId);
563 563
 	}
564 564
 
565 565
 	/**
@@ -568,19 +568,19 @@  discard block
 block discarded – undo
568 568
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
569 569
 	 * @return string
570 570
 	 */
571
-	public function parseFormatParameter( array $constraintParameters, string $constraintTypeItemId ): string {
572
-		$this->checkError( $constraintParameters );
573
-		$formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' );
574
-		if ( !array_key_exists( $formatId, $constraintParameters ) ) {
571
+	public function parseFormatParameter(array $constraintParameters, string $constraintTypeItemId): string {
572
+		$this->checkError($constraintParameters);
573
+		$formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId');
574
+		if (!array_key_exists($formatId, $constraintParameters)) {
575 575
 			throw new ConstraintParameterException(
576
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
577
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
578
-					->withEntityId( new NumericPropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
576
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
577
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
578
+					->withEntityId(new NumericPropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY)
579 579
 			);
580 580
 		}
581 581
 
582
-		$this->requireSingleParameter( $constraintParameters, $formatId );
583
-		return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId );
582
+		$this->requireSingleParameter($constraintParameters, $formatId);
583
+		return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId);
584 584
 	}
585 585
 
586 586
 	/**
@@ -588,16 +588,16 @@  discard block
 block discarded – undo
588 588
 	 * @throws ConstraintParameterException if the parameter is invalid
589 589
 	 * @return EntityId[]
590 590
 	 */
591
-	public function parseExceptionParameter( array $constraintParameters ): array {
592
-		$this->checkError( $constraintParameters );
593
-		$exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' );
594
-		if ( !array_key_exists( $exceptionId, $constraintParameters ) ) {
591
+	public function parseExceptionParameter(array $constraintParameters): array {
592
+		$this->checkError($constraintParameters);
593
+		$exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId');
594
+		if (!array_key_exists($exceptionId, $constraintParameters)) {
595 595
 			return [];
596 596
 		}
597 597
 
598 598
 		return array_map(
599
-			function ( $snakSerialization ) use ( $exceptionId ) {
600
-				return $this->parseEntityIdParameter( $snakSerialization, $exceptionId );
599
+			function($snakSerialization) use ($exceptionId) {
600
+				return $this->parseEntityIdParameter($snakSerialization, $exceptionId);
601 601
 			},
602 602
 			$constraintParameters[$exceptionId]
603 603
 		);
@@ -608,39 +608,39 @@  discard block
 block discarded – undo
608 608
 	 * @throws ConstraintParameterException if the parameter is invalid
609 609
 	 * @return string|null 'mandatory', 'suggestion' or null
610 610
 	 */
611
-	public function parseConstraintStatusParameter( array $constraintParameters ): ?string {
612
-		$this->checkError( $constraintParameters );
613
-		$constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' );
614
-		if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) {
611
+	public function parseConstraintStatusParameter(array $constraintParameters): ?string {
612
+		$this->checkError($constraintParameters);
613
+		$constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId');
614
+		if (!array_key_exists($constraintStatusId, $constraintParameters)) {
615 615
 			return null;
616 616
 		}
617 617
 
618
-		$mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' );
619
-		$supportedStatuses = [ new ItemId( $mandatoryId ) ];
620
-		if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) {
621
-			$suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' );
622
-			$supportedStatuses[] = new ItemId( $suggestionId );
618
+		$mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId');
619
+		$supportedStatuses = [new ItemId($mandatoryId)];
620
+		if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) {
621
+			$suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId');
622
+			$supportedStatuses[] = new ItemId($suggestionId);
623 623
 		} else {
624 624
 			$suggestionId = null;
625 625
 		}
626 626
 
627
-		$this->requireSingleParameter( $constraintParameters, $constraintStatusId );
628
-		$snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] );
629
-		$this->requireValueParameter( $snak, $constraintStatusId );
627
+		$this->requireSingleParameter($constraintParameters, $constraintStatusId);
628
+		$snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]);
629
+		$this->requireValueParameter($snak, $constraintStatusId);
630 630
 		'@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak';
631 631
 		$dataValue = $snak->getDataValue();
632 632
 		'@phan-var EntityIdValue $dataValue';
633 633
 		$entityId = $dataValue->getEntityId();
634 634
 		$statusId = $entityId->getSerialization();
635 635
 
636
-		if ( $statusId === $mandatoryId ) {
636
+		if ($statusId === $mandatoryId) {
637 637
 			return 'mandatory';
638
-		} elseif ( $statusId === $suggestionId ) {
638
+		} elseif ($statusId === $suggestionId) {
639 639
 			return 'suggestion';
640 640
 		} else {
641 641
 			throw new ConstraintParameterException(
642
-				( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
643
-					->withEntityId( new NumericPropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
642
+				(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
643
+					->withEntityId(new NumericPropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY)
644 644
 					->withEntityIdList(
645 645
 						$supportedStatuses,
646 646
 						Role::CONSTRAINT_PARAMETER_VALUE
@@ -653,12 +653,12 @@  discard block
 block discarded – undo
653 653
 	 * Require that $dataValue is a {@link MonolingualTextValue}.
654 654
 	 * @throws ConstraintParameterException
655 655
 	 */
656
-	private function requireMonolingualTextParameter( DataValue $dataValue, string $parameterId ): void {
657
-		if ( !( $dataValue instanceof MonolingualTextValue ) ) {
656
+	private function requireMonolingualTextParameter(DataValue $dataValue, string $parameterId): void {
657
+		if (!($dataValue instanceof MonolingualTextValue)) {
658 658
 			throw new ConstraintParameterException(
659
-				( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) )
660
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
661
-					->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
659
+				(new ViolationMessage('wbqc-violation-message-parameter-monolingualtext'))
660
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
661
+					->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
662 662
 			);
663 663
 		}
664 664
 	}
@@ -668,31 +668,31 @@  discard block
 block discarded – undo
668 668
 	 *
669 669
 	 * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts
670 670
 	 */
671
-	private function parseMultilingualTextParameter( array $snakSerializations, string $parameterId ): MultilingualTextValue {
671
+	private function parseMultilingualTextParameter(array $snakSerializations, string $parameterId): MultilingualTextValue {
672 672
 		$result = [];
673 673
 
674
-		foreach ( $snakSerializations as $snakSerialization ) {
675
-			$snak = $this->snakDeserializer->deserialize( $snakSerialization );
676
-			$this->requireValueParameter( $snak, $parameterId );
674
+		foreach ($snakSerializations as $snakSerialization) {
675
+			$snak = $this->snakDeserializer->deserialize($snakSerialization);
676
+			$this->requireValueParameter($snak, $parameterId);
677 677
 
678 678
 			$value = $snak->getDataValue();
679
-			$this->requireMonolingualTextParameter( $value, $parameterId );
679
+			$this->requireMonolingualTextParameter($value, $parameterId);
680 680
 			/** @var MonolingualTextValue $value */
681 681
 			'@phan-var MonolingualTextValue $value';
682 682
 
683 683
 			$code = $value->getLanguageCode();
684
-			if ( array_key_exists( $code, $result ) ) {
684
+			if (array_key_exists($code, $result)) {
685 685
 				throw new ConstraintParameterException(
686
-					( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) )
687
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
688
-						->withLanguage( $code )
686
+					(new ViolationMessage('wbqc-violation-message-parameter-single-per-language'))
687
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
688
+						->withLanguage($code)
689 689
 				);
690 690
 			}
691 691
 
692 692
 			$result[$code] = $value;
693 693
 		}
694 694
 
695
-		return new MultilingualTextValue( $result );
695
+		return new MultilingualTextValue($result);
696 696
 	}
697 697
 
698 698
 	/**
@@ -700,11 +700,11 @@  discard block
 block discarded – undo
700 700
 	 * @throws ConstraintParameterException if the parameter is invalid
701 701
 	 * @return MultilingualTextValue
702 702
 	 */
703
-	public function parseSyntaxClarificationParameter( array $constraintParameters ): MultilingualTextValue {
704
-		$syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' );
703
+	public function parseSyntaxClarificationParameter(array $constraintParameters): MultilingualTextValue {
704
+		$syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId');
705 705
 
706
-		if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) {
707
-			return new MultilingualTextValue( [] );
706
+		if (!array_key_exists($syntaxClarificationId, $constraintParameters)) {
707
+			return new MultilingualTextValue([]);
708 708
 		}
709 709
 
710 710
 		$syntaxClarifications = $this->parseMultilingualTextParameter(
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
 	 * @throws ConstraintParameterException if the parameter is invalid
721 721
 	 * @return MultilingualTextValue
722 722
 	 */
723
-	public function parseConstraintClarificationParameter( array $constraintParameters ): MultilingualTextValue {
724
-		$constraintClarificationId = $this->config->get( 'WBQualityConstraintsConstraintClarificationId' );
723
+	public function parseConstraintClarificationParameter(array $constraintParameters): MultilingualTextValue {
724
+		$constraintClarificationId = $this->config->get('WBQualityConstraintsConstraintClarificationId');
725 725
 
726
-		if ( !array_key_exists( $constraintClarificationId, $constraintParameters ) ) {
727
-			return new MultilingualTextValue( [] );
726
+		if (!array_key_exists($constraintClarificationId, $constraintParameters)) {
727
+			return new MultilingualTextValue([]);
728 728
 		}
729 729
 
730 730
 		$constraintClarifications = $this->parseMultilingualTextParameter(
@@ -757,14 +757,14 @@  discard block
 block discarded – undo
757 757
 		array $validContextTypes,
758 758
 		array $validEntityTypes
759 759
 	): array {
760
-		$contextTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' );
760
+		$contextTypeParameterId = $this->config->get('WBQualityConstraintsConstraintScopeId');
761 761
 		$contextTypeItemIds = $this->parseItemIdsParameter(
762 762
 			$constraintParameters,
763 763
 			$constraintTypeItemId,
764 764
 			false,
765 765
 			$contextTypeParameterId
766 766
 		);
767
-		$entityTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintEntityTypesId' );
767
+		$entityTypeParameterId = $this->config->get('WBQualityConstraintsConstraintEntityTypesId');
768 768
 		$entityTypeItemIds = $this->parseItemIdsParameter(
769 769
 			$constraintParameters,
770 770
 			$constraintTypeItemId,
@@ -780,26 +780,26 @@  discard block
 block discarded – undo
780 780
 		$contextTypes = null;
781 781
 		$entityTypes = null;
782 782
 
783
-		if ( $contextTypeParameterId === $entityTypeParameterId ) {
783
+		if ($contextTypeParameterId === $entityTypeParameterId) {
784 784
 			$itemIds = $contextTypeItemIds;
785 785
 			$mapping = $contextTypeMapping + $entityTypeMapping;
786
-			foreach ( $itemIds as $itemId ) {
787
-				$mapped = $this->mapItemId( $itemId, $mapping, $contextTypeParameterId );
788
-				if ( in_array( $mapped, $contextTypeMapping, true ) ) {
786
+			foreach ($itemIds as $itemId) {
787
+				$mapped = $this->mapItemId($itemId, $mapping, $contextTypeParameterId);
788
+				if (in_array($mapped, $contextTypeMapping, true)) {
789 789
 					$contextTypes[] = $mapped;
790 790
 				} else {
791 791
 					$entityTypes[] = $mapped;
792 792
 				}
793 793
 			}
794 794
 		} else {
795
-			foreach ( $contextTypeItemIds as $contextTypeItemId ) {
795
+			foreach ($contextTypeItemIds as $contextTypeItemId) {
796 796
 				$contextTypes[] = $this->mapItemId(
797 797
 					$contextTypeItemId,
798 798
 					$contextTypeMapping,
799 799
 					$contextTypeParameterId
800 800
 				);
801 801
 			}
802
-			foreach ( $entityTypeItemIds as $entityTypeItemId ) {
802
+			foreach ($entityTypeItemIds as $entityTypeItemId) {
803 803
 				$entityTypes[] = $this->mapItemId(
804 804
 					$entityTypeItemId,
805 805
 					$entityTypeMapping,
@@ -808,21 +808,21 @@  discard block
 block discarded – undo
808 808
 			}
809 809
 		}
810 810
 
811
-		$this->checkValidScope( $constraintTypeItemId, $contextTypes, $validContextTypes );
812
-		$this->checkValidScope( $constraintTypeItemId, $entityTypes, $validEntityTypes );
811
+		$this->checkValidScope($constraintTypeItemId, $contextTypes, $validContextTypes);
812
+		$this->checkValidScope($constraintTypeItemId, $entityTypes, $validEntityTypes);
813 813
 
814
-		return [ $contextTypes, $entityTypes ];
814
+		return [$contextTypes, $entityTypes];
815 815
 	}
816 816
 
817
-	private function checkValidScope( string $constraintTypeItemId, ?array $types, array $validTypes ): void {
818
-		$invalidTypes = array_diff( $types ?: [], $validTypes );
819
-		if ( $invalidTypes !== [] ) {
820
-			$invalidType = array_pop( $invalidTypes );
817
+	private function checkValidScope(string $constraintTypeItemId, ?array $types, array $validTypes): void {
818
+		$invalidTypes = array_diff($types ?: [], $validTypes);
819
+		if ($invalidTypes !== []) {
820
+			$invalidType = array_pop($invalidTypes);
821 821
 			throw new ConstraintParameterException(
822
-				( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) )
823
-					->withConstraintScope( $invalidType, Role::CONSTRAINT_PARAMETER_VALUE )
824
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
825
-					->withConstraintScopeList( $validTypes, Role::CONSTRAINT_PARAMETER_VALUE )
822
+				(new ViolationMessage('wbqc-violation-message-invalid-scope'))
823
+					->withConstraintScope($invalidType, Role::CONSTRAINT_PARAMETER_VALUE)
824
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
825
+					->withConstraintScopeList($validTypes, Role::CONSTRAINT_PARAMETER_VALUE)
826 826
 			);
827 827
 		}
828 828
 	}
@@ -830,8 +830,8 @@  discard block
 block discarded – undo
830 830
 	/**
831 831
 	 * Turn an item ID into a full unit string (using the concept URI).
832 832
 	 */
833
-	private function parseUnitParameter( ItemId $unitId ): string {
834
-		return $this->unitItemConceptBaseUri . $unitId->getSerialization();
833
+	private function parseUnitParameter(ItemId $unitId): string {
834
+		return $this->unitItemConceptBaseUri.$unitId->getSerialization();
835 835
 	}
836 836
 
837 837
 	/**
@@ -839,23 +839,23 @@  discard block
 block discarded – undo
839 839
 	 *
840 840
 	 * @throws ConstraintParameterException
841 841
 	 */
842
-	private function parseUnitItem( ItemIdSnakValue $item ): UnitsParameter {
843
-		switch ( true ) {
842
+	private function parseUnitItem(ItemIdSnakValue $item): UnitsParameter {
843
+		switch (true) {
844 844
 			case $item->isValue():
845
-				$unit = $this->parseUnitParameter( $item->getItemId() );
845
+				$unit = $this->parseUnitParameter($item->getItemId());
846 846
 				return new UnitsParameter(
847
-					[ $item->getItemId() ],
848
-					[ UnboundedQuantityValue::newFromNumber( 1, $unit ) ],
847
+					[$item->getItemId()],
848
+					[UnboundedQuantityValue::newFromNumber(1, $unit)],
849 849
 					false
850 850
 				);
851 851
 			case $item->isSomeValue():
852
-				$qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
852
+				$qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
853 853
 				throw new ConstraintParameterException(
854
-					( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) )
855
-						->withEntityId( new NumericPropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
854
+					(new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue'))
855
+						->withEntityId(new NumericPropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY)
856 856
 				);
857 857
 			case $item->isNoValue():
858
-				return new UnitsParameter( [], [], true );
858
+				return new UnitsParameter([], [], true);
859 859
 		}
860 860
 	}
861 861
 
@@ -865,36 +865,36 @@  discard block
 block discarded – undo
865 865
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
866 866
 	 * @return UnitsParameter
867 867
 	 */
868
-	public function parseUnitsParameter( array $constraintParameters, string $constraintTypeItemId ): UnitsParameter {
869
-		$items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true );
868
+	public function parseUnitsParameter(array $constraintParameters, string $constraintTypeItemId): UnitsParameter {
869
+		$items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true);
870 870
 		$unitItems = [];
871 871
 		$unitQuantities = [];
872 872
 		$unitlessAllowed = false;
873 873
 
874
-		foreach ( $items as $item ) {
875
-			$unit = $this->parseUnitItem( $item );
876
-			$unitItems = array_merge( $unitItems, $unit->getUnitItemIds() );
877
-			$unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() );
874
+		foreach ($items as $item) {
875
+			$unit = $this->parseUnitItem($item);
876
+			$unitItems = array_merge($unitItems, $unit->getUnitItemIds());
877
+			$unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities());
878 878
 			$unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed();
879 879
 		}
880 880
 
881
-		if ( $unitQuantities === [] && !$unitlessAllowed ) {
881
+		if ($unitQuantities === [] && !$unitlessAllowed) {
882 882
 			throw new LogicException(
883 883
 				'The "units" parameter is required, and yet we seem to be missing any allowed unit'
884 884
 			);
885 885
 		}
886 886
 
887
-		return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed );
887
+		return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed);
888 888
 	}
889 889
 
890 890
 	private function getEntityTypeMapping(): array {
891 891
 		return [
892
-			$this->config->get( 'WBQualityConstraintsWikibaseItemId' ) => 'item',
893
-			$this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) => 'property',
894
-			$this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) => 'lexeme',
895
-			$this->config->get( 'WBQualityConstraintsWikibaseFormId' ) => 'form',
896
-			$this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) => 'sense',
897
-			$this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) => 'mediainfo',
892
+			$this->config->get('WBQualityConstraintsWikibaseItemId') => 'item',
893
+			$this->config->get('WBQualityConstraintsWikibasePropertyId') => 'property',
894
+			$this->config->get('WBQualityConstraintsWikibaseLexemeId') => 'lexeme',
895
+			$this->config->get('WBQualityConstraintsWikibaseFormId') => 'form',
896
+			$this->config->get('WBQualityConstraintsWikibaseSenseId') => 'sense',
897
+			$this->config->get('WBQualityConstraintsWikibaseMediaInfoId') => 'mediainfo',
898 898
 		];
899 899
 	}
900 900
 
@@ -904,10 +904,10 @@  discard block
 block discarded – undo
904 904
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
905 905
 	 * @return EntityTypesParameter
906 906
 	 */
907
-	public function parseEntityTypesParameter( array $constraintParameters, string $constraintTypeItemId ): EntityTypesParameter {
907
+	public function parseEntityTypesParameter(array $constraintParameters, string $constraintTypeItemId): EntityTypesParameter {
908 908
 		$entityTypes = [];
909 909
 		$entityTypeItemIds = [];
910
-		$parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
910
+		$parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
911 911
 		$itemIds = $this->parseItemIdsParameter(
912 912
 			$constraintParameters,
913 913
 			$constraintTypeItemId,
@@ -916,22 +916,22 @@  discard block
 block discarded – undo
916 916
 		);
917 917
 
918 918
 		$mapping = $this->getEntityTypeMapping();
919
-		foreach ( $itemIds as $itemId ) {
920
-			$entityType = $this->mapItemId( $itemId, $mapping, $parameterId );
919
+		foreach ($itemIds as $itemId) {
920
+			$entityType = $this->mapItemId($itemId, $mapping, $parameterId);
921 921
 			$entityTypes[] = $entityType;
922 922
 			$entityTypeItemIds[] = $itemId;
923 923
 		}
924 924
 
925
-		if ( $entityTypes === [] ) {
925
+		if ($entityTypes === []) {
926 926
 			// @codeCoverageIgnoreStart
927 927
 			throw new LogicException(
928
-				'The "entity types" parameter is required, ' .
928
+				'The "entity types" parameter is required, '.
929 929
 				'and yet we seem to be missing any allowed entity type'
930 930
 			);
931 931
 			// @codeCoverageIgnoreEnd
932 932
 		}
933 933
 
934
-		return new EntityTypesParameter( $entityTypes, $entityTypeItemIds );
934
+		return new EntityTypesParameter($entityTypes, $entityTypeItemIds);
935 935
 	}
936 936
 
937 937
 	/**
@@ -939,18 +939,18 @@  discard block
 block discarded – undo
939 939
 	 * @throws ConstraintParameterException if the parameter is invalid
940 940
 	 * @return PropertyId[]
941 941
 	 */
942
-	public function parseSeparatorsParameter( array $constraintParameters ): array {
943
-		$separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' );
942
+	public function parseSeparatorsParameter(array $constraintParameters): array {
943
+		$separatorId = $this->config->get('WBQualityConstraintsSeparatorId');
944 944
 
945
-		if ( !array_key_exists( $separatorId, $constraintParameters ) ) {
945
+		if (!array_key_exists($separatorId, $constraintParameters)) {
946 946
 			return [];
947 947
 		}
948 948
 
949 949
 		$parameters = $constraintParameters[$separatorId];
950 950
 		$separators = [];
951 951
 
952
-		foreach ( $parameters as $parameter ) {
953
-			$separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId );
952
+		foreach ($parameters as $parameter) {
953
+			$separators[] = $this->parsePropertyIdParameter($parameter, $separatorId);
954 954
 		}
955 955
 
956 956
 		return $separators;
@@ -958,17 +958,17 @@  discard block
 block discarded – undo
958 958
 
959 959
 	private function getConstraintScopeContextTypeMapping(): array {
960 960
 		return [
961
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ) => Context::TYPE_STATEMENT,
962
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ) => Context::TYPE_QUALIFIER,
963
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ) => Context::TYPE_REFERENCE,
961
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId') => Context::TYPE_STATEMENT,
962
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId') => Context::TYPE_QUALIFIER,
963
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId') => Context::TYPE_REFERENCE,
964 964
 		];
965 965
 	}
966 966
 
967 967
 	private function getPropertyScopeContextTypeMapping(): array {
968 968
 		return [
969
-			$this->config->get( 'WBQualityConstraintsAsMainValueId' ) => Context::TYPE_STATEMENT,
970
-			$this->config->get( 'WBQualityConstraintsAsQualifiersId' ) => Context::TYPE_QUALIFIER,
971
-			$this->config->get( 'WBQualityConstraintsAsReferencesId' ) => Context::TYPE_REFERENCE,
969
+			$this->config->get('WBQualityConstraintsAsMainValueId') => Context::TYPE_STATEMENT,
970
+			$this->config->get('WBQualityConstraintsAsQualifiersId') => Context::TYPE_QUALIFIER,
971
+			$this->config->get('WBQualityConstraintsAsReferencesId') => Context::TYPE_REFERENCE,
972 972
 		];
973 973
 	}
974 974
 
@@ -978,9 +978,9 @@  discard block
 block discarded – undo
978 978
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
979 979
 	 * @return string[] list of Context::TYPE_* constants
980 980
 	 */
981
-	public function parsePropertyScopeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
981
+	public function parsePropertyScopeParameter(array $constraintParameters, string $constraintTypeItemId): array {
982 982
 		$contextTypes = [];
983
-		$parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' );
983
+		$parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId');
984 984
 		$itemIds = $this->parseItemIdsParameter(
985 985
 			$constraintParameters,
986 986
 			$constraintTypeItemId,
@@ -989,14 +989,14 @@  discard block
 block discarded – undo
989 989
 		);
990 990
 
991 991
 		$mapping = $this->getPropertyScopeContextTypeMapping();
992
-		foreach ( $itemIds as $itemId ) {
993
-			$contextTypes[] = $this->mapItemId( $itemId, $mapping, $parameterId );
992
+		foreach ($itemIds as $itemId) {
993
+			$contextTypes[] = $this->mapItemId($itemId, $mapping, $parameterId);
994 994
 		}
995 995
 
996
-		if ( $contextTypes === [] ) {
996
+		if ($contextTypes === []) {
997 997
 			// @codeCoverageIgnoreStart
998 998
 			throw new LogicException(
999
-				'The "property scope" parameter is required, ' .
999
+				'The "property scope" parameter is required, '.
1000 1000
 				'and yet we seem to be missing any allowed scope'
1001 1001
 			);
1002 1002
 			// @codeCoverageIgnoreEnd
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/TimeValueComparer.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@
 block discarded – undo
16 16
 	 */
17 17
 	private $timeValueCalculator;
18 18
 
19
-	public function __construct( ?TimeValueCalculator $timeValueCalculator = null ) {
19
+	public function __construct(?TimeValueCalculator $timeValueCalculator = null) {
20 20
 		$this->timeValueCalculator = $timeValueCalculator ?: new TimeValueCalculator();
21 21
 	}
22 22
 
23
-	public function getComparison( TimeValue $lhs, TimeValue $rhs ) {
24
-		$lhsTimestamp = $this->timeValueCalculator->getTimestamp( $lhs );
25
-		$rhsTimestamp = $this->timeValueCalculator->getTimestamp( $rhs );
23
+	public function getComparison(TimeValue $lhs, TimeValue $rhs) {
24
+		$lhsTimestamp = $this->timeValueCalculator->getTimestamp($lhs);
25
+		$rhsTimestamp = $this->timeValueCalculator->getTimestamp($rhs);
26 26
 
27
-		if ( $lhsTimestamp === $rhsTimestamp ) {
27
+		if ($lhsTimestamp === $rhsTimestamp) {
28 28
 			return 0;
29 29
 		}
30 30
 
31 31
 		return $lhsTimestamp < $rhsTimestamp ? -1 : 1;
32 32
 	}
33 33
 
34
-	public function getMinimum( TimeValue $timeValue1, TimeValue $timeValue2 ) {
35
-		return $this->getComparison( $timeValue1, $timeValue2 ) <= 0 ? $timeValue1 : $timeValue2;
34
+	public function getMinimum(TimeValue $timeValue1, TimeValue $timeValue2) {
35
+		return $this->getComparison($timeValue1, $timeValue2) <= 0 ? $timeValue1 : $timeValue2;
36 36
 	}
37 37
 
38
-	public function isFutureTime( TimeValue $timeValue ) {
39
-		return $this->getComparison( $timeValue, new NowValue() ) >= 0;
38
+	public function isFutureTime(TimeValue $timeValue) {
39
+		return $this->getComparison($timeValue, new NowValue()) >= 0;
40 40
 	}
41 41
 
42 42
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Result/CheckResult.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result;
6 6
 
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
 		string $status = self::STATUS_TODO,
109 109
 		?ViolationMessage $message = null
110 110
 	) {
111
-		if ( $contextCursor instanceof Context ) {
111
+		if ($contextCursor instanceof Context) {
112 112
 			$context = $contextCursor;
113 113
 			$this->contextCursor = $context->getCursor();
114 114
 			$this->snakType = $context->getSnak()->getType();
115 115
 			$mainSnak = $context->getSnak();
116
-			if ( $mainSnak instanceof PropertyValueSnak ) {
116
+			if ($mainSnak instanceof PropertyValueSnak) {
117 117
 				$this->dataValue = $mainSnak->getDataValue();
118 118
 			} else {
119 119
 				$this->dataValue = null;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		$this->status = $status;
128 128
 		$this->message = $message;
129 129
 		$this->metadata = Metadata::blank();
130
-		$this->constraintClarification = new MultilingualTextValue( [] );
130
+		$this->constraintClarification = new MultilingualTextValue([]);
131 131
 	}
132 132
 
133 133
 	public function getContextCursor(): ContextCursor {
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 		return $this->status;
164 164
 	}
165 165
 
166
-	public function setStatus( string $status ): void {
166
+	public function setStatus(string $status): void {
167 167
 		$this->status = $status;
168 168
 	}
169 169
 
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 		return $this->message;
172 172
 	}
173 173
 
174
-	public function setMessage( ?ViolationMessage $message ) {
174
+	public function setMessage(?ViolationMessage $message) {
175 175
 		$this->message = $message;
176 176
 	}
177 177
 
178
-	public function withMetadata( Metadata $metadata ): self {
178
+	public function withMetadata(Metadata $metadata): self {
179 179
 		$this->metadata = $metadata;
180 180
 		return $this;
181 181
 	}
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		return $this->constraintClarification;
189 189
 	}
190 190
 
191
-	public function setConstraintClarification( MultilingualTextValue $constraintClarification ) {
191
+	public function setConstraintClarification(MultilingualTextValue $constraintClarification) {
192 192
 		$this->constraintClarification = $constraintClarification;
193 193
 	}
194 194
 
Please login to merge, or discard this patch.