Completed
Push — master ( 651fc0...41b435 )
by
unknown
21s
created
src/Job/CheckConstraintsJob.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -37,25 +37,25 @@  discard block
 block discarded – undo
37 37
 	 * @param Title $title
38 38
 	 * @param string[] $params should contain 'entityId' => 'Q1234'
39 39
 	 */
40
-	public function __construct( Title $title, array $params ) {
41
-		parent::__construct( self::COMMAND, $title, $params );
40
+	public function __construct(Title $title, array $params) {
41
+		parent::__construct(self::COMMAND, $title, $params);
42 42
 		$this->removeDuplicates = true;
43 43
 
44
-		Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' );
44
+		Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']');
45 45
 
46
-		$resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() );
46
+		$resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance());
47 47
 		'@phan-var CachingResultsSource $resultSource';
48 48
 		// This job should only ever be used when caching result sources are used.
49
-		$this->setResultsSource( $resultSource );
49
+		$this->setResultsSource($resultSource);
50 50
 
51
-		$this->setEntityIdParser( WikibaseRepo::getEntityIdParser() );
51
+		$this->setEntityIdParser(WikibaseRepo::getEntityIdParser());
52 52
 	}
53 53
 
54
-	public function setResultsSource( CachingResultsSource $resultsSource ) {
54
+	public function setResultsSource(CachingResultsSource $resultsSource) {
55 55
 		$this->resultsSource = $resultsSource;
56 56
 	}
57 57
 
58
-	public function setEntityIdParser( EntityIdParser $parser ) {
58
+	public function setEntityIdParser(EntityIdParser $parser) {
59 59
 		$this->entityIdParser = $parser;
60 60
 	}
61 61
 
@@ -66,19 +66,19 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function run() {
68 68
 		try {
69
-			$entityId = $this->entityIdParser->parse( $this->params['entityId'] );
70
-		} catch ( EntityIdParsingException ) {
69
+			$entityId = $this->entityIdParser->parse($this->params['entityId']);
70
+		} catch (EntityIdParsingException) {
71 71
 			return false;
72 72
 		}
73 73
 
74
-		$this->checkConstraints( $entityId );
74
+		$this->checkConstraints($entityId);
75 75
 
76 76
 		return true;
77 77
 	}
78 78
 
79
-	private function checkConstraints( EntityId $entityId ) {
79
+	private function checkConstraints(EntityId $entityId) {
80 80
 		$this->resultsSource->getResults(
81
-			[ $entityId ],
81
+			[$entityId],
82 82
 			[],
83 83
 			null,
84 84
 			[]
Please login to merge, or discard this patch.
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +88 added lines, -88 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\Specials;
6 6
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 		Config $config,
92 92
 		StatsFactory $statsFactory
93 93
 	) {
94
-		parent::__construct( 'ConstraintReport' );
94
+		parent::__construct('ConstraintReport');
95 95
 
96 96
 		$this->entityLookup = $entityLookup;
97 97
 		$this->entityTitleLookup = $entityTitleLookup;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 
112 112
 		$this->violationMessageRenderer = $violationMessageRendererFactory->getViolationMessageRenderer(
113 113
 			$language,
114
-			$languageFallbackChainFactory->newFromLanguage( $language ),
114
+			$languageFallbackChainFactory->newFromLanguage($language),
115 115
 			$this->getContext()
116 116
 		);
117 117
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @inheritDoc
146 146
 	 */
147 147
 	public function getDescription() {
148
-		return $this->msg( 'wbqc-constraintreport' );
148
+		return $this->msg('wbqc-constraintreport');
149 149
 	}
150 150
 
151 151
 	/**
@@ -157,75 +157,75 @@  discard block
 block discarded – undo
157 157
 	 * @throws EntityIdParsingException
158 158
 	 * @throws UnexpectedValueException
159 159
 	 */
160
-	public function execute( $subPage ) {
160
+	public function execute($subPage) {
161 161
 		$out = $this->getOutput();
162 162
 
163
-		$postRequest = $this->getContext()->getRequest()->getVal( 'entityid' );
164
-		if ( $postRequest ) {
163
+		$postRequest = $this->getContext()->getRequest()->getVal('entityid');
164
+		if ($postRequest) {
165 165
 			try {
166
-				$entityId = $this->entityIdParser->parse( $postRequest );
167
-				$out->redirect( $this->getPageTitle( $entityId->getSerialization() )->getLocalURL() );
166
+				$entityId = $this->entityIdParser->parse($postRequest);
167
+				$out->redirect($this->getPageTitle($entityId->getSerialization())->getLocalURL());
168 168
 				return;
169
-			} catch ( EntityIdParsingException ) {
169
+			} catch (EntityIdParsingException) {
170 170
 				// fall through, error is shown later
171 171
 			}
172 172
 		}
173 173
 
174 174
 		$out->enableOOUI();
175
-		$out->addModules( $this->getModules() );
175
+		$out->addModules($this->getModules());
176 176
 
177 177
 		$this->setHeaders();
178 178
 
179
-		$out->addHTML( $this->getExplanationText() );
179
+		$out->addHTML($this->getExplanationText());
180 180
 		$this->buildEntityIdForm();
181 181
 
182
-		if ( $postRequest ) {
182
+		if ($postRequest) {
183 183
 			// must be an invalid entity ID (otherwise we would have redirected and returned above)
184 184
 			$out->addHTML(
185
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
185
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
186 186
 			);
187 187
 			return;
188 188
 		}
189 189
 
190
-		if ( !$subPage ) {
190
+		if (!$subPage) {
191 191
 			return;
192 192
 		}
193 193
 
194
-		if ( !is_string( $subPage ) ) {
195
-			throw new InvalidArgumentException( '$subPage must be string.' );
194
+		if (!is_string($subPage)) {
195
+			throw new InvalidArgumentException('$subPage must be string.');
196 196
 		}
197 197
 
198 198
 		try {
199
-			$entityId = $this->entityIdParser->parse( $subPage );
200
-		} catch ( EntityIdParsingException ) {
199
+			$entityId = $this->entityIdParser->parse($subPage);
200
+		} catch (EntityIdParsingException) {
201 201
 			$out->addHTML(
202
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
202
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
203 203
 			);
204 204
 			return;
205 205
 		}
206 206
 
207
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
207
+		if (!$this->entityLookup->hasEntity($entityId)) {
208 208
 			$out->addHTML(
209
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
209
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
210 210
 			);
211 211
 			return;
212 212
 		}
213 213
 
214 214
 		$baseKey = 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck';
215
-		$metric = $this->statsFactory->getCounter( 'special_constraint_report_execute_check_total' );
216
-		$metric->copyToStatsdAt( $baseKey )->increment();
217
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
215
+		$metric = $this->statsFactory->getCounter('special_constraint_report_execute_check_total');
216
+		$metric->copyToStatsdAt($baseKey)->increment();
217
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
218 218
 
219
-		if ( $results !== [] ) {
219
+		if ($results !== []) {
220 220
 			$out->addHTML(
221
-				$this->buildResultHeader( $entityId )
222
-				. $this->buildSummary( $results )
223
-				. $this->buildResultTable( $entityId, $results )
221
+				$this->buildResultHeader($entityId)
222
+				. $this->buildSummary($results)
223
+				. $this->buildResultTable($entityId, $results)
224 224
 			);
225 225
 		} else {
226 226
 			$out->addHTML(
227
-				$this->buildResultHeader( $entityId )
228
-				. $this->buildNotice( 'wbqc-constraintreport-empty-result' )
227
+				$this->buildResultHeader($entityId)
228
+				. $this->buildNotice('wbqc-constraintreport-empty-result')
229 229
 			);
230 230
 		}
231 231
 	}
@@ -241,16 +241,16 @@  discard block
 block discarded – undo
241 241
 				'name' => 'entityid',
242 242
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
243 243
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
244
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped(),
244
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped(),
245 245
 				'required' => true,
246 246
 			],
247 247
 		];
248
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' );
249
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() );
250
-		$htmlForm->setSubmitCallback( static function () {
248
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form');
249
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped());
250
+		$htmlForm->setSubmitCallback(static function() {
251 251
 			return false;
252 252
 		} );
253
-		$htmlForm->setMethod( 'post' );
253
+		$htmlForm->setMethod('post');
254 254
 		$htmlForm->show();
255 255
 	}
256 256
 
@@ -264,9 +264,9 @@  discard block
 block discarded – undo
264 264
 	 *
265 265
 	 * @return string HTML
266 266
 	 */
267
-	private function buildNotice( string $messageKey, bool $error = false ): string {
267
+	private function buildNotice(string $messageKey, bool $error = false): string {
268 268
 		$cssClasses = 'wbqc-constraintreport-notice';
269
-		if ( $error ) {
269
+		if ($error) {
270 270
 			$cssClasses .= ' wbqc-constraintreport-notice-error';
271 271
 		}
272 272
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 				[
276 276
 					'class' => $cssClasses,
277 277
 				],
278
-				$this->msg( $messageKey )->escaped()
278
+				$this->msg($messageKey)->escaped()
279 279
 			);
280 280
 	}
281 281
 
@@ -285,16 +285,16 @@  discard block
 block discarded – undo
285 285
 	private function getExplanationText(): string {
286 286
 		return Html::rawElement(
287 287
 			'div',
288
-			[ 'class' => 'wbqc-explanation' ],
288
+			['class' => 'wbqc-explanation'],
289 289
 			Html::rawElement(
290 290
 				'p',
291 291
 				[],
292
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped()
292
+				$this->msg('wbqc-constraintreport-explanation-part-one')->escaped()
293 293
 			)
294 294
 			. Html::rawElement(
295 295
 				'p',
296 296
 				[],
297
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped()
297
+				$this->msg('wbqc-constraintreport-explanation-part-two')->escaped()
298 298
 			)
299 299
 		);
300 300
 	}
@@ -305,31 +305,31 @@  discard block
 block discarded – undo
305 305
 	 *
306 306
 	 * @return string HTML
307 307
 	 */
308
-	private function buildResultTable( EntityId $entityId, array $results ): string {
308
+	private function buildResultTable(EntityId $entityId, array $results): string {
309 309
 		// Set table headers
310 310
 		$table = new HtmlTableBuilder(
311 311
 			[
312 312
 				new HtmlTableHeaderBuilder(
313
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->text(),
313
+					$this->msg('wbqc-constraintreport-result-table-header-status')->text(),
314 314
 					true
315 315
 				),
316 316
 				new HtmlTableHeaderBuilder(
317
-					$this->msg( 'wbqc-constraintreport-result-table-header-property' )->text(),
317
+					$this->msg('wbqc-constraintreport-result-table-header-property')->text(),
318 318
 					true
319 319
 				),
320 320
 				new HtmlTableHeaderBuilder(
321
-					$this->msg( 'wbqc-constraintreport-result-table-header-message' )->text(),
321
+					$this->msg('wbqc-constraintreport-result-table-header-message')->text(),
322 322
 					true
323 323
 				),
324 324
 				new HtmlTableHeaderBuilder(
325
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->text(),
325
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->text(),
326 326
 					true
327 327
 				),
328 328
 			]
329 329
 		);
330 330
 
331
-		foreach ( $results as $result ) {
332
-			$table = $this->appendToResultTable( $table, $entityId, $result );
331
+		foreach ($results as $result) {
332
+			$table = $this->appendToResultTable($table, $entityId, $result);
333 333
 		}
334 334
 
335 335
 		return $table->toHtml();
@@ -341,35 +341,35 @@  discard block
 block discarded – undo
341 341
 		CheckResult $result
342 342
 	): HtmlTableBuilder {
343 343
 		$message = $result->getMessage();
344
-		if ( $message === null ) {
344
+		if ($message === null) {
345 345
 			// no row for this result
346 346
 			return $table;
347 347
 		}
348 348
 
349 349
 		// Status column
350
-		$statusColumn = $this->formatStatus( $result->getStatus() );
350
+		$statusColumn = $this->formatStatus($result->getStatus());
351 351
 
352 352
 		// Property column
353
-		$propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() );
353
+		$propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId());
354 354
 		$propertyColumn = $this->getClaimLink(
355 355
 			$entityId,
356 356
 			$propertyId,
357
-			$this->entityIdLabelFormatter->formatEntityId( $propertyId )
357
+			$this->entityIdLabelFormatter->formatEntityId($propertyId)
358 358
 		);
359 359
 
360 360
 		// Message column
361
-		$messageColumn = $this->violationMessageRenderer->render( $message );
361
+		$messageColumn = $this->violationMessageRenderer->render($message);
362 362
 
363 363
 		// Constraint column
364 364
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
365 365
 		try {
366
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
367
-		} catch ( InvalidArgumentException ) {
368
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
366
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
367
+		} catch (InvalidArgumentException) {
368
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
369 369
 		}
370 370
 		$constraintColumn = $this->getClaimLink(
371 371
 			$propertyId,
372
-			new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
372
+			new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
373 373
 			$constraintTypeLabel
374 374
 		);
375 375
 
@@ -377,16 +377,16 @@  discard block
 block discarded – undo
377 377
 		$table->appendRow(
378 378
 			[
379 379
 				new HtmlTableCellBuilder(
380
-					new HtmlArmor( $statusColumn )
380
+					new HtmlArmor($statusColumn)
381 381
 				),
382 382
 				new HtmlTableCellBuilder(
383
-					new HtmlArmor( $propertyColumn )
383
+					new HtmlArmor($propertyColumn)
384 384
 				),
385 385
 				new HtmlTableCellBuilder(
386
-					new HtmlArmor( $messageColumn )
386
+					new HtmlArmor($messageColumn)
387 387
 				),
388 388
 				new HtmlTableCellBuilder(
389
-					new HtmlArmor( $constraintColumn )
389
+					new HtmlArmor($constraintColumn)
390 390
 				),
391 391
 			]
392 392
 		);
@@ -401,15 +401,15 @@  discard block
 block discarded – undo
401 401
 	 *
402 402
 	 * @return string HTML
403 403
 	 */
404
-	protected function buildResultHeader( EntityId $entityId ): string {
405
-		$entityLink = sprintf( '%s (%s)',
406
-							   $this->entityIdLinkFormatter->formatEntityId( $entityId ),
407
-							   htmlspecialchars( $entityId->getSerialization() ) );
404
+	protected function buildResultHeader(EntityId $entityId): string {
405
+		$entityLink = sprintf('%s (%s)',
406
+							   $this->entityIdLinkFormatter->formatEntityId($entityId),
407
+							   htmlspecialchars($entityId->getSerialization()));
408 408
 
409 409
 		return Html::rawElement(
410 410
 			'h3',
411 411
 			[],
412
-			sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink )
412
+			sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink)
413 413
 		);
414 414
 	}
415 415
 
@@ -420,24 +420,24 @@  discard block
 block discarded – undo
420 420
 	 *
421 421
 	 * @return string HTML
422 422
 	 */
423
-	protected function buildSummary( array $results ): string {
423
+	protected function buildSummary(array $results): string {
424 424
 		$statuses = [];
425
-		foreach ( $results as $result ) {
426
-			$status = strtolower( $result->getStatus() );
427
-			$statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1;
425
+		foreach ($results as $result) {
426
+			$status = strtolower($result->getStatus());
427
+			$statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1;
428 428
 		}
429 429
 
430 430
 		$statusElements = [];
431
-		foreach ( $statuses as $status => $count ) {
432
-			if ( $count > 0 ) {
431
+		foreach ($statuses as $status => $count) {
432
+			if ($count > 0) {
433 433
 				$statusElements[] =
434
-					$this->formatStatus( $status )
434
+					$this->formatStatus($status)
435 435
 					. ': '
436 436
 					. $count;
437 437
 			}
438 438
 		}
439 439
 
440
-		return Html::rawElement( 'p', [], implode( ', ', $statusElements ) );
440
+		return Html::rawElement('p', [], implode(', ', $statusElements));
441 441
 	}
442 442
 
443 443
 	/**
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	 *
450 450
 	 * @return string HTML
451 451
 	 */
452
-	private function formatStatus( string $status ): string {
453
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
452
+	private function formatStatus(string $status): string {
453
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
454 454
 		$statusIcons = [
455 455
 			CheckResult::STATUS_SUGGESTION => [
456 456
 				'icon' => 'suggestion-constraint-violation',
@@ -467,25 +467,25 @@  discard block
 block discarded – undo
467 467
 			],
468 468
 		];
469 469
 
470
-		if ( array_key_exists( $status, $statusIcons ) ) {
471
-			$iconWidget = new IconWidget( $statusIcons[$status] );
472
-			$iconHtml = $iconWidget->toString() . ' ';
470
+		if (array_key_exists($status, $statusIcons)) {
471
+			$iconWidget = new IconWidget($statusIcons[$status]);
472
+			$iconHtml = $iconWidget->toString().' ';
473 473
 		} else {
474 474
 			$iconHtml = '';
475 475
 		}
476 476
 
477
-		$labelWidget = new LabelWidget( [
478
-			'label' => $this->msg( $messageName )->text(),
479
-		] );
477
+		$labelWidget = new LabelWidget([
478
+			'label' => $this->msg($messageName)->text(),
479
+		]);
480 480
 		$labelHtml = $labelWidget->toString();
481 481
 
482 482
 		$formattedStatus =
483 483
 			Html::rawElement(
484 484
 				'span',
485 485
 				[
486
-					'class' => 'wbqc-status wbqc-status-' . $status,
486
+					'class' => 'wbqc-status wbqc-status-'.$status,
487 487
 				],
488
-				$iconHtml . $labelHtml
488
+				$iconHtml.$labelHtml
489 489
 			);
490 490
 
491 491
 		return $formattedStatus;
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 		return Html::rawElement(
509 509
 			'a',
510 510
 			[
511
-				'href' => $this->getClaimUrl( $entityId, $propertyId ),
511
+				'href' => $this->getClaimUrl($entityId, $propertyId),
512 512
 				'target' => '_blank',
513 513
 			],
514 514
 			$text
@@ -522,8 +522,8 @@  discard block
 block discarded – undo
522 522
 		EntityId $entityId,
523 523
 		NumericPropertyId $propertyId
524 524
 	): string {
525
-		$title = $this->entityTitleLookup->getTitleForId( $entityId );
526
-		$entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() );
525
+		$title = $this->entityTitleLookup->getTitleForId($entityId);
526
+		$entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization());
527 527
 
528 528
 		return $entityUrl;
529 529
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/FormatChecker.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 		$this->sparqlHelper = $sparqlHelper;
75 75
 		$this->shellboxClientFactory = $shellboxClientFactory;
76 76
 		$this->knownGoodPatternsAsKeys = array_fill_keys(
77
-			$this->config->get( 'WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns' ),
77
+			$this->config->get('WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns'),
78 78
 			null
79 79
 		);
80 80
 		$this->logger = $logger ?? new NullLogger();
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 * @throws ConstraintParameterException
109 109
 	 * @return CheckResult
110 110
 	 */
111
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
111
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
112 112
 		$constraintParameters = $constraint->getConstraintParameters();
113 113
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
114 114
 
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 
124 124
 		$snak = $context->getSnak();
125 125
 
126
-		if ( !$snak instanceof PropertyValueSnak ) {
126
+		if (!$snak instanceof PropertyValueSnak) {
127 127
 			// nothing to check
128
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
128
+			return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
129 129
 		}
130 130
 
131 131
 		$dataValue = $snak->getDataValue();
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		 * error handling:
135 135
 		 *   type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext'
136 136
 		 */
137
-		switch ( $dataValue->getType() ) {
137
+		switch ($dataValue->getType()) {
138 138
 			case 'string':
139 139
 				$text = $dataValue->getValue();
140 140
 				break;
@@ -144,13 +144,13 @@  discard block
 block discarded – undo
144 144
 				$text = $dataValue->getText();
145 145
 				break;
146 146
 			default:
147
-				$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) )
148
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
149
-					->withDataValueType( 'string' )
150
-					->withDataValueType( 'monolingualtext' );
151
-				return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
147
+				$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2'))
148
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
149
+					->withDataValueType('string')
150
+					->withDataValueType('monolingualtext');
151
+				return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
152 152
 		}
153
-		$status = $this->runRegexCheck( $text, $format );
153
+		$status = $this->runRegexCheck($text, $format);
154 154
 		$message = $this->formatMessage(
155 155
 			$status,
156 156
 			$text,
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			$syntaxClarifications,
160 160
 			$constraintTypeItemId
161 161
 		);
162
-		return new CheckResult( $context, $constraint, $status, $message );
162
+		return new CheckResult($context, $constraint, $status, $message);
163 163
 	}
164 164
 
165 165
 	private function formatMessage(
@@ -171,43 +171,43 @@  discard block
 block discarded – undo
171 171
 		string $constraintTypeItemId
172 172
 	): ?ViolationMessage {
173 173
 		$message = null;
174
-		if ( $status === CheckResult::STATUS_VIOLATION ) {
175
-			$message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) )
176
-				->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY )
177
-				->withDataValue( new StringValue( $text ), Role::OBJECT )
178
-				->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE )
179
-				->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE );
180
-		} elseif ( $status === CheckResult::STATUS_TODO ) {
181
-			$message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) )
182
-				->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM );
174
+		if ($status === CheckResult::STATUS_VIOLATION) {
175
+			$message = (new ViolationMessage('wbqc-violation-message-format-clarification'))
176
+				->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY)
177
+				->withDataValue(new StringValue($text), Role::OBJECT)
178
+				->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE)
179
+				->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE);
180
+		} elseif ($status === CheckResult::STATUS_TODO) {
181
+			$message = (new ViolationMessage('wbqc-violation-message-security-reason'))
182
+				->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM);
183 183
 		}
184 184
 
185 185
 		return $message;
186 186
 	}
187 187
 
188 188
 	/** @throws ConstraintParameterException */
189
-	private function runRegexCheck( string $text, string $format ): string {
190
-		if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) {
189
+	private function runRegexCheck(string $text, string $format): string {
190
+		if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) {
191 191
 			return CheckResult::STATUS_TODO;
192 192
 		}
193
-		if ( \array_key_exists( $format, $this->knownGoodPatternsAsKeys ) ) {
194
-			$checkResult = FormatCheckerHelper::runRegexCheck( $format, $text );
193
+		if (\array_key_exists($format, $this->knownGoodPatternsAsKeys)) {
194
+			$checkResult = FormatCheckerHelper::runRegexCheck($format, $text);
195 195
 		} elseif (
196
-			$this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom()
196
+			$this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom()
197 197
 		) {
198
-			$checkResult = $this->runRegexCheckUsingShellbox( $text, $format );
198
+			$checkResult = $this->runRegexCheckUsingShellbox($text, $format);
199 199
 		} else {
200
-			return $this->runRegexCheckUsingSparql( $text, $format );
200
+			return $this->runRegexCheckUsingSparql($text, $format);
201 201
 		}
202 202
 
203
-		if ( $checkResult === 1 ) {
203
+		if ($checkResult === 1) {
204 204
 			return CheckResult::STATUS_COMPLIANCE;
205
-		} elseif ( $checkResult === 0 ) {
205
+		} elseif ($checkResult === 0) {
206 206
 			return CheckResult::STATUS_VIOLATION;
207
-		} elseif ( $checkResult === false ) {
207
+		} elseif ($checkResult === false) {
208 208
 			throw new ConstraintParameterException(
209
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
210
-					->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE )
209
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
210
+					->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE)
211 211
 			);
212 212
 		} else {
213 213
 			return $checkResult;
@@ -221,51 +221,51 @@  discard block
 block discarded – undo
221 221
 	 *   - FALSE if $format is invalid regex
222 222
 	 *   - CheckResult::STATUS_TODO if Shellbox is not enabled
223 223
 	 */
224
-	private function runRegexCheckUsingShellbox( string $text, string $format ) {
225
-		if ( !$this->shellboxClientFactory->isEnabled( 'constraint-regex-checker' ) ) {
224
+	private function runRegexCheckUsingShellbox(string $text, string $format) {
225
+		if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) {
226 226
 			return CheckResult::STATUS_TODO;
227 227
 		}
228 228
 
229 229
 		try {
230
-			return $this->shellboxClientFactory->getClient( [
231
-				'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000,
230
+			return $this->shellboxClientFactory->getClient([
231
+				'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000,
232 232
 				'service' => 'constraint-regex-checker',
233
-			] )->call(
233
+			])->call(
234 234
 				'constraint-regex-checker',
235
-				[ FormatCheckerHelper::class, 'runRegexCheck' ],
236
-				[ $format, $text ],
237
-				[ 'classes' => [ FormatCheckerHelper::class ] ],
235
+				[FormatCheckerHelper::class, 'runRegexCheck'],
236
+				[$format, $text],
237
+				['classes' => [FormatCheckerHelper::class]],
238 238
 			);
239
-		} catch ( ClientExceptionInterface $ce ) {
240
-			$this->logger->notice( __METHOD__ . ': Network error, skipping check: {exception}', [
239
+		} catch (ClientExceptionInterface $ce) {
240
+			$this->logger->notice(__METHOD__.': Network error, skipping check: {exception}', [
241 241
 				'exception' => $ce,
242 242
 				'text' => $text,
243 243
 				'format' => $format,
244
-			] );
244
+			]);
245 245
 			return CheckResult::STATUS_TODO;
246
-		} catch ( ShellboxError $e ) {
247
-			$this->logger->error( __METHOD__ . ': Shellbox error, skipping check: {exception}', [
246
+		} catch (ShellboxError $e) {
247
+			$this->logger->error(__METHOD__.': Shellbox error, skipping check: {exception}', [
248 248
 				'exception' => $e,
249 249
 				'text' => $text,
250 250
 				'format' => $format,
251
-			] );
251
+			]);
252 252
 			return CheckResult::STATUS_TODO;
253 253
 		}
254 254
 	}
255 255
 
256
-	private function runRegexCheckUsingSparql( string $text, string $format ): string {
257
-		if ( $this->sparqlHelper instanceof DummySparqlHelper ) {
256
+	private function runRegexCheckUsingSparql(string $text, string $format): string {
257
+		if ($this->sparqlHelper instanceof DummySparqlHelper) {
258 258
 			return CheckResult::STATUS_TODO;
259 259
 		}
260 260
 
261
-		if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) {
261
+		if ($this->sparqlHelper->matchesRegularExpression($text, $format)) {
262 262
 			return CheckResult::STATUS_COMPLIANCE;
263 263
 		} else {
264 264
 			return CheckResult::STATUS_VIOLATION;
265 265
 		}
266 266
 	}
267 267
 
268
-	public function checkConstraintParameters( Constraint $constraint ): array {
268
+	public function checkConstraintParameters(Constraint $constraint): array {
269 269
 		$constraintParameters = $constraint->getConstraintParameters();
270 270
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
271 271
 		$exceptions = [];
@@ -274,14 +274,14 @@  discard block
 block discarded – undo
274 274
 				$constraintParameters,
275 275
 				$constraintTypeItemId
276 276
 			);
277
-		} catch ( ConstraintParameterException $e ) {
277
+		} catch (ConstraintParameterException $e) {
278 278
 			$exceptions[] = $e;
279 279
 		}
280 280
 		try {
281 281
 			$this->constraintParameterParser->parseSyntaxClarificationParameter(
282 282
 				$constraintParameters
283 283
 			);
284
-		} catch ( ConstraintParameterException $e ) {
284
+		} catch (ConstraintParameterException $e) {
285 285
 			$exceptions[] = $e;
286 286
 		}
287 287
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/ValueTypeChecker.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 	 * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs
89 89
 	 * @return CheckResult
90 90
 	 */
91
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
92
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
93
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED );
91
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
92
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
93
+			return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED);
94 94
 		}
95 95
 
96 96
 		$constraintParameters = $constraint->getConstraintParameters();
@@ -106,18 +106,18 @@  discard block
 block discarded – undo
106 106
 			$constraintTypeItemId
107 107
 		);
108 108
 		$relationIds = [];
109
-		if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) {
110
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
109
+		if ($relation === 'instance' || $relation === 'instanceOrSubclass') {
110
+			$relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId');
111 111
 		}
112
-		if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) {
113
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
112
+		if ($relation === 'subclass' || $relation === 'instanceOrSubclass') {
113
+			$relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId');
114 114
 		}
115 115
 
116 116
 		$snak = $context->getSnak();
117 117
 
118
-		if ( !$snak instanceof PropertyValueSnak ) {
118
+		if (!$snak instanceof PropertyValueSnak) {
119 119
 			// nothing to check
120
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
120
+			return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
121 121
 		}
122 122
 
123 123
 		$dataValue = $snak->getDataValue();
@@ -126,23 +126,23 @@  discard block
 block discarded – undo
126 126
 		 * error handling:
127 127
 		 *   type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid'
128 128
 		 */
129
-		if ( !$dataValue instanceof EntityIdValue ) {
130
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
131
-				->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
132
-				->withDataValueType( 'wikibase-entityid' );
133
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
129
+		if (!$dataValue instanceof EntityIdValue) {
130
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
131
+				->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
132
+				->withDataValueType('wikibase-entityid');
133
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
134 134
 		}
135 135
 
136 136
 		try {
137
-			$item = $this->entityLookup->getEntity( $dataValue->getEntityId() );
138
-		} catch ( UnresolvedEntityRedirectException ) {
137
+			$item = $this->entityLookup->getEntity($dataValue->getEntityId());
138
+		} catch (UnresolvedEntityRedirectException) {
139 139
 			// Edge case (double redirect): Pretend the entity doesn't exist
140 140
 			$item = null;
141 141
 		}
142 142
 
143
-		if ( !( $item instanceof StatementListProvidingEntity ) ) {
144
-			$message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' );
145
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
143
+		if (!($item instanceof StatementListProvidingEntity)) {
144
+			$message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist');
145
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
146 146
 		}
147 147
 
148 148
 		$statements = $item->getStatements();
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			$classes
154 154
 		);
155 155
 
156
-		if ( $result->getBool() ) {
156
+		if ($result->getBool()) {
157 157
 			$message = null;
158 158
 			$status = CheckResult::STATUS_COMPLIANCE;
159 159
 		} else {
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 			$status = CheckResult::STATUS_VIOLATION;
168 168
 		}
169 169
 
170
-		return ( new CheckResult( $context, $constraint, $status, $message ) )
171
-			->withMetadata( $result->getMetadata() );
170
+		return (new CheckResult($context, $constraint, $status, $message))
171
+			->withMetadata($result->getMetadata());
172 172
 	}
173 173
 
174
-	public function checkConstraintParameters( Constraint $constraint ): array {
174
+	public function checkConstraintParameters(Constraint $constraint): array {
175 175
 		$constraintParameters = $constraint->getConstraintParameters();
176 176
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
177 177
 		$exceptions = [];
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 				$constraintParameters,
181 181
 				$constraintTypeItemId
182 182
 			);
183
-		} catch ( ConstraintParameterException $e ) {
183
+		} catch (ConstraintParameterException $e) {
184 184
 			$exceptions[] = $e;
185 185
 		}
186 186
 		try {
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 				$constraintParameters,
189 189
 				$constraintTypeItemId
190 190
 			);
191
-		} catch ( ConstraintParameterException $e ) {
191
+		} catch (ConstraintParameterException $e) {
192 192
 			$exceptions[] = $e;
193 193
 		}
194 194
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +87 added lines, -87 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\Message;
6 6
 
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
 		$this->maxListLength = $maxListLength;
71 71
 	}
72 72
 
73
-	public function render( ViolationMessage $violationMessage ): string {
73
+	public function render(ViolationMessage $violationMessage): string {
74 74
 		$messageKey = $violationMessage->getMessageKey();
75
-		$paramsLists = [ [] ];
76
-		foreach ( $violationMessage->getArguments() as $argument ) {
77
-			$params = $this->renderArgument( $argument );
75
+		$paramsLists = [[]];
76
+		foreach ($violationMessage->getArguments() as $argument) {
77
+			$params = $this->renderArgument($argument);
78 78
 			$paramsLists[] = $params;
79 79
 		}
80
-		$allParams = array_merge( ...$paramsLists );
80
+		$allParams = array_merge(...$paramsLists);
81 81
 		return $this->messageLocalizer
82
-			->msg( $messageKey )
83
-			->params( $allParams )
82
+			->msg($messageKey)
83
+			->params($allParams)
84 84
 			->escaped();
85 85
 	}
86 86
 
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	 * @param string|null $role one of the Role::* constants
90 90
 	 * @return string HTML
91 91
 	 */
92
-	protected function addRole( string $value, ?string $role ): string {
93
-		if ( $role === null ) {
92
+	protected function addRole(string $value, ?string $role): string {
93
+		if ($role === null) {
94 94
 			return $value;
95 95
 		}
96 96
 
97
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
98
-			$value .
97
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
98
+			$value.
99 99
 			'</span>';
100 100
 	}
101 101
 
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 	 * @param string $key message key
104 104
 	 * @return string HTML
105 105
 	 */
106
-	protected function msgEscaped( string $key ): string {
107
-		return $this->messageLocalizer->msg( $key )->escaped();
106
+	protected function msgEscaped(string $key): string {
107
+		return $this->messageLocalizer->msg($key)->escaped();
108 108
 	}
109 109
 
110 110
 	/**
111 111
 	 * @param array $argument
112 112
 	 * @return MessageParam[] params (for Message::params)
113 113
 	 */
114
-	protected function renderArgument( array $argument ): array {
114
+	protected function renderArgument(array $argument): array {
115 115
 		$methods = [
116 116
 			ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId',
117 117
 			ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList',
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 		$value = $argument['value'];
133 133
 		$role = $argument['role'];
134 134
 
135
-		if ( array_key_exists( $type, $methods ) ) {
135
+		if (array_key_exists($type, $methods)) {
136 136
 			$method = $methods[$type];
137
-			$params = $this->$method( $value, $role );
137
+			$params = $this->$method($value, $role);
138 138
 		} else {
139 139
 			throw new InvalidArgumentException(
140
-				'Unknown ViolationMessage argument type ' . $type . '!'
140
+				'Unknown ViolationMessage argument type '.$type.'!'
141 141
 			);
142 142
 		}
143 143
 
@@ -151,36 +151,36 @@  discard block
 block discarded – undo
151 151
 	 * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ])
152 152
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
153 153
 	 */
154
-	private function renderList( array $list, ?string $role, callable $render ): array {
155
-		if ( $list === [] ) {
154
+	private function renderList(array $list, ?string $role, callable $render): array {
155
+		if ($list === []) {
156 156
 			return [
157
-				Message::numParam( 0 ),
158
-				Message::rawParam( '<ul></ul>' ),
157
+				Message::numParam(0),
158
+				Message::rawParam('<ul></ul>'),
159 159
 			];
160 160
 		}
161 161
 
162
-		if ( count( $list ) > $this->maxListLength ) {
163
-			$list = array_slice( $list, 0, $this->maxListLength );
162
+		if (count($list) > $this->maxListLength) {
163
+			$list = array_slice($list, 0, $this->maxListLength);
164 164
 			$truncated = true;
165 165
 		}
166 166
 
167 167
 		$renderedParamsLists = array_map(
168 168
 			$render,
169 169
 			$list,
170
-			array_fill( 0, count( $list ), $role )
170
+			array_fill(0, count($list), $role)
171 171
 		);
172
-		$renderedParams = array_column( $renderedParamsLists, 0 );
173
-		$renderedElements = array_map( static fn ( MessageParam $msg ) => $msg->getValue(), $renderedParams );
174
-		if ( isset( $truncated ) ) {
175
-			$renderedElements[] = $this->msgEscaped( 'ellipsis' );
172
+		$renderedParams = array_column($renderedParamsLists, 0);
173
+		$renderedElements = array_map(static fn (MessageParam $msg) => $msg->getValue(), $renderedParams);
174
+		if (isset($truncated)) {
175
+			$renderedElements[] = $this->msgEscaped('ellipsis');
176 176
 		}
177 177
 
178 178
 		return array_merge(
179 179
 			[
180
-				Message::numParam( count( $list ) ),
180
+				Message::numParam(count($list)),
181 181
 				Message::rawParam(
182
-					'<ul><li>' .
183
-					implode( '</li><li>', $renderedElements ) .
182
+					'<ul><li>'.
183
+					implode('</li><li>', $renderedElements).
184 184
 					'</li></ul>'
185 185
 				),
186 186
 			],
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
 	 * @param string|null $role one of the Role::* constants
194 194
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
195 195
 	 */
196
-	private function renderEntityId( EntityId $entityId, ?string $role ): array {
197
-		return [ Message::rawParam( $this->addRole(
198
-			$this->entityIdFormatter->formatEntityId( $entityId ),
196
+	private function renderEntityId(EntityId $entityId, ?string $role): array {
197
+		return [Message::rawParam($this->addRole(
198
+			$this->entityIdFormatter->formatEntityId($entityId),
199 199
 			$role
200
-		) ) ];
200
+		))];
201 201
 	}
202 202
 
203 203
 	/**
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 	 * @param string|null $role one of the Role::* constants
206 206
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
207 207
 	 */
208
-	private function renderEntityIdList( array $entityIdList, ?string $role ): array {
209
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
208
+	private function renderEntityIdList(array $entityIdList, ?string $role): array {
209
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
210 210
 	}
211 211
 
212 212
 	/**
@@ -214,24 +214,24 @@  discard block
 block discarded – undo
214 214
 	 * @param string|null $role one of the Role::* constants
215 215
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
216 216
 	 */
217
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, ?string $role ): array {
218
-		switch ( true ) {
217
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, ?string $role): array {
218
+		switch (true) {
219 219
 			case $value->isValue():
220
-				return $this->renderEntityId( $value->getItemId(), $role );
220
+				return $this->renderEntityId($value->getItemId(), $role);
221 221
 			case $value->isSomeValue():
222
-				return [ Message::rawParam( $this->addRole(
223
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
224
-						$this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) .
222
+				return [Message::rawParam($this->addRole(
223
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
224
+						$this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue').
225 225
 						'</span>',
226 226
 					$role
227
-				) ) ];
227
+				))];
228 228
 			case $value->isNoValue():
229
-				return [ Message::rawParam( $this->addRole(
230
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
231
-					$this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) .
229
+				return [Message::rawParam($this->addRole(
230
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
231
+					$this->msgEscaped('wikibase-snakview-snaktypeselector-novalue').
232 232
 						'</span>',
233 233
 					$role
234
-				) ) ];
234
+				))];
235 235
 			default:
236 236
 				// @codeCoverageIgnoreStart
237 237
 				throw new LogicException(
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 	 * @param string|null $role one of the Role::* constants
247 247
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
248 248
 	 */
249
-	private function renderItemIdSnakValueList( array $valueList, ?string $role ): array {
250
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
249
+	private function renderItemIdSnakValueList(array $valueList, ?string $role): array {
250
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
251 251
 	}
252 252
 
253 253
 	/**
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
 	 * @param string|null $role one of the Role::* constants
256 256
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
257 257
 	 */
258
-	private function renderDataValue( DataValue $dataValue, ?string $role ): array {
259
-		return [ Message::rawParam( $this->addRole(
260
-			$this->dataValueFormatter->format( $dataValue ),
258
+	private function renderDataValue(DataValue $dataValue, ?string $role): array {
259
+		return [Message::rawParam($this->addRole(
260
+			$this->dataValueFormatter->format($dataValue),
261 261
 			$role
262
-		) ) ];
262
+		))];
263 263
 	}
264 264
 
265 265
 	/**
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @param string|null $role one of the Role::* constants
268 268
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
269 269
 	 */
270
-	private function renderDataValueType( string $dataValueType, ?string $role ): array {
270
+	private function renderDataValueType(string $dataValueType, ?string $role): array {
271 271
 		$messageKeys = [
272 272
 			'string' => 'datatypes-type-string',
273 273
 			'monolingualtext' => 'datatypes-type-monolingualtext',
@@ -276,15 +276,15 @@  discard block
 block discarded – undo
276 276
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
277 277
 		];
278 278
 
279
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
280
-			return [ Message::rawParam( $this->addRole(
281
-				$this->msgEscaped( $messageKeys[$dataValueType] ),
279
+		if (array_key_exists($dataValueType, $messageKeys)) {
280
+			return [Message::rawParam($this->addRole(
281
+				$this->msgEscaped($messageKeys[$dataValueType]),
282 282
 				$role
283
-			) ) ];
283
+			))];
284 284
 		} else {
285 285
 			// @codeCoverageIgnoreStart
286 286
 			throw new LogicException(
287
-				'Unknown data value type ' . $dataValueType
287
+				'Unknown data value type '.$dataValueType
288 288
 			);
289 289
 			// @codeCoverageIgnoreEnd
290 290
 		}
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
 	 * @param string|null $role one of the Role::* constants
296 296
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
297 297
 	 */
298
-	private function renderInlineCode( string $code, ?string $role ): array {
299
-		return [ Message::rawParam( $this->addRole(
300
-			'<code>' . htmlspecialchars( $code ) . '</code>',
298
+	private function renderInlineCode(string $code, ?string $role): array {
299
+		return [Message::rawParam($this->addRole(
300
+			'<code>'.htmlspecialchars($code).'</code>',
301 301
 			$role
302
-		) ) ];
302
+		))];
303 303
 	}
304 304
 
305 305
 	/**
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
 	 * @param string|null $role one of the Role::* constants
308 308
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
309 309
 	 */
310
-	private function renderConstraintScope( string $scope, ?string $role ): array {
311
-		switch ( $scope ) {
310
+	private function renderConstraintScope(string $scope, ?string $role): array {
311
+		switch ($scope) {
312 312
 			case Context::TYPE_STATEMENT:
313 313
 				$itemId = $this->config->get(
314 314
 					'WBQualityConstraintsConstraintCheckedOnMainValueId'
@@ -328,10 +328,10 @@  discard block
 block discarded – undo
328 328
 				// callers should never let this happen, but if it does happen,
329 329
 				// showing “unknown value” seems reasonable
330 330
 				// @codeCoverageIgnoreStart
331
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
331
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
332 332
 				// @codeCoverageIgnoreEnd
333 333
 		}
334
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
334
+		return $this->renderEntityId(new ItemId($itemId), $role);
335 335
 	}
336 336
 
337 337
 	/**
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
 	 * @param string|null $role one of the Role::* constants
340 340
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
341 341
 	 */
342
-	private function renderConstraintScopeList( array $scopeList, ?string $role ): array {
343
-		return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] );
342
+	private function renderConstraintScopeList(array $scopeList, ?string $role): array {
343
+		return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']);
344 344
 	}
345 345
 
346 346
 	/**
@@ -348,25 +348,25 @@  discard block
 block discarded – undo
348 348
 	 * @param string|null $role one of the Role::* constants
349 349
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
350 350
 	 */
351
-	private function renderPropertyScope( string $scope, ?string $role ): array {
352
-		switch ( $scope ) {
351
+	private function renderPropertyScope(string $scope, ?string $role): array {
352
+		switch ($scope) {
353 353
 			case Context::TYPE_STATEMENT:
354
-				$itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' );
354
+				$itemId = $this->config->get('WBQualityConstraintsAsMainValueId');
355 355
 				break;
356 356
 			case Context::TYPE_QUALIFIER:
357
-				$itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' );
357
+				$itemId = $this->config->get('WBQualityConstraintsAsQualifiersId');
358 358
 				break;
359 359
 			case Context::TYPE_REFERENCE:
360
-				$itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' );
360
+				$itemId = $this->config->get('WBQualityConstraintsAsReferencesId');
361 361
 				break;
362 362
 			default:
363 363
 				// callers should never let this happen, but if it does happen,
364 364
 				// showing “unknown value” seems reasonable
365 365
 				// @codeCoverageIgnoreStart
366
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
366
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
367 367
 				// @codeCoverageIgnoreEnd
368 368
 		}
369
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
369
+		return $this->renderEntityId(new ItemId($itemId), $role);
370 370
 	}
371 371
 
372 372
 	/**
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
 	 * @param string|null $role one of the Role::* constants
375 375
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
376 376
 	 */
377
-	private function renderPropertyScopeList( array $scopeList, ?string $role ): array {
378
-		return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] );
377
+	private function renderPropertyScopeList(array $scopeList, ?string $role): array {
378
+		return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']);
379 379
 	}
380 380
 
381 381
 	/**
@@ -384,14 +384,14 @@  discard block
 block discarded – undo
384 384
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
385 385
 	 * @suppress PhanUnusedPrivateMethodParameter
386 386
 	 */
387
-	private function renderLanguage( string $languageCode, ?string $role ): array {
387
+	private function renderLanguage(string $languageCode, ?string $role): array {
388 388
 		return [
389 389
 			// ::renderList (through ::renderLanguageList) requires 'raw' parameter
390 390
 			// so we effectively build Message::plaintextParam here
391
-			Message::rawParam( htmlspecialchars(
392
-				$this->languageNameUtils->getLanguageName( $languageCode, $this->userLanguageCode )
393
-			) ),
394
-			Message::plaintextParam( $languageCode ),
391
+			Message::rawParam(htmlspecialchars(
392
+				$this->languageNameUtils->getLanguageName($languageCode, $this->userLanguageCode)
393
+			)),
394
+			Message::plaintextParam($languageCode),
395 395
 		];
396 396
 	}
397 397
 
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
 	 * @param string|null $role one of the Role::* constants
401 401
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
402 402
 	 */
403
-	private function renderLanguageList( array $languageCodes, ?string $role ): array {
404
-		return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] );
403
+	private function renderLanguageList(array $languageCodes, ?string $role): array {
404
+		return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']);
405 405
 	}
406 406
 
407 407
 }
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 ) {
573
-				$message = new ViolationMessage( 'wbqc-violation-message-sparql-error' );
574
-				$result = new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, $message );
572
+			} catch (SparqlHelperException) {
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/TypeCheckerHelper.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -81,26 +81,26 @@  discard block
 block discarded – undo
81 81
 	 * @return bool
82 82
 	 * @throws OverflowException if $entitiesChecked exceeds the configured limit
83 83
 	 */
84
-	private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) {
85
-		$maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' );
84
+	private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) {
85
+		$maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities');
86 86
 		if ( ++$entitiesChecked > $maxEntities ) {
87
-			throw new OverflowException( 'Too many entities to check' );
87
+			throw new OverflowException('Too many entities to check');
88 88
 		}
89 89
 
90
-		$item = $this->entityLookup->getEntity( $comparativeClass );
91
-		if ( !( $item instanceof StatementListProvider ) ) {
90
+		$item = $this->entityLookup->getEntity($comparativeClass);
91
+		if (!($item instanceof StatementListProvider)) {
92 92
 			return false; // lookup failed, probably because item doesn't exist
93 93
 		}
94 94
 
95
-		$subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
95
+		$subclassId = $this->config->get('WBQualityConstraintsSubclassOfId');
96 96
 		$statements = $item->getStatements()
97
-			->getByPropertyId( new NumericPropertyId( $subclassId ) )
97
+			->getByPropertyId(new NumericPropertyId($subclassId))
98 98
 			->getBestStatements();
99 99
 		/** @var Statement $statement */
100
-		foreach ( $statements as $statement ) {
100
+		foreach ($statements as $statement) {
101 101
 			$mainSnak = $statement->getMainSnak();
102 102
 
103
-			if ( !$this->hasCorrectType( $mainSnak ) ) {
103
+			if (!$this->hasCorrectType($mainSnak)) {
104 104
 				continue;
105 105
 			}
106 106
 			/** @var PropertyValueSnak $mainSnak */
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
 			'@phan-var EntityIdValue $dataValue';
111 111
 			$comparativeClass = $dataValue->getEntityId();
112 112
 
113
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
113
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
114 114
 				return true;
115 115
 			}
116 116
 
117
-			if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) {
117
+			if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) {
118 118
 				return true;
119 119
 			}
120 120
 		}
@@ -135,40 +135,40 @@  discard block
 block discarded – undo
135 135
 	 * @return CachedBool
136 136
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
137 137
 	 */
138
-	public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) {
139
-		$timing = $this->statsFactory->getTiming( 'isSubclassOf_duration_seconds' )
140
-			->setLabel( 'result', 'success' )
141
-			->setLabel( 'TypeCheckerImplementation', 'php' )
142
-			->copyToStatsdAt( 'wikibase.quality.constraints.type.php.success.timing' );
138
+	public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) {
139
+		$timing = $this->statsFactory->getTiming('isSubclassOf_duration_seconds')
140
+			->setLabel('result', 'success')
141
+			->setLabel('TypeCheckerImplementation', 'php')
142
+			->copyToStatsdAt('wikibase.quality.constraints.type.php.success.timing');
143 143
 		$timing->start();
144 144
 
145 145
 		try {
146 146
 			$entitiesChecked = 0;
147
-			$isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked );
147
+			$isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked);
148 148
 			$timing->stop();
149 149
 
150 150
 			// not really a timing, but works like one (we want percentiles etc.)
151 151
 			// TODO: probably a good candidate for T348796
152
-			$this->statsFactory->getTiming( 'isSubclassOf_entities_total' )
153
-				->setLabel( 'TypeCheckerImplementation', 'php' )
154
-				->setLabel( 'result', 'success' )
155
-				->copyToStatsdAt( 'wikibase.quality.constraints.type.php.success.entities' )
156
-				->observe( $entitiesChecked );
157
-
158
-			return new CachedBool( $isSubclass, Metadata::blank() );
159
-		} catch ( OverflowException ) {
160
-			$timing->setLabel( 'result', 'overflow' )
161
-				->copyToStatsdAt( 'wikibase.quality.constraints.type.php.overflow.timing' )
152
+			$this->statsFactory->getTiming('isSubclassOf_entities_total')
153
+				->setLabel('TypeCheckerImplementation', 'php')
154
+				->setLabel('result', 'success')
155
+				->copyToStatsdAt('wikibase.quality.constraints.type.php.success.entities')
156
+				->observe($entitiesChecked);
157
+
158
+			return new CachedBool($isSubclass, Metadata::blank());
159
+		} catch (OverflowException) {
160
+			$timing->setLabel('result', 'overflow')
161
+				->copyToStatsdAt('wikibase.quality.constraints.type.php.overflow.timing')
162 162
 				->stop();
163 163
 
164
-			if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) {
165
-				$this->statsFactory->getCounter( 'sparql_typeFallback_total' )
166
-					->copyToStatsdAt( 'wikibase.quality.constraints.sparql.typeFallback' )
164
+			if (!($this->sparqlHelper instanceof DummySparqlHelper)) {
165
+				$this->statsFactory->getCounter('sparql_typeFallback_total')
166
+					->copyToStatsdAt('wikibase.quality.constraints.sparql.typeFallback')
167 167
 					->increment();
168 168
 
169
-				$timing->setLabel( 'TypeCheckerImplementation', 'sparql' )
170
-					->setLabel( 'result', 'success' )
171
-					->copyToStatsdAt( 'wikibase.quality.constraints.type.sparql.success.timing' )
169
+				$timing->setLabel('TypeCheckerImplementation', 'sparql')
170
+					->setLabel('result', 'success')
171
+					->copyToStatsdAt('wikibase.quality.constraints.type.sparql.success.timing')
172 172
 					->start();
173 173
 
174 174
 				$hasType = $this->sparqlHelper->hasType(
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 
181 181
 				return $hasType;
182 182
 			} else {
183
-				return new CachedBool( false, Metadata::blank() );
183
+				return new CachedBool(false, Metadata::blank());
184 184
 			}
185 185
 		}
186 186
 	}
@@ -198,13 +198,13 @@  discard block
 block discarded – undo
198 198
 	 * @return CachedBool
199 199
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
200 200
 	 */
201
-	public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) {
201
+	public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) {
202 202
 		$metadatas = [];
203 203
 
204
-		foreach ( $this->getBestStatementsByPropertyIds( $statements, $relationIds ) as $statement ) {
204
+		foreach ($this->getBestStatementsByPropertyIds($statements, $relationIds) as $statement) {
205 205
 			$mainSnak = $statement->getMainSnak();
206 206
 
207
-			if ( !$this->hasCorrectType( $mainSnak ) ) {
207
+			if (!$this->hasCorrectType($mainSnak)) {
208 208
 				continue;
209 209
 			}
210 210
 			/** @var PropertyValueSnak $mainSnak */
@@ -214,24 +214,24 @@  discard block
 block discarded – undo
214 214
 			'@phan-var EntityIdValue $dataValue';
215 215
 			$comparativeClass = $dataValue->getEntityId();
216 216
 
217
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
217
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
218 218
 				// discard $metadatas, we know this is fresh
219
-				return new CachedBool( true, Metadata::blank() );
219
+				return new CachedBool(true, Metadata::blank());
220 220
 			}
221 221
 
222
-			$result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck );
222
+			$result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck);
223 223
 			$metadatas[] = $result->getMetadata();
224
-			if ( $result->getBool() ) {
224
+			if ($result->getBool()) {
225 225
 				return new CachedBool(
226 226
 					true,
227
-					Metadata::merge( $metadatas )
227
+					Metadata::merge($metadatas)
228 228
 				);
229 229
 			}
230 230
 		}
231 231
 
232 232
 		return new CachedBool(
233 233
 			false,
234
-			Metadata::merge( $metadatas )
234
+			Metadata::merge($metadatas)
235 235
 		);
236 236
 	}
237 237
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 * @return bool
241 241
 	 * @phan-assert PropertyValueSnak $mainSnak
242 242
 	 */
243
-	private function hasCorrectType( Snak $mainSnak ) {
243
+	private function hasCorrectType(Snak $mainSnak) {
244 244
 		return $mainSnak instanceof PropertyValueSnak
245 245
 			&& $mainSnak->getDataValue()->getType() === 'wikibase-entityid';
246 246
 	}
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
 	) {
258 258
 		$statementArrays = [];
259 259
 
260
-		foreach ( $propertyIdSerializations as $propertyIdSerialization ) {
261
-			$propertyId = new NumericPropertyId( $propertyIdSerialization );
260
+		foreach ($propertyIdSerializations as $propertyIdSerialization) {
261
+			$propertyId = new NumericPropertyId($propertyIdSerialization);
262 262
 			$statementArrays[] = $statements
263
-				->getByPropertyId( $propertyId )
263
+				->getByPropertyId($propertyId)
264 264
 				->getBestStatements()
265 265
 				->toArray();
266 266
 		}
267 267
 
268
-		return array_merge( ...$statementArrays );
268
+		return array_merge(...$statementArrays);
269 269
 	}
270 270
 
271 271
 	/**
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 		$relation
286 286
 	) {
287 287
 		$classes = array_map(
288
-			static function ( $itemIdSerialization ) {
289
-				return new ItemId( $itemIdSerialization );
288
+			static function($itemIdSerialization) {
289
+				return new ItemId($itemIdSerialization);
290 290
 			},
291 291
 			$classes
292 292
 		);
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
 		// wbqc-violation-message-valueType-instance
299 299
 		// wbqc-violation-message-valueType-subclass
300 300
 		// wbqc-violation-message-valueType-instanceOrSubclass
301
-		return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) )
302
-			->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY )
303
-			->withEntityId( $entityId, Role::SUBJECT )
304
-			->withEntityIdList( $classes, Role::OBJECT );
301
+		return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation))
302
+			->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY)
303
+			->withEntityId($entityId, Role::SUBJECT)
304
+			->withEntityIdList($classes, Role::OBJECT);
305 305
 	}
306 306
 
307 307
 }
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,34 +213,34 @@  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 231
 	/** @throws ConstraintParameterException */
232
-	private function parseItemIdParameter( PropertyValueSnak $snak, string $parameterId ): ItemIdSnakValue {
232
+	private function parseItemIdParameter(PropertyValueSnak $snak, string $parameterId): ItemIdSnakValue {
233 233
 		$dataValue = $snak->getDataValue();
234
-		if ( $dataValue instanceof EntityIdValue ) {
234
+		if ($dataValue instanceof EntityIdValue) {
235 235
 			$entityId = $dataValue->getEntityId();
236
-			if ( $entityId instanceof ItemId ) {
237
-				return ItemIdSnakValue::fromItemId( $entityId );
236
+			if ($entityId instanceof ItemId) {
237
+				return ItemIdSnakValue::fromItemId($entityId);
238 238
 			}
239 239
 		}
240 240
 		throw new ConstraintParameterException(
241
-			( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) )
242
-				->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
243
-				->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
241
+			(new ViolationMessage('wbqc-violation-message-parameter-item'))
242
+				->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
243
+				->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
244 244
 		);
245 245
 	}
246 246
 
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 		bool $required,
259 259
 		?string $parameterId = null
260 260
 	): array {
261
-		$this->checkError( $constraintParameters );
262
-		$parameterId ??= $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
263
-		if ( !array_key_exists( $parameterId, $constraintParameters ) ) {
264
-			if ( $required ) {
261
+		$this->checkError($constraintParameters);
262
+		$parameterId ??= $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
263
+		if (!array_key_exists($parameterId, $constraintParameters)) {
264
+			if ($required) {
265 265
 				throw new ConstraintParameterException(
266
-					( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
267
-						->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
268
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
266
+					(new ViolationMessage('wbqc-violation-message-parameter-needed'))
267
+						->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
268
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
269 269
 				);
270 270
 			} else {
271 271
 				return [];
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
 		}
274 274
 
275 275
 		$values = [];
276
-		foreach ( $constraintParameters[$parameterId] as $parameter ) {
277
-			$snak = $this->snakDeserializer->deserialize( $parameter );
278
-			switch ( true ) {
276
+		foreach ($constraintParameters[$parameterId] as $parameter) {
277
+			$snak = $this->snakDeserializer->deserialize($parameter);
278
+			switch (true) {
279 279
 				case $snak instanceof PropertyValueSnak:
280
-					$values[] = $this->parseItemIdParameter( $snak, $parameterId );
280
+					$values[] = $this->parseItemIdParameter($snak, $parameterId);
281 281
 					break;
282 282
 				case $snak instanceof PropertySomeValueSnak:
283 283
 					$values[] = ItemIdSnakValue::someValue();
@@ -306,13 +306,13 @@  discard block
 block discarded – undo
306 306
 		string $parameterId
307 307
 	): array {
308 308
 		/** @throws ConstraintParameterException */
309
-		return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId {
310
-			if ( $value->isValue() ) {
309
+		return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId {
310
+			if ($value->isValue()) {
311 311
 				return $value->getItemId();
312 312
 			} else {
313 313
 				throw new ConstraintParameterException(
314
-					( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) )
315
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
314
+					(new ViolationMessage('wbqc-violation-message-parameter-value'))
315
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
316 316
 				);
317 317
 			}
318 318
 		}, $this->parseItemsParameter(
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 			$constraintTypeItemId,
321 321
 			$required,
322 322
 			$parameterId
323
-		) );
323
+		));
324 324
 	}
325 325
 
326 326
 	/**
@@ -328,18 +328,18 @@  discard block
 block discarded – undo
328 328
 	 * @throws ConstraintParameterException
329 329
 	 * @return mixed elements of $mapping
330 330
 	 */
331
-	private function mapItemId( ItemId $itemId, array $mapping, string $parameterId ) {
331
+	private function mapItemId(ItemId $itemId, array $mapping, string $parameterId) {
332 332
 		$serialization = $itemId->getSerialization();
333
-		if ( array_key_exists( $serialization, $mapping ) ) {
333
+		if (array_key_exists($serialization, $mapping)) {
334 334
 			return $mapping[$serialization];
335 335
 		} else {
336
-			$allowed = array_map( static function ( $id ) {
337
-				return new ItemId( $id );
338
-			}, array_keys( $mapping ) );
336
+			$allowed = array_map(static function($id) {
337
+				return new ItemId($id);
338
+			}, array_keys($mapping));
339 339
 			throw new ConstraintParameterException(
340
-				( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
341
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
342
-					->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE )
340
+				(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
341
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
342
+					->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE)
343 343
 			);
344 344
 		}
345 345
 	}
@@ -350,27 +350,27 @@  discard block
 block discarded – undo
350 350
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
351 351
 	 * @return PropertyId[]
352 352
 	 */
353
-	public function parsePropertiesParameter( array $constraintParameters, string $constraintTypeItemId ): array {
354
-		$this->checkError( $constraintParameters );
355
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
356
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
353
+	public function parsePropertiesParameter(array $constraintParameters, string $constraintTypeItemId): array {
354
+		$this->checkError($constraintParameters);
355
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
356
+		if (!array_key_exists($propertyId, $constraintParameters)) {
357 357
 			throw new ConstraintParameterException(
358
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
359
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
360
-					->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
358
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
359
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
360
+					->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
361 361
 			);
362 362
 		}
363 363
 
364 364
 		$parameters = $constraintParameters[$propertyId];
365
-		if ( count( $parameters ) === 1 &&
366
-			$this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak
365
+		if (count($parameters) === 1 &&
366
+			$this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak
367 367
 		) {
368 368
 			return [];
369 369
 		}
370 370
 
371 371
 		$properties = [];
372
-		foreach ( $parameters as $parameter ) {
373
-			$properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId );
372
+		foreach ($parameters as $parameter) {
373
+			$properties[] = $this->parsePropertyIdParameter($parameter, $propertyId);
374 374
 		}
375 375
 		return $properties;
376 376
 	}
@@ -378,24 +378,24 @@  discard block
 block discarded – undo
378 378
 	/**
379 379
 	 * @throws ConstraintParameterException
380 380
 	 */
381
-	private function parseValueOrNoValueParameter( array $snakSerialization, string $parameterId ): ?DataValue {
382
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
383
-		if ( $snak instanceof PropertyValueSnak ) {
381
+	private function parseValueOrNoValueParameter(array $snakSerialization, string $parameterId): ?DataValue {
382
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
383
+		if ($snak instanceof PropertyValueSnak) {
384 384
 			return $snak->getDataValue();
385
-		} elseif ( $snak instanceof PropertyNoValueSnak ) {
385
+		} elseif ($snak instanceof PropertyNoValueSnak) {
386 386
 			return null;
387 387
 		} else {
388 388
 			throw new ConstraintParameterException(
389
-				( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) )
390
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
389
+				(new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue'))
390
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
391 391
 			);
392 392
 		}
393 393
 	}
394 394
 
395
-	private function parseValueOrNoValueOrNowParameter( array $snakSerialization, string $parameterId ): ?DataValue {
395
+	private function parseValueOrNoValueOrNowParameter(array $snakSerialization, string $parameterId): ?DataValue {
396 396
 		try {
397
-			return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId );
398
-		} catch ( ConstraintParameterException ) {
397
+			return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId);
398
+		} catch (ConstraintParameterException) {
399 399
 			// unknown value means “now”
400 400
 			return new NowValue();
401 401
 		}
@@ -404,14 +404,14 @@  discard block
 block discarded – undo
404 404
 	/**
405 405
 	 * Checks whether there is exactly one non-null quantity with the given unit.
406 406
 	 */
407
-	private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, string $unit ): bool {
408
-		if ( !( $min instanceof UnboundedQuantityValue ) ||
409
-			!( $max instanceof UnboundedQuantityValue )
407
+	private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, string $unit): bool {
408
+		if (!($min instanceof UnboundedQuantityValue) ||
409
+			!($max instanceof UnboundedQuantityValue)
410 410
 		) {
411 411
 			return false;
412 412
 		}
413 413
 
414
-		return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit );
414
+		return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit);
415 415
 	}
416 416
 
417 417
 	/**
@@ -431,42 +431,42 @@  discard block
 block discarded – undo
431 431
 		string $constraintTypeItemId,
432 432
 		string $type
433 433
 	): array {
434
-		$this->checkError( $constraintParameters );
435
-		if ( !array_key_exists( $minimumId, $constraintParameters ) ||
436
-			!array_key_exists( $maximumId, $constraintParameters )
434
+		$this->checkError($constraintParameters);
435
+		if (!array_key_exists($minimumId, $constraintParameters) ||
436
+			!array_key_exists($maximumId, $constraintParameters)
437 437
 		) {
438 438
 			throw new ConstraintParameterException(
439
-				( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) )
440
-					->withDataValueType( $type )
441
-					->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
442
-					->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
443
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
439
+				(new ViolationMessage('wbqc-violation-message-range-parameters-needed'))
440
+					->withDataValueType($type)
441
+					->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
442
+					->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
443
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
444 444
 			);
445 445
 		}
446 446
 
447
-		$this->requireSingleParameter( $constraintParameters, $minimumId );
448
-		$this->requireSingleParameter( $constraintParameters, $maximumId );
447
+		$this->requireSingleParameter($constraintParameters, $minimumId);
448
+		$this->requireSingleParameter($constraintParameters, $maximumId);
449 449
 		$parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter';
450
-		$min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId );
451
-		$max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId );
450
+		$min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId);
451
+		$max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId);
452 452
 
453
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
454
-		if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) {
453
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
454
+		if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) {
455 455
 			throw new ConstraintParameterException(
456
-				new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' )
456
+				new ViolationMessage('wbqc-violation-message-range-parameters-one-year')
457 457
 			);
458 458
 		}
459
-		if ( ( $min === null && $max === null ) ||
460
-			( $min !== null && $max !== null && $min->equals( $max ) )
459
+		if (($min === null && $max === null) ||
460
+			($min !== null && $max !== null && $min->equals($max))
461 461
 		) {
462 462
 			throw new ConstraintParameterException(
463
-				( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) )
464
-					->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
465
-					->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
463
+				(new ViolationMessage('wbqc-violation-message-range-parameters-same'))
464
+					->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
465
+					->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
466 466
 			);
467 467
 		}
468 468
 
469
-		return [ $min, $max ];
469
+		return [$min, $max];
470 470
 	}
471 471
 
472 472
 	/**
@@ -476,11 +476,11 @@  discard block
 block discarded – undo
476 476
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
477 477
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
478 478
 	 */
479
-	public function parseQuantityRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
479
+	public function parseQuantityRangeParameter(array $constraintParameters, string $constraintTypeItemId): array {
480 480
 		return $this->parseRangeParameter(
481 481
 			$constraintParameters,
482
-			$this->config->get( 'WBQualityConstraintsMinimumQuantityId' ),
483
-			$this->config->get( 'WBQualityConstraintsMaximumQuantityId' ),
482
+			$this->config->get('WBQualityConstraintsMinimumQuantityId'),
483
+			$this->config->get('WBQualityConstraintsMaximumQuantityId'),
484 484
 			$constraintTypeItemId,
485 485
 			'quantity'
486 486
 		);
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
494 494
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
495 495
 	 */
496
-	public function parseTimeRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
496
+	public function parseTimeRangeParameter(array $constraintParameters, string $constraintTypeItemId): array {
497 497
 		return $this->parseRangeParameter(
498 498
 			$constraintParameters,
499
-			$this->config->get( 'WBQualityConstraintsMinimumDateId' ),
500
-			$this->config->get( 'WBQualityConstraintsMaximumDateId' ),
499
+			$this->config->get('WBQualityConstraintsMinimumDateId'),
500
+			$this->config->get('WBQualityConstraintsMaximumDateId'),
501 501
 			$constraintTypeItemId,
502 502
 			'time'
503 503
 		);
@@ -510,20 +510,20 @@  discard block
 block discarded – undo
510 510
 	 * @throws ConstraintParameterException
511 511
 	 * @return string[]
512 512
 	 */
513
-	public function parseLanguageParameter( array $constraintParameters, string $constraintTypeItemId ): array {
514
-		$this->checkError( $constraintParameters );
515
-		$languagePropertyId = $this->config->get( 'WBQualityConstraintsLanguagePropertyId' );
516
-		if ( !array_key_exists( $languagePropertyId, $constraintParameters ) ) {
513
+	public function parseLanguageParameter(array $constraintParameters, string $constraintTypeItemId): array {
514
+		$this->checkError($constraintParameters);
515
+		$languagePropertyId = $this->config->get('WBQualityConstraintsLanguagePropertyId');
516
+		if (!array_key_exists($languagePropertyId, $constraintParameters)) {
517 517
 			throw new ConstraintParameterException(
518
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
519
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
520
-					->withEntityId( new NumericPropertyId( $languagePropertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
518
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
519
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
520
+					->withEntityId(new NumericPropertyId($languagePropertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
521 521
 			);
522 522
 		}
523 523
 
524 524
 		$languages = [];
525
-		foreach ( $constraintParameters[$languagePropertyId] as $snak ) {
526
-			$languages[] = $this->parseStringParameter( $snak, $languagePropertyId );
525
+		foreach ($constraintParameters[$languagePropertyId] as $snak) {
526
+			$languages[] = $this->parseStringParameter($snak, $languagePropertyId);
527 527
 		}
528 528
 		return $languages;
529 529
 	}
@@ -532,17 +532,17 @@  discard block
 block discarded – undo
532 532
 	 * Parse a single string parameter.
533 533
 	 * @throws ConstraintParameterException
534 534
 	 */
535
-	private function parseStringParameter( array $snakSerialization, string $parameterId ): string {
536
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
537
-		$this->requireValueParameter( $snak, $parameterId );
535
+	private function parseStringParameter(array $snakSerialization, string $parameterId): string {
536
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
537
+		$this->requireValueParameter($snak, $parameterId);
538 538
 		$value = $snak->getDataValue();
539
-		if ( $value instanceof StringValue ) {
539
+		if ($value instanceof StringValue) {
540 540
 			return $value->getValue();
541 541
 		} else {
542 542
 			throw new ConstraintParameterException(
543
-				( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) )
544
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
545
-					->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
543
+				(new ViolationMessage('wbqc-violation-message-parameter-string'))
544
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
545
+					->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
546 546
 			);
547 547
 		}
548 548
 	}
@@ -553,15 +553,15 @@  discard block
 block discarded – undo
553 553
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
554 554
 	 * @return string
555 555
 	 */
556
-	public function parseNamespaceParameter( array $constraintParameters, string $constraintTypeItemId ): string {
557
-		$this->checkError( $constraintParameters );
558
-		$namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' );
559
-		if ( !array_key_exists( $namespaceId, $constraintParameters ) ) {
556
+	public function parseNamespaceParameter(array $constraintParameters, string $constraintTypeItemId): string {
557
+		$this->checkError($constraintParameters);
558
+		$namespaceId = $this->config->get('WBQualityConstraintsNamespaceId');
559
+		if (!array_key_exists($namespaceId, $constraintParameters)) {
560 560
 			return '';
561 561
 		}
562 562
 
563
-		$this->requireSingleParameter( $constraintParameters, $namespaceId );
564
-		return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId );
563
+		$this->requireSingleParameter($constraintParameters, $namespaceId);
564
+		return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId);
565 565
 	}
566 566
 
567 567
 	/**
@@ -570,19 +570,19 @@  discard block
 block discarded – undo
570 570
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
571 571
 	 * @return string
572 572
 	 */
573
-	public function parseFormatParameter( array $constraintParameters, string $constraintTypeItemId ): string {
574
-		$this->checkError( $constraintParameters );
575
-		$formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' );
576
-		if ( !array_key_exists( $formatId, $constraintParameters ) ) {
573
+	public function parseFormatParameter(array $constraintParameters, string $constraintTypeItemId): string {
574
+		$this->checkError($constraintParameters);
575
+		$formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId');
576
+		if (!array_key_exists($formatId, $constraintParameters)) {
577 577
 			throw new ConstraintParameterException(
578
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
579
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
580
-					->withEntityId( new NumericPropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
578
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
579
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
580
+					->withEntityId(new NumericPropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY)
581 581
 			);
582 582
 		}
583 583
 
584
-		$this->requireSingleParameter( $constraintParameters, $formatId );
585
-		return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId );
584
+		$this->requireSingleParameter($constraintParameters, $formatId);
585
+		return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId);
586 586
 	}
587 587
 
588 588
 	/**
@@ -590,16 +590,16 @@  discard block
 block discarded – undo
590 590
 	 * @throws ConstraintParameterException if the parameter is invalid
591 591
 	 * @return EntityId[]
592 592
 	 */
593
-	public function parseExceptionParameter( array $constraintParameters ): array {
594
-		$this->checkError( $constraintParameters );
595
-		$exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' );
596
-		if ( !array_key_exists( $exceptionId, $constraintParameters ) ) {
593
+	public function parseExceptionParameter(array $constraintParameters): array {
594
+		$this->checkError($constraintParameters);
595
+		$exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId');
596
+		if (!array_key_exists($exceptionId, $constraintParameters)) {
597 597
 			return [];
598 598
 		}
599 599
 
600 600
 		return array_map(
601
-			function ( $snakSerialization ) use ( $exceptionId ) {
602
-				return $this->parseEntityIdParameter( $snakSerialization, $exceptionId );
601
+			function($snakSerialization) use ($exceptionId) {
602
+				return $this->parseEntityIdParameter($snakSerialization, $exceptionId);
603 603
 			},
604 604
 			$constraintParameters[$exceptionId]
605 605
 		);
@@ -610,39 +610,39 @@  discard block
 block discarded – undo
610 610
 	 * @throws ConstraintParameterException if the parameter is invalid
611 611
 	 * @return string|null 'mandatory', 'suggestion' or null
612 612
 	 */
613
-	public function parseConstraintStatusParameter( array $constraintParameters ): ?string {
614
-		$this->checkError( $constraintParameters );
615
-		$constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' );
616
-		if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) {
613
+	public function parseConstraintStatusParameter(array $constraintParameters): ?string {
614
+		$this->checkError($constraintParameters);
615
+		$constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId');
616
+		if (!array_key_exists($constraintStatusId, $constraintParameters)) {
617 617
 			return null;
618 618
 		}
619 619
 
620
-		$mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' );
621
-		$supportedStatuses = [ new ItemId( $mandatoryId ) ];
622
-		if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) {
623
-			$suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' );
624
-			$supportedStatuses[] = new ItemId( $suggestionId );
620
+		$mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId');
621
+		$supportedStatuses = [new ItemId($mandatoryId)];
622
+		if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) {
623
+			$suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId');
624
+			$supportedStatuses[] = new ItemId($suggestionId);
625 625
 		} else {
626 626
 			$suggestionId = null;
627 627
 		}
628 628
 
629
-		$this->requireSingleParameter( $constraintParameters, $constraintStatusId );
630
-		$snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] );
631
-		$this->requireValueParameter( $snak, $constraintStatusId );
629
+		$this->requireSingleParameter($constraintParameters, $constraintStatusId);
630
+		$snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]);
631
+		$this->requireValueParameter($snak, $constraintStatusId);
632 632
 		'@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak';
633 633
 		$dataValue = $snak->getDataValue();
634 634
 		'@phan-var EntityIdValue $dataValue';
635 635
 		$entityId = $dataValue->getEntityId();
636 636
 		$statusId = $entityId->getSerialization();
637 637
 
638
-		if ( $statusId === $mandatoryId ) {
638
+		if ($statusId === $mandatoryId) {
639 639
 			return 'mandatory';
640
-		} elseif ( $statusId === $suggestionId ) {
640
+		} elseif ($statusId === $suggestionId) {
641 641
 			return 'suggestion';
642 642
 		} else {
643 643
 			throw new ConstraintParameterException(
644
-				( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
645
-					->withEntityId( new NumericPropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
644
+				(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
645
+					->withEntityId(new NumericPropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY)
646 646
 					->withEntityIdList(
647 647
 						$supportedStatuses,
648 648
 						Role::CONSTRAINT_PARAMETER_VALUE
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 	 * Require that $dataValue is a {@link MonolingualTextValue}.
656 656
 	 * @throws ConstraintParameterException
657 657
 	 */
658
-	private function requireMonolingualTextParameter( DataValue $dataValue, string $parameterId ): void {
659
-		if ( !( $dataValue instanceof MonolingualTextValue ) ) {
658
+	private function requireMonolingualTextParameter(DataValue $dataValue, string $parameterId): void {
659
+		if (!($dataValue instanceof MonolingualTextValue)) {
660 660
 			throw new ConstraintParameterException(
661
-				( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) )
662
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
663
-					->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
661
+				(new ViolationMessage('wbqc-violation-message-parameter-monolingualtext'))
662
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
663
+					->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
664 664
 			);
665 665
 		}
666 666
 	}
@@ -670,31 +670,31 @@  discard block
 block discarded – undo
670 670
 	 *
671 671
 	 * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts
672 672
 	 */
673
-	private function parseMultilingualTextParameter( array $snakSerializations, string $parameterId ): MultilingualTextValue {
673
+	private function parseMultilingualTextParameter(array $snakSerializations, string $parameterId): MultilingualTextValue {
674 674
 		$result = [];
675 675
 
676
-		foreach ( $snakSerializations as $snakSerialization ) {
677
-			$snak = $this->snakDeserializer->deserialize( $snakSerialization );
678
-			$this->requireValueParameter( $snak, $parameterId );
676
+		foreach ($snakSerializations as $snakSerialization) {
677
+			$snak = $this->snakDeserializer->deserialize($snakSerialization);
678
+			$this->requireValueParameter($snak, $parameterId);
679 679
 
680 680
 			$value = $snak->getDataValue();
681
-			$this->requireMonolingualTextParameter( $value, $parameterId );
681
+			$this->requireMonolingualTextParameter($value, $parameterId);
682 682
 			/** @var MonolingualTextValue $value */
683 683
 			'@phan-var MonolingualTextValue $value';
684 684
 
685 685
 			$code = $value->getLanguageCode();
686
-			if ( array_key_exists( $code, $result ) ) {
686
+			if (array_key_exists($code, $result)) {
687 687
 				throw new ConstraintParameterException(
688
-					( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) )
689
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
690
-						->withLanguage( $code )
688
+					(new ViolationMessage('wbqc-violation-message-parameter-single-per-language'))
689
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
690
+						->withLanguage($code)
691 691
 				);
692 692
 			}
693 693
 
694 694
 			$result[$code] = $value;
695 695
 		}
696 696
 
697
-		return new MultilingualTextValue( $result );
697
+		return new MultilingualTextValue($result);
698 698
 	}
699 699
 
700 700
 	/**
@@ -702,11 +702,11 @@  discard block
 block discarded – undo
702 702
 	 * @throws ConstraintParameterException if the parameter is invalid
703 703
 	 * @return MultilingualTextValue
704 704
 	 */
705
-	public function parseSyntaxClarificationParameter( array $constraintParameters ): MultilingualTextValue {
706
-		$syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' );
705
+	public function parseSyntaxClarificationParameter(array $constraintParameters): MultilingualTextValue {
706
+		$syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId');
707 707
 
708
-		if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) {
709
-			return new MultilingualTextValue( [] );
708
+		if (!array_key_exists($syntaxClarificationId, $constraintParameters)) {
709
+			return new MultilingualTextValue([]);
710 710
 		}
711 711
 
712 712
 		$syntaxClarifications = $this->parseMultilingualTextParameter(
@@ -722,11 +722,11 @@  discard block
 block discarded – undo
722 722
 	 * @throws ConstraintParameterException if the parameter is invalid
723 723
 	 * @return MultilingualTextValue
724 724
 	 */
725
-	public function parseConstraintClarificationParameter( array $constraintParameters ): MultilingualTextValue {
726
-		$constraintClarificationId = $this->config->get( 'WBQualityConstraintsConstraintClarificationId' );
725
+	public function parseConstraintClarificationParameter(array $constraintParameters): MultilingualTextValue {
726
+		$constraintClarificationId = $this->config->get('WBQualityConstraintsConstraintClarificationId');
727 727
 
728
-		if ( !array_key_exists( $constraintClarificationId, $constraintParameters ) ) {
729
-			return new MultilingualTextValue( [] );
728
+		if (!array_key_exists($constraintClarificationId, $constraintParameters)) {
729
+			return new MultilingualTextValue([]);
730 730
 		}
731 731
 
732 732
 		$constraintClarifications = $this->parseMultilingualTextParameter(
@@ -759,14 +759,14 @@  discard block
 block discarded – undo
759 759
 		array $validContextTypes,
760 760
 		array $validEntityTypes
761 761
 	): array {
762
-		$contextTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' );
762
+		$contextTypeParameterId = $this->config->get('WBQualityConstraintsConstraintScopeId');
763 763
 		$contextTypeItemIds = $this->parseItemIdsParameter(
764 764
 			$constraintParameters,
765 765
 			$constraintTypeItemId,
766 766
 			false,
767 767
 			$contextTypeParameterId
768 768
 		);
769
-		$entityTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintEntityTypesId' );
769
+		$entityTypeParameterId = $this->config->get('WBQualityConstraintsConstraintEntityTypesId');
770 770
 		$entityTypeItemIds = $this->parseItemIdsParameter(
771 771
 			$constraintParameters,
772 772
 			$constraintTypeItemId,
@@ -782,26 +782,26 @@  discard block
 block discarded – undo
782 782
 		$contextTypes = null;
783 783
 		$entityTypes = null;
784 784
 
785
-		if ( $contextTypeParameterId === $entityTypeParameterId ) {
785
+		if ($contextTypeParameterId === $entityTypeParameterId) {
786 786
 			$itemIds = $contextTypeItemIds;
787 787
 			$mapping = $contextTypeMapping + $entityTypeMapping;
788
-			foreach ( $itemIds as $itemId ) {
789
-				$mapped = $this->mapItemId( $itemId, $mapping, $contextTypeParameterId );
790
-				if ( in_array( $mapped, $contextTypeMapping, true ) ) {
788
+			foreach ($itemIds as $itemId) {
789
+				$mapped = $this->mapItemId($itemId, $mapping, $contextTypeParameterId);
790
+				if (in_array($mapped, $contextTypeMapping, true)) {
791 791
 					$contextTypes[] = $mapped;
792 792
 				} else {
793 793
 					$entityTypes[] = $mapped;
794 794
 				}
795 795
 			}
796 796
 		} else {
797
-			foreach ( $contextTypeItemIds as $contextTypeItemId ) {
797
+			foreach ($contextTypeItemIds as $contextTypeItemId) {
798 798
 				$contextTypes[] = $this->mapItemId(
799 799
 					$contextTypeItemId,
800 800
 					$contextTypeMapping,
801 801
 					$contextTypeParameterId
802 802
 				);
803 803
 			}
804
-			foreach ( $entityTypeItemIds as $entityTypeItemId ) {
804
+			foreach ($entityTypeItemIds as $entityTypeItemId) {
805 805
 				$entityTypes[] = $this->mapItemId(
806 806
 					$entityTypeItemId,
807 807
 					$entityTypeMapping,
@@ -810,22 +810,22 @@  discard block
 block discarded – undo
810 810
 			}
811 811
 		}
812 812
 
813
-		$this->checkValidScope( $constraintTypeItemId, $contextTypes, $validContextTypes );
814
-		$this->checkValidScope( $constraintTypeItemId, $entityTypes, $validEntityTypes );
813
+		$this->checkValidScope($constraintTypeItemId, $contextTypes, $validContextTypes);
814
+		$this->checkValidScope($constraintTypeItemId, $entityTypes, $validEntityTypes);
815 815
 
816
-		return [ $contextTypes, $entityTypes ];
816
+		return [$contextTypes, $entityTypes];
817 817
 	}
818 818
 
819 819
 	/** @throws ConstraintParameterException */
820
-	private function checkValidScope( string $constraintTypeItemId, ?array $types, array $validTypes ): void {
821
-		$invalidTypes = array_diff( $types ?: [], $validTypes );
822
-		if ( $invalidTypes !== [] ) {
823
-			$invalidType = array_pop( $invalidTypes );
820
+	private function checkValidScope(string $constraintTypeItemId, ?array $types, array $validTypes): void {
821
+		$invalidTypes = array_diff($types ?: [], $validTypes);
822
+		if ($invalidTypes !== []) {
823
+			$invalidType = array_pop($invalidTypes);
824 824
 			throw new ConstraintParameterException(
825
-				( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) )
826
-					->withConstraintScope( $invalidType, Role::CONSTRAINT_PARAMETER_VALUE )
827
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
828
-					->withConstraintScopeList( $validTypes, Role::CONSTRAINT_PARAMETER_VALUE )
825
+				(new ViolationMessage('wbqc-violation-message-invalid-scope'))
826
+					->withConstraintScope($invalidType, Role::CONSTRAINT_PARAMETER_VALUE)
827
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
828
+					->withConstraintScopeList($validTypes, Role::CONSTRAINT_PARAMETER_VALUE)
829 829
 			);
830 830
 		}
831 831
 	}
@@ -833,8 +833,8 @@  discard block
 block discarded – undo
833 833
 	/**
834 834
 	 * Turn an item ID into a full unit string (using the concept URI).
835 835
 	 */
836
-	private function parseUnitParameter( ItemId $unitId ): string {
837
-		return $this->unitItemConceptBaseUri . $unitId->getSerialization();
836
+	private function parseUnitParameter(ItemId $unitId): string {
837
+		return $this->unitItemConceptBaseUri.$unitId->getSerialization();
838 838
 	}
839 839
 
840 840
 	/**
@@ -842,23 +842,23 @@  discard block
 block discarded – undo
842 842
 	 *
843 843
 	 * @throws ConstraintParameterException
844 844
 	 */
845
-	private function parseUnitItem( ItemIdSnakValue $item ): UnitsParameter {
846
-		switch ( true ) {
845
+	private function parseUnitItem(ItemIdSnakValue $item): UnitsParameter {
846
+		switch (true) {
847 847
 			case $item->isValue():
848
-				$unit = $this->parseUnitParameter( $item->getItemId() );
848
+				$unit = $this->parseUnitParameter($item->getItemId());
849 849
 				return new UnitsParameter(
850
-					[ $item->getItemId() ],
851
-					[ UnboundedQuantityValue::newFromNumber( 1, $unit ) ],
850
+					[$item->getItemId()],
851
+					[UnboundedQuantityValue::newFromNumber(1, $unit)],
852 852
 					false
853 853
 				);
854 854
 			case $item->isSomeValue():
855
-				$qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
855
+				$qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
856 856
 				throw new ConstraintParameterException(
857
-					( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) )
858
-						->withEntityId( new NumericPropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
857
+					(new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue'))
858
+						->withEntityId(new NumericPropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY)
859 859
 				);
860 860
 			case $item->isNoValue():
861
-				return new UnitsParameter( [], [], true );
861
+				return new UnitsParameter([], [], true);
862 862
 		}
863 863
 	}
864 864
 
@@ -868,36 +868,36 @@  discard block
 block discarded – undo
868 868
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
869 869
 	 * @return UnitsParameter
870 870
 	 */
871
-	public function parseUnitsParameter( array $constraintParameters, string $constraintTypeItemId ): UnitsParameter {
872
-		$items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true );
871
+	public function parseUnitsParameter(array $constraintParameters, string $constraintTypeItemId): UnitsParameter {
872
+		$items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true);
873 873
 		$unitItems = [];
874 874
 		$unitQuantities = [];
875 875
 		$unitlessAllowed = false;
876 876
 
877
-		foreach ( $items as $item ) {
878
-			$unit = $this->parseUnitItem( $item );
879
-			$unitItems = array_merge( $unitItems, $unit->getUnitItemIds() );
880
-			$unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() );
877
+		foreach ($items as $item) {
878
+			$unit = $this->parseUnitItem($item);
879
+			$unitItems = array_merge($unitItems, $unit->getUnitItemIds());
880
+			$unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities());
881 881
 			$unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed();
882 882
 		}
883 883
 
884
-		if ( $unitQuantities === [] && !$unitlessAllowed ) {
884
+		if ($unitQuantities === [] && !$unitlessAllowed) {
885 885
 			throw new LogicException(
886 886
 				'The "units" parameter is required, and yet we seem to be missing any allowed unit'
887 887
 			);
888 888
 		}
889 889
 
890
-		return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed );
890
+		return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed);
891 891
 	}
892 892
 
893 893
 	private function getEntityTypeMapping(): array {
894 894
 		return [
895
-			$this->config->get( 'WBQualityConstraintsWikibaseItemId' ) => 'item',
896
-			$this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) => 'property',
897
-			$this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) => 'lexeme',
898
-			$this->config->get( 'WBQualityConstraintsWikibaseFormId' ) => 'form',
899
-			$this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) => 'sense',
900
-			$this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) => 'mediainfo',
895
+			$this->config->get('WBQualityConstraintsWikibaseItemId') => 'item',
896
+			$this->config->get('WBQualityConstraintsWikibasePropertyId') => 'property',
897
+			$this->config->get('WBQualityConstraintsWikibaseLexemeId') => 'lexeme',
898
+			$this->config->get('WBQualityConstraintsWikibaseFormId') => 'form',
899
+			$this->config->get('WBQualityConstraintsWikibaseSenseId') => 'sense',
900
+			$this->config->get('WBQualityConstraintsWikibaseMediaInfoId') => 'mediainfo',
901 901
 		];
902 902
 	}
903 903
 
@@ -907,10 +907,10 @@  discard block
 block discarded – undo
907 907
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
908 908
 	 * @return EntityTypesParameter
909 909
 	 */
910
-	public function parseEntityTypesParameter( array $constraintParameters, string $constraintTypeItemId ): EntityTypesParameter {
910
+	public function parseEntityTypesParameter(array $constraintParameters, string $constraintTypeItemId): EntityTypesParameter {
911 911
 		$entityTypes = [];
912 912
 		$entityTypeItemIds = [];
913
-		$parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
913
+		$parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
914 914
 		$itemIds = $this->parseItemIdsParameter(
915 915
 			$constraintParameters,
916 916
 			$constraintTypeItemId,
@@ -919,22 +919,22 @@  discard block
 block discarded – undo
919 919
 		);
920 920
 
921 921
 		$mapping = $this->getEntityTypeMapping();
922
-		foreach ( $itemIds as $itemId ) {
923
-			$entityType = $this->mapItemId( $itemId, $mapping, $parameterId );
922
+		foreach ($itemIds as $itemId) {
923
+			$entityType = $this->mapItemId($itemId, $mapping, $parameterId);
924 924
 			$entityTypes[] = $entityType;
925 925
 			$entityTypeItemIds[] = $itemId;
926 926
 		}
927 927
 
928
-		if ( $entityTypes === [] ) {
928
+		if ($entityTypes === []) {
929 929
 			// @codeCoverageIgnoreStart
930 930
 			throw new LogicException(
931
-				'The "entity types" parameter is required, ' .
931
+				'The "entity types" parameter is required, '.
932 932
 				'and yet we seem to be missing any allowed entity type'
933 933
 			);
934 934
 			// @codeCoverageIgnoreEnd
935 935
 		}
936 936
 
937
-		return new EntityTypesParameter( $entityTypes, $entityTypeItemIds );
937
+		return new EntityTypesParameter($entityTypes, $entityTypeItemIds);
938 938
 	}
939 939
 
940 940
 	/**
@@ -942,18 +942,18 @@  discard block
 block discarded – undo
942 942
 	 * @throws ConstraintParameterException if the parameter is invalid
943 943
 	 * @return PropertyId[]
944 944
 	 */
945
-	public function parseSeparatorsParameter( array $constraintParameters ): array {
946
-		$separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' );
945
+	public function parseSeparatorsParameter(array $constraintParameters): array {
946
+		$separatorId = $this->config->get('WBQualityConstraintsSeparatorId');
947 947
 
948
-		if ( !array_key_exists( $separatorId, $constraintParameters ) ) {
948
+		if (!array_key_exists($separatorId, $constraintParameters)) {
949 949
 			return [];
950 950
 		}
951 951
 
952 952
 		$parameters = $constraintParameters[$separatorId];
953 953
 		$separators = [];
954 954
 
955
-		foreach ( $parameters as $parameter ) {
956
-			$separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId );
955
+		foreach ($parameters as $parameter) {
956
+			$separators[] = $this->parsePropertyIdParameter($parameter, $separatorId);
957 957
 		}
958 958
 
959 959
 		return $separators;
@@ -961,17 +961,17 @@  discard block
 block discarded – undo
961 961
 
962 962
 	private function getConstraintScopeContextTypeMapping(): array {
963 963
 		return [
964
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ) => Context::TYPE_STATEMENT,
965
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ) => Context::TYPE_QUALIFIER,
966
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ) => Context::TYPE_REFERENCE,
964
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId') => Context::TYPE_STATEMENT,
965
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId') => Context::TYPE_QUALIFIER,
966
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId') => Context::TYPE_REFERENCE,
967 967
 		];
968 968
 	}
969 969
 
970 970
 	private function getPropertyScopeContextTypeMapping(): array {
971 971
 		return [
972
-			$this->config->get( 'WBQualityConstraintsAsMainValueId' ) => Context::TYPE_STATEMENT,
973
-			$this->config->get( 'WBQualityConstraintsAsQualifiersId' ) => Context::TYPE_QUALIFIER,
974
-			$this->config->get( 'WBQualityConstraintsAsReferencesId' ) => Context::TYPE_REFERENCE,
972
+			$this->config->get('WBQualityConstraintsAsMainValueId') => Context::TYPE_STATEMENT,
973
+			$this->config->get('WBQualityConstraintsAsQualifiersId') => Context::TYPE_QUALIFIER,
974
+			$this->config->get('WBQualityConstraintsAsReferencesId') => Context::TYPE_REFERENCE,
975 975
 		];
976 976
 	}
977 977
 
@@ -981,9 +981,9 @@  discard block
 block discarded – undo
981 981
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
982 982
 	 * @return string[] list of Context::TYPE_* constants
983 983
 	 */
984
-	public function parsePropertyScopeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
984
+	public function parsePropertyScopeParameter(array $constraintParameters, string $constraintTypeItemId): array {
985 985
 		$contextTypes = [];
986
-		$parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' );
986
+		$parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId');
987 987
 		$itemIds = $this->parseItemIdsParameter(
988 988
 			$constraintParameters,
989 989
 			$constraintTypeItemId,
@@ -992,14 +992,14 @@  discard block
 block discarded – undo
992 992
 		);
993 993
 
994 994
 		$mapping = $this->getPropertyScopeContextTypeMapping();
995
-		foreach ( $itemIds as $itemId ) {
996
-			$contextTypes[] = $this->mapItemId( $itemId, $mapping, $parameterId );
995
+		foreach ($itemIds as $itemId) {
996
+			$contextTypes[] = $this->mapItemId($itemId, $mapping, $parameterId);
997 997
 		}
998 998
 
999
-		if ( $contextTypes === [] ) {
999
+		if ($contextTypes === []) {
1000 1000
 			// @codeCoverageIgnoreStart
1001 1001
 			throw new LogicException(
1002
-				'The "property scope" parameter is required, ' .
1002
+				'The "property scope" parameter is required, '.
1003 1003
 				'and yet we seem to be missing any allowed scope'
1004 1004
 			);
1005 1005
 			// @codeCoverageIgnoreEnd
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/SparqlHelper.php 1 patch
Spacing   +232 added lines, -236 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
 
@@ -166,143 +166,143 @@  discard block
 block discarded – undo
166 166
 		$this->defaultUserAgent = $defaultUserAgent;
167 167
 		$this->requestFactory = $requestFactory;
168 168
 		$this->entityPrefixes = [];
169
-		foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) {
170
-			$this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName );
169
+		foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) {
170
+			$this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName);
171 171
 		}
172 172
 
173
-		$this->primaryEndpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' );
174
-		$this->additionalEndpoints = $config->get( 'WBQualityConstraintsAdditionalSparqlEndpoints' ) ?: [];
175
-		$this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' );
176
-		$this->subclassOfId = new NumericPropertyId( $config->get( 'WBQualityConstraintsSubclassOfId' ) );
177
-		$this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' );
173
+		$this->primaryEndpoint = $config->get('WBQualityConstraintsSparqlEndpoint');
174
+		$this->additionalEndpoints = $config->get('WBQualityConstraintsAdditionalSparqlEndpoints') ?: [];
175
+		$this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis');
176
+		$this->subclassOfId = new NumericPropertyId($config->get('WBQualityConstraintsSubclassOfId'));
177
+		$this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize');
178 178
 		$this->timeoutExceptionClasses = $config->get(
179 179
 			'WBQualityConstraintsSparqlTimeoutExceptionClasses'
180 180
 		);
181 181
 		$this->sparqlHasWikibaseSupport = $config->get(
182 182
 			'WBQualityConstraintsSparqlHasWikibaseSupport'
183 183
 		);
184
-		$this->sparqlThrottlingFallbackDuration = (int)$config->get(
184
+		$this->sparqlThrottlingFallbackDuration = (int) $config->get(
185 185
 			'WBQualityConstraintsSparqlThrottlingFallbackDuration'
186 186
 		);
187 187
 
188
-		$this->prefixes = $this->getQueryPrefixes( $rdfVocabulary );
188
+		$this->prefixes = $this->getQueryPrefixes($rdfVocabulary);
189 189
 
190 190
 		$this->rdfVocabularyWithoutNormalization = clone $rdfVocabulary;
191 191
 		// @phan-suppress-next-line PhanTypeMismatchProperty
192 192
 		$this->rdfVocabularyWithoutNormalization->normalizedPropertyValueNamespace = array_fill_keys(
193
-			array_keys( $rdfVocabulary->normalizedPropertyValueNamespace ),
193
+			array_keys($rdfVocabulary->normalizedPropertyValueNamespace),
194 194
 			null
195 195
 		);
196 196
 	}
197 197
 
198
-	private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ): string {
198
+	private function getQueryPrefixes(RdfVocabulary $rdfVocabulary): string {
199 199
 		// TODO: it would probably be smarter that RdfVocabulary exposed these prefixes somehow
200 200
 		$prefixes = '';
201
-		foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) {
201
+		foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) {
202 202
 			$prefixes .= <<<END
203
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
203
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
204 204
 END;
205 205
 		}
206 206
 
207
-		foreach ( $rdfVocabulary->statementNamespaceNames as $sourceName => $sourceNamespaces ) {
207
+		foreach ($rdfVocabulary->statementNamespaceNames as $sourceName => $sourceNamespaces) {
208 208
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NS_VALUE];
209 209
 			$prefixes .= <<<END
210
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
210
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
211 211
 END;
212 212
 		}
213 213
 
214
-		foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) {
214
+		foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) {
215 215
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM];
216 216
 			$prefixes .= <<<END
217
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
217
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
218 218
 END;
219 219
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM];
220 220
 			$prefixes .= <<<END
221
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
221
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
222 222
 END;
223 223
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT];
224 224
 			$prefixes .= <<<END
225
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
225
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
226 226
 END;
227 227
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_VALUE];
228 228
 			$prefixes .= <<<END
229
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
229
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
230 230
 END;
231 231
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER];
232 232
 			$prefixes .= <<<END
233
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
233
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
234 234
 END;
235 235
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE];
236 236
 			$prefixes .= <<<END
237
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
237
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
238 238
 END;
239 239
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE];
240 240
 			$prefixes .= <<<END
241
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
241
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
242 242
 END;
243 243
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE];
244 244
 			$prefixes .= <<<END
245
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
245
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
246 246
 END;
247 247
 		}
248 248
 		$namespaceName = RdfVocabulary::NS_ONTOLOGY;
249 249
 		$prefixes .= <<<END
250
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
250
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
251 251
 END;
252 252
 		return $prefixes;
253 253
 	}
254 254
 
255 255
 	/** Return a SPARQL term like `wd:Q123` for the given ID. */
256
-	private function wd( EntityId $id ): string {
257
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
256
+	private function wd(EntityId $id): string {
257
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
258 258
 		$prefix = $this->rdfVocabulary->entityNamespaceNames[$repository];
259 259
 		return "$prefix:{$id->getSerialization()}";
260 260
 	}
261 261
 
262 262
 	/** Return a SPARQL term like `wdt:P123` for the given ID. */
263
-	private function wdt( PropertyId $id ): string {
264
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
263
+	private function wdt(PropertyId $id): string {
264
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
265 265
 		$prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_DIRECT_CLAIM];
266 266
 		return "$prefix:{$id->getSerialization()}";
267 267
 	}
268 268
 
269 269
 	/** Return a SPARQL term like `p:P123` for the given ID. */
270
-	private function p( PropertyId $id ): string {
271
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
270
+	private function p(PropertyId $id): string {
271
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
272 272
 		$prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_CLAIM];
273 273
 		return "$prefix:{$id->getSerialization()}";
274 274
 	}
275 275
 
276 276
 	/** Return a SPARQL term like `pq:P123` for the given ID. */
277
-	private function pq( PropertyId $id ): string {
278
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
277
+	private function pq(PropertyId $id): string {
278
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
279 279
 		$prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_QUALIFIER];
280 280
 		return "$prefix:{$id->getSerialization()}";
281 281
 	}
282 282
 
283 283
 	/** Return a SPARQL term like `wdno:P123` for the given ID. */
284
-	private function wdno( PropertyId $id ): string {
285
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
284
+	private function wdno(PropertyId $id): string {
285
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
286 286
 		$prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_NOVALUE];
287 287
 		return "$prefix:{$id->getSerialization()}";
288 288
 	}
289 289
 
290 290
 	/** Return a SPARQL term like `prov:NAME` for the given name. */
291
-	private function prov( string $name ): string {
291
+	private function prov(string $name): string {
292 292
 		$prefix = RdfVocabulary::NS_PROV;
293 293
 		return "$prefix:$name";
294 294
 	}
295 295
 
296 296
 	/** Return a SPARQL term like `wikibase:NAME` for the given name. */
297
-	private function wikibase( string $name ): string {
297
+	private function wikibase(string $name): string {
298 298
 		$prefix = RdfVocabulary::NS_ONTOLOGY;
299 299
 		return "$prefix:$name";
300 300
 	}
301 301
 
302 302
 	/** Return a SPARQL snippet like `MINUS { ?var wikibase:rank wikibase:DeprecatedRank. }`. */
303
-	private function minusDeprecatedRank( string $varName ): string {
303
+	private function minusDeprecatedRank(string $varName): string {
304 304
 		$deprecatedRank = RdfVocabulary::RANK_MAP[Statement::RANK_DEPRECATED];
305
-		return "MINUS { $varName {$this->wikibase( 'rank' )} {$this->wikibase( $deprecatedRank )}. }";
305
+		return "MINUS { $varName {$this->wikibase('rank')} {$this->wikibase($deprecatedRank)}. }";
306 306
 	}
307 307
 
308 308
 	/**
@@ -312,43 +312,42 @@  discard block
 block discarded – undo
312 312
 	 * @return CachedBool
313 313
 	 * @throws SparqlHelperException if the query times out or some other error occurs
314 314
 	 */
315
-	public function hasType( EntityId $id, array $classes ): CachedBool {
315
+	public function hasType(EntityId $id, array $classes): CachedBool {
316 316
 		// TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually
317 317
 		$gearingHint = $this->sparqlHasWikibaseSupport ?
318
-			' hint:Prior hint:gearing "forward".' :
319
-			'';
318
+			' hint:Prior hint:gearing "forward".' : '';
320 319
 
321 320
 		$metadatas = [];
322 321
 
323
-		foreach ( array_chunk( $classes, 20 ) as $classesChunk ) {
324
-			$classesValues = implode( ' ', array_map(
325
-				function ( string $class ) {
326
-					return $this->wd( new ItemId( $class ) );
322
+		foreach (array_chunk($classes, 20) as $classesChunk) {
323
+			$classesValues = implode(' ', array_map(
324
+				function(string $class) {
325
+					return $this->wd(new ItemId($class));
327 326
 				},
328 327
 				$classesChunk
329
-			) );
328
+			));
330 329
 
331 330
 			$query = <<<EOF
332 331
 ASK {
333
-  BIND({$this->wd( $id )} AS ?item)
332
+  BIND({$this->wd($id)} AS ?item)
334 333
   VALUES ?class { $classesValues }
335
-  ?item {$this->wdt( $this->subclassOfId )}* ?class.$gearingHint
334
+  ?item {$this->wdt($this->subclassOfId)}* ?class.$gearingHint
336 335
 }
337 336
 EOF;
338 337
 
339
-			$result = $this->runQuery( $query, $this->primaryEndpoint );
338
+			$result = $this->runQuery($query, $this->primaryEndpoint);
340 339
 			$metadatas[] = $result->getMetadata();
341
-			if ( $result->getArray()['boolean'] ) {
340
+			if ($result->getArray()['boolean']) {
342 341
 				return new CachedBool(
343 342
 					true,
344
-					Metadata::merge( $metadatas )
343
+					Metadata::merge($metadatas)
345 344
 				);
346 345
 			}
347 346
 		}
348 347
 
349 348
 		return new CachedBool(
350 349
 			false,
351
-			Metadata::merge( $metadatas )
350
+			Metadata::merge($metadatas)
352 351
 		);
353 352
 	}
354 353
 
@@ -366,12 +365,12 @@  discard block
 block discarded – undo
366 365
 		array $separators
367 366
 	): CachedEntityIds {
368 367
 		$mainSnak = $statement->getMainSnak();
369
-		if ( !( $mainSnak instanceof PropertyValueSnak ) ) {
370
-			return new CachedEntityIds( [], Metadata::blank() );
368
+		if (!($mainSnak instanceof PropertyValueSnak)) {
369
+			return new CachedEntityIds([], Metadata::blank());
371 370
 		}
372 371
 
373 372
 		$propertyId = $statement->getPropertyId();
374
-		$pPredicateAndObject = "{$this->p( $propertyId )} ?otherStatement."; // p:P123 ?otherStatement.
373
+		$pPredicateAndObject = "{$this->p($propertyId)} ?otherStatement."; // p:P123 ?otherStatement.
375 374
 		$otherStatementPredicateAndObject = $this->getSnakPredicateAndObject(
376 375
 			$entityId,
377 376
 			$mainSnak,
@@ -380,57 +379,57 @@  discard block
 block discarded – undo
380 379
 
381 380
 		$isSeparator = [];
382 381
 		$unusedSeparators = [];
383
-		foreach ( $separators as $separator ) {
382
+		foreach ($separators as $separator) {
384 383
 			$isSeparator[$separator->getSerialization()] = true;
385 384
 			$unusedSeparators[$separator->getSerialization()] = $separator;
386 385
 		}
387 386
 		$separatorFilters = '';
388
-		foreach ( $statement->getQualifiers() as $qualifier ) {
387
+		foreach ($statement->getQualifiers() as $qualifier) {
389 388
 			$qualPropertyId = $qualifier->getPropertyId();
390
-			if ( !( $isSeparator[$qualPropertyId->getSerialization()] ?? false ) ) {
389
+			if (!($isSeparator[$qualPropertyId->getSerialization()] ?? false)) {
391 390
 				continue;
392 391
 			}
393
-			unset( $unusedSeparators[$qualPropertyId->getSerialization()] );
392
+			unset($unusedSeparators[$qualPropertyId->getSerialization()]);
394 393
 			// only look for other statements with the same qualifier
395
-			if ( $qualifier instanceof PropertyValueSnak ) {
394
+			if ($qualifier instanceof PropertyValueSnak) {
396 395
 				$sepPredicateAndObject = $this->getSnakPredicateAndObject(
397 396
 					$entityId,
398 397
 					$qualifier,
399 398
 					RdfVocabulary::NSP_QUALIFIER
400 399
 				);
401 400
 				$separatorFilters .= "  ?otherStatement $sepPredicateAndObject\n";
402
-			} elseif ( $qualifier instanceof PropertyNoValueSnak ) {
403
-				$sepPredicateAndObject = "a {$this->wdno( $qualPropertyId )}."; // a wdno:P123.
401
+			} elseif ($qualifier instanceof PropertyNoValueSnak) {
402
+				$sepPredicateAndObject = "a {$this->wdno($qualPropertyId)}."; // a wdno:P123.
404 403
 				$separatorFilters .= "  ?otherStatement $sepPredicateAndObject\n";
405 404
 			} else {
406 405
 				// "some value" / "unknown value" is always different from everything else,
407 406
 				// therefore the whole statement has no duplicates and we can return immediately
408
-				return new CachedEntityIds( [], Metadata::blank() );
407
+				return new CachedEntityIds([], Metadata::blank());
409 408
 			}
410 409
 		}
411
-		foreach ( $unusedSeparators as $unusedSeparator ) {
410
+		foreach ($unusedSeparators as $unusedSeparator) {
412 411
 			// exclude other statements which have a separator that this one lacks
413
-			$separatorFilters .= "  MINUS { ?otherStatement {$this->pq( $unusedSeparator )} []. }\n";
414
-			$separatorFilters .= "  MINUS { ?otherStatement a {$this->wdno( $unusedSeparator )}. }\n";
412
+			$separatorFilters .= "  MINUS { ?otherStatement {$this->pq($unusedSeparator)} []. }\n";
413
+			$separatorFilters .= "  MINUS { ?otherStatement a {$this->wdno($unusedSeparator)}. }\n";
415 414
 		}
416 415
 
417 416
 		$query = <<<SPARQL
418 417
 SELECT DISTINCT ?otherEntity WHERE {
419 418
   ?otherEntity $pPredicateAndObject
420 419
   ?otherStatement $otherStatementPredicateAndObject
421
-  {$this->minusDeprecatedRank( '?otherStatement' )}
422
-  FILTER(?otherEntity != {$this->wd( $entityId )})
420
+  {$this->minusDeprecatedRank('?otherStatement')}
421
+  FILTER(?otherEntity != {$this->wd($entityId)})
423 422
 $separatorFilters
424 423
 }
425 424
 LIMIT 10
426 425
 SPARQL;
427 426
 
428
-		$results = [ $this->runQuery( $query, $this->primaryEndpoint ) ];
429
-		foreach ( $this->additionalEndpoints as $endpoint ) {
430
-			$results[] = $this->runQuery( $query, $endpoint );
427
+		$results = [$this->runQuery($query, $this->primaryEndpoint)];
428
+		foreach ($this->additionalEndpoints as $endpoint) {
429
+			$results[] = $this->runQuery($query, $endpoint);
431 430
 		}
432 431
 
433
-		return $this->getOtherEntities( $results );
432
+		return $this->getOtherEntities($results);
434 433
 	}
435 434
 
436 435
 	/**
@@ -449,40 +448,38 @@  discard block
 block discarded – undo
449 448
 		bool $ignoreDeprecatedStatements
450 449
 	): CachedEntityIds {
451 450
 		$propertyId = $snak->getPropertyId();
452
-		$pPredicateAndObject = "{$this->p( $propertyId )} ?otherStatement."; // p:P123 ?otherStatement.
451
+		$pPredicateAndObject = "{$this->p($propertyId)} ?otherStatement."; // p:P123 ?otherStatement.
453 452
 
454 453
 		$otherSubject = $type === Context::TYPE_QUALIFIER ?
455
-			'?otherStatement' :
456
-			"?otherStatement {$this->prov( 'wasDerivedFrom' )} ?reference.\n  ?reference";
454
+			'?otherStatement' : "?otherStatement {$this->prov('wasDerivedFrom')} ?reference.\n  ?reference";
457 455
 		$otherPredicateAndObject = $this->getSnakPredicateAndObject(
458 456
 			$entityId,
459 457
 			$snak,
460 458
 			$type === Context::TYPE_QUALIFIER ?
461
-				RdfVocabulary::NSP_QUALIFIER :
462
-				RdfVocabulary::NSP_REFERENCE
459
+				RdfVocabulary::NSP_QUALIFIER : RdfVocabulary::NSP_REFERENCE
463 460
 		);
464 461
 
465 462
 		$deprecatedFilter = '';
466
-		if ( $ignoreDeprecatedStatements ) {
467
-			$deprecatedFilter = '  ' . $this->minusDeprecatedRank( '?otherStatement' );
463
+		if ($ignoreDeprecatedStatements) {
464
+			$deprecatedFilter = '  '.$this->minusDeprecatedRank('?otherStatement');
468 465
 		}
469 466
 
470 467
 		$query = <<<SPARQL
471 468
 SELECT DISTINCT ?otherEntity WHERE {
472 469
   ?otherEntity $pPredicateAndObject
473 470
   $otherSubject $otherPredicateAndObject
474
-  FILTER(?otherEntity != {$this->wd( $entityId )})
471
+  FILTER(?otherEntity != {$this->wd($entityId)})
475 472
 $deprecatedFilter
476 473
 }
477 474
 LIMIT 10
478 475
 SPARQL;
479 476
 
480
-		$results = [ $this->runQuery( $query, $this->primaryEndpoint ) ];
481
-		foreach ( $this->additionalEndpoints as $endpoint ) {
482
-			$results[] = $this->runQuery( $query, $endpoint );
477
+		$results = [$this->runQuery($query, $this->primaryEndpoint)];
478
+		foreach ($this->additionalEndpoints as $endpoint) {
479
+			$results[] = $this->runQuery($query, $endpoint);
483 480
 		}
484 481
 
485
-		return $this->getOtherEntities( $results );
482
+		return $this->getOtherEntities($results);
486 483
 	}
487 484
 
488 485
 	/**
@@ -513,13 +510,13 @@  discard block
 block discarded – undo
513 510
 		$writer->start();
514 511
 		$writer->drain();
515 512
 		$placeholder1 = 'wbqc';
516
-		$placeholder2 = 'x' . wfRandomString( 32 );
517
-		$writer->about( $placeholder1, $placeholder2 );
513
+		$placeholder2 = 'x'.wfRandomString(32);
514
+		$writer->about($placeholder1, $placeholder2);
518 515
 
519 516
 		$propertyId = $snak->getPropertyId();
520 517
 		$pid = $propertyId->getSerialization();
521
-		$propertyRepository = $this->rdfVocabulary->getEntityRepositoryName( $propertyId );
522
-		$entityRepository = $this->rdfVocabulary->getEntityRepositoryName( $entityId );
518
+		$propertyRepository = $this->rdfVocabulary->getEntityRepositoryName($propertyId);
519
+		$entityRepository = $this->rdfVocabulary->getEntityRepositoryName($entityId);
523 520
 		$propertyNamespace = $this->rdfVocabulary->propertyNamespaceNames[$propertyRepository][$namespace];
524 521
 		$value = $snak->getDataValue();
525 522
 		if (
@@ -550,21 +547,21 @@  discard block
 block discarded – undo
550 547
 				$writer,
551 548
 				$propertyNamespace,
552 549
 				$pid,
553
-				$this->propertyDataTypeLookup->getDataTypeIdForProperty( $propertyId ),
550
+				$this->propertyDataTypeLookup->getDataTypeIdForProperty($propertyId),
554 551
 				$this->rdfVocabulary->statementNamespaceNames[$entityRepository][RdfVocabulary::NS_VALUE], // should be unused
555 552
 				$snak
556 553
 			);
557 554
 		}
558 555
 
559 556
 		$triple = $writer->drain(); // wbqc:xRANDOM ps:PID "value". or similar
560
-		return trim( str_replace( "$placeholder1:$placeholder2", '', $triple ) );
557
+		return trim(str_replace("$placeholder1:$placeholder2", '', $triple));
561 558
 	}
562 559
 
563 560
 	/**
564 561
 	 * Return SPARQL code for a string literal with $text as content.
565 562
 	 */
566
-	private function stringLiteral( string $text ): string {
567
-		return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"';
563
+	private function stringLiteral(string $text): string {
564
+		return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"';
568 565
 	}
569 566
 
570 567
 	/**
@@ -574,26 +571,26 @@  discard block
 block discarded – undo
574 571
 	 *
575 572
 	 * @return CachedEntityIds
576 573
 	 */
577
-	private function getOtherEntities( array $results ): CachedEntityIds {
574
+	private function getOtherEntities(array $results): CachedEntityIds {
578 575
 		$allResultBindings = [];
579 576
 		$metadatas = [];
580 577
 
581
-		foreach ( $results as $result ) {
578
+		foreach ($results as $result) {
582 579
 			$metadatas[] = $result->getMetadata();
583
-			$allResultBindings = array_merge( $allResultBindings, $result->getArray()['results']['bindings'] );
580
+			$allResultBindings = array_merge($allResultBindings, $result->getArray()['results']['bindings']);
584 581
 		}
585 582
 
586 583
 		$entityIds = array_map(
587
-			function ( $resultBindings ) {
584
+			function($resultBindings) {
588 585
 				$entityIRI = $resultBindings['otherEntity']['value'];
589
-				foreach ( $this->entityPrefixes as $entityPrefix ) {
590
-					$entityPrefixLength = strlen( $entityPrefix );
591
-					if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) {
586
+				foreach ($this->entityPrefixes as $entityPrefix) {
587
+					$entityPrefixLength = strlen($entityPrefix);
588
+					if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) {
592 589
 						try {
593 590
 							return $this->entityIdParser->parse(
594
-								substr( $entityIRI, $entityPrefixLength )
591
+								substr($entityIRI, $entityPrefixLength)
595 592
 							);
596
-						} catch ( EntityIdParsingException ) {
593
+						} catch (EntityIdParsingException) {
597 594
 							// fall through
598 595
 						}
599 596
 					}
@@ -607,8 +604,8 @@  discard block
 block discarded – undo
607 604
 		);
608 605
 
609 606
 		return new CachedEntityIds(
610
-			array_values( array_filter( array_unique( $entityIds ) ) ),
611
-			Metadata::merge( $metadatas )
607
+			array_values(array_filter(array_unique($entityIds))),
608
+			Metadata::merge($metadatas)
612 609
 		);
613 610
 	}
614 611
 
@@ -616,63 +613,63 @@  discard block
 block discarded – undo
616 613
 	 * @throws SparqlHelperException if the query times out or some other error occurs
617 614
 	 * @throws ConstraintParameterException if the $regex is invalid
618 615
 	 */
619
-	public function matchesRegularExpression( string $text, string $regex ): bool {
616
+	public function matchesRegularExpression(string $text, string $regex): bool {
620 617
 		// caching wrapper around matchesRegularExpressionWithSparql
621 618
 
622
-		$textHash = hash( 'sha256', $text );
619
+		$textHash = hash('sha256', $text);
623 620
 		$cacheKey = $this->cache->makeKey(
624 621
 			'WikibaseQualityConstraints', // extension
625 622
 			'regex', // action
626 623
 			'WDQS-Java', // regex flavor
627
-			hash( 'sha256', $regex )
624
+			hash('sha256', $regex)
628 625
 		);
629 626
 
630 627
 		$baseRegexCacheKey = 'wikibase.quality.constraints.regex.cache';
631
-		$metric = $this->statsFactory->getCounter( 'regex_cache_total' );
628
+		$metric = $this->statsFactory->getCounter('regex_cache_total');
632 629
 
633 630
 		$cacheMapArray = $this->cache->getWithSetCallback(
634 631
 			$cacheKey,
635 632
 			WANObjectCache::TTL_DAY,
636
-			function ( $cacheMapArray ) use ( $text, $regex, $textHash, $metric, $baseRegexCacheKey ) {
633
+			function($cacheMapArray) use ($text, $regex, $textHash, $metric, $baseRegexCacheKey) {
637 634
 				// Initialize the cache map if not set
638
-				if ( $cacheMapArray === false ) {
635
+				if ($cacheMapArray === false) {
639 636
 					$metric
640
-						->setLabel( 'operation', 'refresh' )
641
-						->setLabel( 'status', 'init' )
642
-						->copyToStatsdAt( [
637
+						->setLabel('operation', 'refresh')
638
+						->setLabel('status', 'init')
639
+						->copyToStatsdAt([
643 640
 							"$baseRegexCacheKey.refresh.init",
644
-						] )->increment();
641
+						])->increment();
645 642
 
646 643
 					return [];
647 644
 				}
648 645
 
649
-				$cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize );
650
-				if ( $cacheMap->has( $textHash ) ) {
646
+				$cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize);
647
+				if ($cacheMap->has($textHash)) {
651 648
 					$metric
652
-						->setLabel( 'operation', 'refresh' )
653
-						->setLabel( 'status', 'hit' )
654
-						->copyToStatsdAt( [
649
+						->setLabel('operation', 'refresh')
650
+						->setLabel('status', 'hit')
651
+						->copyToStatsdAt([
655 652
 							"$baseRegexCacheKey.refresh",
656 653
 							"$baseRegexCacheKey.refresh.hit",
657
-						] )
654
+						])
658 655
 						->increment();
659 656
 
660
-					$cacheMap->get( $textHash ); // ping cache
657
+					$cacheMap->get($textHash); // ping cache
661 658
 				} else {
662 659
 					$metric
663
-						->setLabel( 'operation', 'refresh' )
664
-						->setLabel( 'status', 'miss' )
665
-						->copyToStatsdAt( [
660
+						->setLabel('operation', 'refresh')
661
+						->setLabel('status', 'miss')
662
+						->copyToStatsdAt([
666 663
 							"$baseRegexCacheKey.refresh",
667 664
 							"$baseRegexCacheKey.refresh.miss",
668
-						] )
665
+						])
669 666
 						->increment();
670 667
 
671 668
 					try {
672
-						$matches = $this->matchesRegularExpressionWithSparql( $text, $regex );
673
-					} catch ( ConstraintParameterException $e ) {
674
-						$matches = $this->serializeConstraintParameterException( $e );
675
-					} catch ( SparqlHelperException ) {
669
+						$matches = $this->matchesRegularExpressionWithSparql($text, $regex);
670
+					} catch (ConstraintParameterException $e) {
671
+						$matches = $this->serializeConstraintParameterException($e);
672
+					} catch (SparqlHelperException) {
676 673
 						// don’t cache this
677 674
 						return $cacheMap->toArray();
678 675
 					}
@@ -696,54 +693,54 @@  discard block
 block discarded – undo
696 693
 			]
697 694
 		);
698 695
 
699
-		if ( isset( $cacheMapArray[$textHash] ) ) {
696
+		if (isset($cacheMapArray[$textHash])) {
700 697
 			$metric
701
-				->setLabel( 'operation', 'none' )
702
-				->setLabel( 'status', 'hit' )
703
-				->copyToStatsdAt( [
698
+				->setLabel('operation', 'none')
699
+				->setLabel('status', 'hit')
700
+				->copyToStatsdAt([
704 701
 					"$baseRegexCacheKey.hit",
705
-				] )
702
+				])
706 703
 				->increment();
707 704
 
708 705
 			$matches = $cacheMapArray[$textHash];
709
-			if ( is_bool( $matches ) ) {
706
+			if (is_bool($matches)) {
710 707
 				return $matches;
711
-			} elseif ( is_array( $matches ) &&
712
-				$matches['type'] == ConstraintParameterException::class ) {
713
-				throw $this->deserializeConstraintParameterException( $matches );
708
+			} elseif (is_array($matches) &&
709
+				$matches['type'] == ConstraintParameterException::class) {
710
+				throw $this->deserializeConstraintParameterException($matches);
714 711
 			} else {
715 712
 				throw new UnexpectedValueException(
716
-					'Value of unknown type in object cache (' .
717
-					'cache key: ' . $cacheKey . ', ' .
718
-					'cache map key: ' . $textHash . ', ' .
719
-					'value type: ' . get_debug_type( $matches ) . ')'
713
+					'Value of unknown type in object cache ('.
714
+					'cache key: '.$cacheKey.', '.
715
+					'cache map key: '.$textHash.', '.
716
+					'value type: '.get_debug_type($matches).')'
720 717
 				);
721 718
 			}
722 719
 		} else {
723 720
 			$metric
724
-				->setLabel( 'operation', 'none' )
725
-				->setLabel( 'status', 'miss' )
726
-				->copyToStatsdAt( [
721
+				->setLabel('operation', 'none')
722
+				->setLabel('status', 'miss')
723
+				->copyToStatsdAt([
727 724
 					"$baseRegexCacheKey.miss",
728
-				] )
725
+				])
729 726
 				->increment();
730 727
 
731
-			return $this->matchesRegularExpressionWithSparql( $text, $regex );
728
+			return $this->matchesRegularExpressionWithSparql($text, $regex);
732 729
 		}
733 730
 	}
734 731
 
735
-	private function serializeConstraintParameterException( ConstraintParameterException $cpe ): array {
732
+	private function serializeConstraintParameterException(ConstraintParameterException $cpe): array {
736 733
 		return [
737 734
 			'type' => ConstraintParameterException::class,
738
-			'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ),
735
+			'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()),
739 736
 		];
740 737
 	}
741 738
 
742
-	private function deserializeConstraintParameterException( array $serialization ): ConstraintParameterException {
739
+	private function deserializeConstraintParameterException(array $serialization): ConstraintParameterException {
743 740
 		$message = $this->violationMessageDeserializer->deserialize(
744 741
 			$serialization['violationMessage']
745 742
 		);
746
-		return new ConstraintParameterException( $message );
743
+		return new ConstraintParameterException($message);
747 744
 	}
748 745
 
749 746
 	/**
@@ -753,25 +750,25 @@  discard block
 block discarded – undo
753 750
 	 * @throws SparqlHelperException if the query times out or some other error occurs
754 751
 	 * @throws ConstraintParameterException if the $regex is invalid
755 752
 	 */
756
-	public function matchesRegularExpressionWithSparql( string $text, string $regex ): bool {
757
-		$textStringLiteral = $this->stringLiteral( $text );
758
-		$regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' );
753
+	public function matchesRegularExpressionWithSparql(string $text, string $regex): bool {
754
+		$textStringLiteral = $this->stringLiteral($text);
755
+		$regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$');
759 756
 
760 757
 		$query = <<<EOF
761 758
 SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {}
762 759
 EOF;
763 760
 
764
-		$result = $this->runQuery( $query, $this->primaryEndpoint, false );
761
+		$result = $this->runQuery($query, $this->primaryEndpoint, false);
765 762
 
766 763
 		$vars = $result->getArray()['results']['bindings'][0];
767
-		if ( array_key_exists( 'matches', $vars ) ) {
764
+		if (array_key_exists('matches', $vars)) {
768 765
 			// true or false ⇒ regex okay, text matches or not
769 766
 			return $vars['matches']['value'] === 'true';
770 767
 		} else {
771 768
 			// empty result: regex broken
772 769
 			throw new ConstraintParameterException(
773
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
774
-					->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE )
770
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
771
+					->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE)
775 772
 			);
776 773
 		}
777 774
 	}
@@ -779,14 +776,14 @@  discard block
 block discarded – undo
779 776
 	/**
780 777
 	 * Check whether the text content of an error response indicates a query timeout.
781 778
 	 */
782
-	public function isTimeout( string $responseContent ): bool {
783
-		$timeoutRegex = implode( '|', array_map(
784
-			static function ( $fqn ) {
785
-				return preg_quote( $fqn, '/' );
779
+	public function isTimeout(string $responseContent): bool {
780
+		$timeoutRegex = implode('|', array_map(
781
+			static function($fqn) {
782
+				return preg_quote($fqn, '/');
786 783
 			},
787 784
 			$this->timeoutExceptionClasses
788
-		) );
789
-		return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent );
785
+		));
786
+		return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent);
790 787
 	}
791 788
 
792 789
 	/**
@@ -798,17 +795,17 @@  discard block
 block discarded – undo
798 795
 	 * @return int|bool the max-age (in seconds)
799 796
 	 * or a plain boolean if no max-age can be determined
800 797
 	 */
801
-	public function getCacheMaxAge( array $responseHeaders ) {
798
+	public function getCacheMaxAge(array $responseHeaders) {
802 799
 		if (
803
-			array_key_exists( 'x-cache-status', $responseHeaders ) &&
804
-			preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] )
800
+			array_key_exists('x-cache-status', $responseHeaders) &&
801
+			preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0])
805 802
 		) {
806 803
 			$maxage = [];
807 804
 			if (
808
-				array_key_exists( 'cache-control', $responseHeaders ) &&
809
-				preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage )
805
+				array_key_exists('cache-control', $responseHeaders) &&
806
+				preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage)
810 807
 			) {
811
-				return intval( $maxage[1] );
808
+				return intval($maxage[1]);
812 809
 			} else {
813 810
 				return true;
814 811
 			}
@@ -829,34 +826,34 @@  discard block
 block discarded – undo
829 826
 	 * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After
830 827
 	 * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format
831 828
 	 */
832
-	public function getThrottling( MWHttpRequest $request ) {
833
-		$retryAfterValue = $request->getResponseHeader( 'Retry-After' );
834
-		if ( $retryAfterValue === null ) {
829
+	public function getThrottling(MWHttpRequest $request) {
830
+		$retryAfterValue = $request->getResponseHeader('Retry-After');
831
+		if ($retryAfterValue === null) {
835 832
 			return self::NO_RETRY_AFTER;
836 833
 		}
837 834
 
838
-		$trimmedRetryAfterValue = trim( $retryAfterValue );
839
-		if ( $trimmedRetryAfterValue === '' ) {
835
+		$trimmedRetryAfterValue = trim($retryAfterValue);
836
+		if ($trimmedRetryAfterValue === '') {
840 837
 			return self::EMPTY_RETRY_AFTER;
841 838
 		}
842 839
 
843
-		if ( is_numeric( $trimmedRetryAfterValue ) ) {
844
-			$delaySeconds = (int)$trimmedRetryAfterValue;
845
-			if ( $delaySeconds >= 0 ) {
846
-				return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) );
840
+		if (is_numeric($trimmedRetryAfterValue)) {
841
+			$delaySeconds = (int) $trimmedRetryAfterValue;
842
+			if ($delaySeconds >= 0) {
843
+				return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S'));
847 844
 			}
848 845
 		} else {
849
-			$return = strtotime( $trimmedRetryAfterValue );
850
-			if ( $return !== false ) {
851
-				return new ConvertibleTimestamp( $return );
846
+			$return = strtotime($trimmedRetryAfterValue);
847
+			if ($return !== false) {
848
+				return new ConvertibleTimestamp($return);
852 849
 			}
853 850
 		}
854 851
 		return self::INVALID_RETRY_AFTER;
855 852
 	}
856 853
 
857
-	private function getTimestampInFuture( DateInterval $delta ): ConvertibleTimestamp {
854
+	private function getTimestampInFuture(DateInterval $delta): ConvertibleTimestamp {
858 855
 		$now = new ConvertibleTimestamp();
859
-		return new ConvertibleTimestamp( $now->timestamp->add( $delta ) );
856
+		return new ConvertibleTimestamp($now->timestamp->add($delta));
860 857
 	}
861 858
 
862 859
 	/**
@@ -871,109 +868,108 @@  discard block
 block discarded – undo
871 868
 	 *
872 869
 	 * @throws SparqlHelperException if the query times out or some other error occurs
873 870
 	 */
874
-	protected function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults {
871
+	protected function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults {
875 872
 		$baseSPARQLKey = 'wikibase.quality.constraints.sparql';
876 873
 
877
-		if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) {
874
+		if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) {
878 875
 			$this->statsFactory
879
-				->getCounter( 'sparql_throttling_total' )
880
-				->copyToStatsdAt( "$baseSPARQLKey.throttling" )
876
+				->getCounter('sparql_throttling_total')
877
+				->copyToStatsdAt("$baseSPARQLKey.throttling")
881 878
 				->increment();
882 879
 
883 880
 			throw new TooManySparqlRequestsException();
884 881
 		}
885 882
 
886
-		if ( $this->sparqlHasWikibaseSupport ) {
883
+		if ($this->sparqlHasWikibaseSupport) {
887 884
 			$needsPrefixes = false;
888 885
 		}
889 886
 
890
-		if ( $needsPrefixes ) {
891
-			$query = $this->prefixes . $query;
887
+		if ($needsPrefixes) {
888
+			$query = $this->prefixes.$query;
892 889
 		}
893
-		$query = "#wbqc\n" . $query;
890
+		$query = "#wbqc\n".$query;
894 891
 
895
-		$url = $endpoint . '?' . http_build_query(
892
+		$url = $endpoint.'?'.http_build_query(
896 893
 			[
897 894
 				'query' => $query,
898 895
 				'format' => 'json',
899 896
 				'maxQueryTimeMillis' => $this->maxQueryTimeMillis,
900 897
 			],
901
-			'', ini_get( 'arg_separator.output' ),
898
+			'', ini_get('arg_separator.output'),
902 899
 			// encode spaces with %20, not +
903 900
 			PHP_QUERY_RFC3986
904 901
 		);
905 902
 
906 903
 		$options = [
907 904
 			'method' => 'GET',
908
-			'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ),
905
+			'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000),
909 906
 			'connectTimeout' => 'default',
910 907
 			'userAgent' => $this->defaultUserAgent,
911 908
 		];
912
-		$request = $this->requestFactory->create( $url, $options, __METHOD__ );
909
+		$request = $this->requestFactory->create($url, $options, __METHOD__);
913 910
 
914 911
 		$timing = $this->statsFactory
915
-			->getTiming( 'sparql_runQuery_duration_seconds' )
916
-			->copyToStatsdAt( "$baseSPARQLKey.timing" );
912
+			->getTiming('sparql_runQuery_duration_seconds')
913
+			->copyToStatsdAt("$baseSPARQLKey.timing");
917 914
 
918 915
 		$timing->start();
919 916
 		$requestStatus = $request->execute();
920 917
 		$timing->stop();
921 918
 
922
-		$this->guardAgainstTooManyRequestsError( $request );
919
+		$this->guardAgainstTooManyRequestsError($request);
923 920
 
924
-		$maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() );
925
-		if ( $maxAge ) {
926
-			$this->statsFactory->getCounter( 'sparql_cached_total' )
927
-				->copyToStatsdAt( "$baseSPARQLKey.cached" )
921
+		$maxAge = $this->getCacheMaxAge($request->getResponseHeaders());
922
+		if ($maxAge) {
923
+			$this->statsFactory->getCounter('sparql_cached_total')
924
+				->copyToStatsdAt("$baseSPARQLKey.cached")
928 925
 				->increment();
929 926
 		}
930 927
 
931 928
 		$sparqlErrorKey = "$baseSPARQLKey.error";
932
-		$metric = $this->statsFactory->getCounter( 'sparql_error_total' );
933
-		if ( $requestStatus->isOK() ) {
929
+		$metric = $this->statsFactory->getCounter('sparql_error_total');
930
+		if ($requestStatus->isOK()) {
934 931
 			$json = $request->getContent();
935
-			$jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC );
936
-			if ( $jsonStatus->isOK() ) {
932
+			$jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC);
933
+			if ($jsonStatus->isOK()) {
937 934
 				return new CachedQueryResults(
938 935
 					$jsonStatus->getValue(),
939 936
 					Metadata::ofCachingMetadata(
940 937
 						$maxAge ?
941
-							CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) :
942
-							CachingMetadata::fresh()
938
+							CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh()
943 939
 					)
944 940
 				);
945 941
 			} else {
946 942
 				$jsonErrorCode = $jsonStatus->getErrors()[0]['message'];
947 943
 				$metric
948
-					->setLabel( 'type', 'json' )
949
-					->setLabel( 'code', "$jsonErrorCode" )
950
-					->copyToStatsdAt( [
944
+					->setLabel('type', 'json')
945
+					->setLabel('code', "$jsonErrorCode")
946
+					->copyToStatsdAt([
951 947
 						"$sparqlErrorKey",
952 948
 						"$sparqlErrorKey.json.$jsonErrorCode",
953
-					] )
949
+					])
954 950
 					->increment();
955 951
 				// fall through to general error handling
956 952
 			}
957 953
 		} else {
958 954
 			$metric
959
-				->setLabel( 'type', 'http' )
960
-				->setLabel( 'code', "{$request->getStatus()}" )
961
-				->copyToStatsdAt( [
955
+				->setLabel('type', 'http')
956
+				->setLabel('code', "{$request->getStatus()}")
957
+				->copyToStatsdAt([
962 958
 					"$sparqlErrorKey",
963 959
 					"$sparqlErrorKey.http.{$request->getStatus()}",
964
-				] )
960
+				])
965 961
 				->increment();
966 962
 			// fall through to general error handling
967 963
 		}
968 964
 
969
-		if ( $this->isTimeout( $request->getContent() ) ) {
965
+		if ($this->isTimeout($request->getContent())) {
970 966
 			$metric
971
-				->setLabel( 'type', 'timeout' )
972
-				->setLabel( 'code', 'none' )
973
-				->copyToStatsdAt( [
967
+				->setLabel('type', 'timeout')
968
+				->setLabel('code', 'none')
969
+				->copyToStatsdAt([
974 970
 					"$sparqlErrorKey",
975 971
 					"$sparqlErrorKey.timeout",
976
-				] )
972
+				])
977 973
 				->increment();
978 974
 		}
979 975
 
@@ -986,33 +982,33 @@  discard block
 block discarded – undo
986 982
 	 * @param MWHttpRequest $request
987 983
 	 * @throws TooManySparqlRequestsException
988 984
 	 */
989
-	private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void {
990
-		if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) {
985
+	private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void {
986
+		if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) {
991 987
 			return;
992 988
 		}
993 989
 
994 990
 		$fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration;
995 991
 
996
-		if ( $fallbackBlockDuration < 0 ) {
997
-			throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' .
998
-				$fallbackBlockDuration );
992
+		if ($fallbackBlockDuration < 0) {
993
+			throw new InvalidArgumentException('Fallback duration must be positive int but is: '.
994
+				$fallbackBlockDuration);
999 995
 		}
1000 996
 
1001 997
 		$throttlingKey = "wikibase.quality.constraints.sparql.throttling";
1002
-		$this->statsFactory->getCounter( 'sparql_throttling_total' )
1003
-			->copyToStatsdAt( $throttlingKey )
998
+		$this->statsFactory->getCounter('sparql_throttling_total')
999
+			->copyToStatsdAt($throttlingKey)
1004 1000
 			->increment();
1005 1001
 
1006
-		$throttlingUntil = $this->getThrottling( $request );
1007
-		if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) {
1008
-			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request );
1002
+		$throttlingUntil = $this->getThrottling($request);
1003
+		if (!($throttlingUntil instanceof ConvertibleTimestamp)) {
1004
+			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request);
1009 1005
 			$this->throttlingLock->lock(
1010 1006
 				self::EXPIRY_LOCK_ID,
1011
-				$this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) )
1007
+				$this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S'))
1012 1008
 			);
1013 1009
 		} else {
1014
-			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request );
1015
-			$this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil );
1010
+			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request);
1011
+			$this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil);
1016 1012
 		}
1017 1013
 		throw new TooManySparqlRequestsException();
1018 1014
 	}
Please login to merge, or discard this patch.