Completed
Push — master ( 5a9354...ab15cd )
by
unknown
46s
created
src/ConstraintCheck/DelegatingConstraintChecker.php 1 patch
Spacing   +162 added lines, -162 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,25 +201,25 @@  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 function ( $resultStatus ) {
206
+			static function($resultStatus) {
207 207
 				return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE;
208 208
 			}
209
-		) );
209
+		));
210 210
 	}
211 211
 
212
-	private function getValidEntityTypes( Constraint $constraint ): array {
213
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
214
-			return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED );
212
+	private function getValidEntityTypes(Constraint $constraint): array {
213
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
214
+			return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED);
215 215
 		}
216 216
 
217
-		return array_keys( array_filter(
217
+		return array_keys(array_filter(
218 218
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(),
219
-			static function ( $resultStatus ) {
219
+			static function($resultStatus) {
220 220
 				return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE;
221 221
 			}
222
-		) );
222
+		));
223 223
 	}
224 224
 
225 225
 	/**
@@ -230,33 +230,33 @@  discard block
 block discarded – undo
230 230
 	 *
231 231
 	 * @return ConstraintParameterException[]
232 232
 	 */
233
-	private function checkCommonConstraintParameters( Constraint $constraint ): array {
233
+	private function checkCommonConstraintParameters(Constraint $constraint): array {
234 234
 		$constraintParameters = $constraint->getConstraintParameters();
235 235
 		try {
236
-			$this->constraintParameterParser->checkError( $constraintParameters );
237
-		} catch ( ConstraintParameterException $e ) {
238
-			return [ $e ];
236
+			$this->constraintParameterParser->checkError($constraintParameters);
237
+		} catch (ConstraintParameterException $e) {
238
+			return [$e];
239 239
 		}
240 240
 
241 241
 		$problems = [];
242 242
 		try {
243
-			$this->constraintParameterParser->parseExceptionParameter( $constraintParameters );
244
-		} catch ( ConstraintParameterException $e ) {
243
+			$this->constraintParameterParser->parseExceptionParameter($constraintParameters);
244
+		} catch (ConstraintParameterException $e) {
245 245
 			$problems[] = $e;
246 246
 		}
247 247
 		try {
248
-			$this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters );
249
-		} catch ( ConstraintParameterException $e ) {
248
+			$this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters);
249
+		} catch (ConstraintParameterException $e) {
250 250
 			$problems[] = $e;
251 251
 		}
252 252
 		try {
253 253
 			$this->constraintParameterParser->parseConstraintScopeParameters(
254 254
 				$constraintParameters,
255 255
 				$constraint->getConstraintTypeItemId(),
256
-				$this->getValidContextTypes( $constraint ),
257
-				$this->getValidEntityTypes( $constraint )
256
+				$this->getValidContextTypes($constraint),
257
+				$this->getValidEntityTypes($constraint)
258 258
 			);
259
-		} catch ( ConstraintParameterException $e ) {
259
+		} catch (ConstraintParameterException $e) {
260 260
 			$problems[] = $e;
261 261
 		}
262 262
 		return $problems;
@@ -269,16 +269,16 @@  discard block
 block discarded – undo
269 269
 	 * @return ConstraintParameterException[][] first level indexed by constraint ID,
270 270
 	 * second level like checkConstraintParametersOnConstraintId (but without possibility of null)
271 271
 	 */
272
-	public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ): array {
273
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
272
+	public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId): array {
273
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
274 274
 		$result = [];
275 275
 
276
-		foreach ( $constraints as $constraint ) {
277
-			$problems = $this->checkCommonConstraintParameters( $constraint );
276
+		foreach ($constraints as $constraint) {
277
+			$problems = $this->checkCommonConstraintParameters($constraint);
278 278
 
279
-			if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
279
+			if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
280 280
 				$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
281
-				$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
281
+				$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
282 282
 			}
283 283
 
284 284
 			$result[$constraint->getConstraintId()] = $problems;
@@ -295,18 +295,18 @@  discard block
 block discarded – undo
295 295
 	 * @return ConstraintParameterException[]|null list of constraint parameter exceptions
296 296
 	 * (empty means all parameters okay), or null if constraint is not found
297 297
 	 */
298
-	public function checkConstraintParametersOnConstraintId( string $constraintId ): ?array {
299
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
298
+	public function checkConstraintParametersOnConstraintId(string $constraintId): ?array {
299
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
300 300
 		'@phan-var NumericPropertyId $propertyId';
301
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
301
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
302 302
 
303
-		foreach ( $constraints as $constraint ) {
304
-			if ( $constraint->getConstraintId() === $constraintId ) {
305
-				$problems = $this->checkCommonConstraintParameters( $constraint );
303
+		foreach ($constraints as $constraint) {
304
+			if ($constraint->getConstraintId() === $constraintId) {
305
+				$problems = $this->checkCommonConstraintParameters($constraint);
306 306
 
307
-				if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
307
+				if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
308 308
 					$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
309
-					$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
309
+					$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
310 310
 				}
311 311
 
312 312
 				return $problems;
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
 		$result = [];
332 332
 
333 333
 		/** @var Statement $statement */
334
-		foreach ( $entity->getStatements() as $statement ) {
335
-			$result = array_merge( $result,
334
+		foreach ($entity->getStatements() as $statement) {
335
+			$result = array_merge($result,
336 336
 				$this->checkStatement(
337 337
 					$entity,
338 338
 					$statement,
339 339
 					$constraintIds,
340 340
 					$defaultResultsPerContext
341
-				) );
341
+				));
342 342
 		}
343 343
 
344 344
 		return $result;
@@ -360,32 +360,32 @@  discard block
 block discarded – undo
360 360
 	): array {
361 361
 		$result = [];
362 362
 
363
-		$result = array_merge( $result,
363
+		$result = array_merge($result,
364 364
 			$this->checkConstraintsForMainSnak(
365 365
 				$entity,
366 366
 				$statement,
367 367
 				$constraintIds,
368 368
 				$defaultResultsPerContext
369
-			) );
369
+			));
370 370
 
371
-		if ( $this->checkQualifiers ) {
372
-			$result = array_merge( $result,
371
+		if ($this->checkQualifiers) {
372
+			$result = array_merge($result,
373 373
 				$this->checkConstraintsForQualifiers(
374 374
 					$entity,
375 375
 					$statement,
376 376
 					$constraintIds,
377 377
 					$defaultResultsPerContext
378
-				) );
378
+				));
379 379
 		}
380 380
 
381
-		if ( $this->checkReferences ) {
382
-			$result = array_merge( $result,
381
+		if ($this->checkReferences) {
382
+			$result = array_merge($result,
383 383
 				$this->checkConstraintsForReferences(
384 384
 					$entity,
385 385
 					$statement,
386 386
 					$constraintIds,
387 387
 					$defaultResultsPerContext
388
-				) );
388
+				));
389 389
 		}
390 390
 
391 391
 		return $result;
@@ -400,17 +400,17 @@  discard block
 block discarded – undo
400 400
 	 * @param string[]|null $constraintIds
401 401
 	 * @return Constraint[]
402 402
 	 */
403
-	private function getConstraintsToUse( PropertyId $propertyId, ?array $constraintIds ): array {
404
-		if ( !( $propertyId instanceof NumericPropertyId ) ) {
403
+	private function getConstraintsToUse(PropertyId $propertyId, ?array $constraintIds): array {
404
+		if (!($propertyId instanceof NumericPropertyId)) {
405 405
 			throw new InvalidArgumentException(
406
-				'Non-numeric property ID not supported:' . $propertyId->getSerialization()
406
+				'Non-numeric property ID not supported:'.$propertyId->getSerialization()
407 407
 			);
408 408
 		}
409
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
410
-		if ( $constraintIds !== null ) {
409
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
410
+		if ($constraintIds !== null) {
411 411
 			$constraintsToUse = [];
412
-			foreach ( $constraints as $constraint ) {
413
-				if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) {
412
+			foreach ($constraints as $constraint) {
413
+				if (in_array($constraint->getConstraintId(), $constraintIds)) {
414 414
 					$constraintsToUse[] = $constraint;
415 415
 				}
416 416
 			}
@@ -434,18 +434,18 @@  discard block
 block discarded – undo
434 434
 		?array $constraintIds,
435 435
 		?callable $defaultResults
436 436
 	): array {
437
-		$context = new MainSnakContext( $entity, $statement );
437
+		$context = new MainSnakContext($entity, $statement);
438 438
 		$constraints = $this->getConstraintsToUse(
439 439
 			$statement->getPropertyId(),
440 440
 			$constraintIds
441 441
 		);
442
-		$result = $defaultResults !== null ? $defaultResults( $context ) : [];
442
+		$result = $defaultResults !== null ? $defaultResults($context) : [];
443 443
 
444
-		foreach ( $constraints as $constraint ) {
444
+		foreach ($constraints as $constraint) {
445 445
 			$parameters = $constraint->getConstraintParameters();
446 446
 			try {
447
-				$exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters );
448
-			} catch ( ConstraintParameterException $e ) {
447
+				$exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters);
448
+			} catch (ConstraintParameterException $e) {
449 449
 				$result[] = new CheckResult(
450 450
 					$context,
451 451
 					$constraint,
@@ -455,13 +455,13 @@  discard block
 block discarded – undo
455 455
 				continue;
456 456
 			}
457 457
 
458
-			if ( in_array( $entity->getId(), $exceptions ) ) {
459
-				$message = new ViolationMessage( 'wbqc-violation-message-exception' );
460
-				$result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message );
458
+			if (in_array($entity->getId(), $exceptions)) {
459
+				$message = new ViolationMessage('wbqc-violation-message-exception');
460
+				$result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message);
461 461
 				continue;
462 462
 			}
463 463
 
464
-			$result[] = $this->getCheckResultFor( $context, $constraint );
464
+			$result[] = $this->getCheckResultFor($context, $constraint);
465 465
 		}
466 466
 
467 467
 		return $result;
@@ -483,24 +483,24 @@  discard block
 block discarded – undo
483 483
 	): array {
484 484
 		$result = [];
485 485
 
486
-		if ( in_array(
486
+		if (in_array(
487 487
 			$statement->getPropertyId()->getSerialization(),
488 488
 			$this->propertiesWithViolatingQualifiers
489
-		) ) {
489
+		)) {
490 490
 			return $result;
491 491
 		}
492 492
 
493
-		foreach ( $statement->getQualifiers() as $qualifier ) {
494
-			$qualifierContext = new QualifierContext( $entity, $statement, $qualifier );
495
-			if ( $defaultResultsPerContext !== null ) {
496
-				$result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) );
493
+		foreach ($statement->getQualifiers() as $qualifier) {
494
+			$qualifierContext = new QualifierContext($entity, $statement, $qualifier);
495
+			if ($defaultResultsPerContext !== null) {
496
+				$result = array_merge($result, $defaultResultsPerContext($qualifierContext));
497 497
 			}
498 498
 			$qualifierConstraints = $this->getConstraintsToUse(
499 499
 				$qualifierContext->getSnak()->getPropertyId(),
500 500
 				$constraintIds
501 501
 			);
502
-			foreach ( $qualifierConstraints as $qualifierConstraint ) {
503
-				$result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint );
502
+			foreach ($qualifierConstraints as $qualifierConstraint) {
503
+				$result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint);
504 504
 			}
505 505
 		}
506 506
 
@@ -524,19 +524,19 @@  discard block
 block discarded – undo
524 524
 		$result = [];
525 525
 
526 526
 		/** @var Reference $reference */
527
-		foreach ( $statement->getReferences() as $reference ) {
528
-			foreach ( $reference->getSnaks() as $snak ) {
527
+		foreach ($statement->getReferences() as $reference) {
528
+			foreach ($reference->getSnaks() as $snak) {
529 529
 				$referenceContext = new ReferenceContext(
530 530
 					$entity, $statement, $reference, $snak
531 531
 				);
532
-				if ( $defaultResultsPerContext !== null ) {
533
-					$result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) );
532
+				if ($defaultResultsPerContext !== null) {
533
+					$result = array_merge($result, $defaultResultsPerContext($referenceContext));
534 534
 				}
535 535
 				$referenceConstraints = $this->getConstraintsToUse(
536 536
 					$referenceContext->getSnak()->getPropertyId(),
537 537
 					$constraintIds
538 538
 				);
539
-				foreach ( $referenceConstraints as $referenceConstraint ) {
539
+				foreach ($referenceConstraints as $referenceConstraint) {
540 540
 					$result[] = $this->getCheckResultFor(
541 541
 						$referenceContext,
542 542
 						$referenceConstraint
@@ -548,20 +548,20 @@  discard block
 block discarded – undo
548 548
 		return $result;
549 549
 	}
550 550
 
551
-	private function getCheckResultFor( Context $context, Constraint $constraint ): CheckResult {
552
-		if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
551
+	private function getCheckResultFor(Context $context, Constraint $constraint): CheckResult {
552
+		if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
553 553
 			$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
554
-			$result = $this->handleScope( $checker, $context, $constraint );
554
+			$result = $this->handleScope($checker, $context, $constraint);
555 555
 
556
-			if ( $result !== null ) {
557
-				$this->addMetadata( $context, $result );
556
+			if ($result !== null) {
557
+				$this->addMetadata($context, $result);
558 558
 				return $result;
559 559
 			}
560 560
 
561
-			$startTime = microtime( true );
561
+			$startTime = microtime(true);
562 562
 			try {
563
-				$result = $checker->checkConstraint( $context, $constraint );
564
-			} catch ( ConstraintParameterException $e ) {
563
+				$result = $checker->checkConstraint($context, $constraint);
564
+			} catch (ConstraintParameterException $e) {
565 565
 				$result = new CheckResult(
566 566
 					$context,
567 567
 					$constraint,
@@ -569,28 +569,28 @@  discard block
 block discarded – undo
569 569
 					CheckResult::STATUS_BAD_PARAMETERS,
570 570
 					$e->getViolationMessage()
571 571
 				);
572
-			} catch ( SparqlHelperException $e ) {
573
-				$message = new ViolationMessage( 'wbqc-violation-message-sparql-error' );
574
-				$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message );
572
+			} catch (SparqlHelperException $e) {
573
+				$message = new ViolationMessage('wbqc-violation-message-sparql-error');
574
+				$result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message);
575 575
 			}
576
-			$endTime = microtime( true );
576
+			$endTime = microtime(true);
577 577
 
578
-			$this->addMetadata( $context, $result );
578
+			$this->addMetadata($context, $result);
579 579
 
580
-			$this->downgradeResultStatus( $result );
580
+			$this->downgradeResultStatus($result);
581 581
 
582 582
 			$this->loggingHelper->logConstraintCheck(
583 583
 				$context,
584 584
 				$constraint,
585 585
 				$result,
586
-				get_class( $checker ),
586
+				get_class($checker),
587 587
 				$endTime - $startTime,
588 588
 				__METHOD__
589 589
 			);
590 590
 
591 591
 			return $result;
592 592
 		} else {
593
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
593
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
594 594
 		}
595 595
 	}
596 596
 
@@ -599,85 +599,85 @@  discard block
 block discarded – undo
599 599
 		Context $context,
600 600
 		Constraint $constraint
601 601
 	): ?CheckResult {
602
-		$validContextTypes = $this->getValidContextTypes( $constraint );
603
-		$validEntityTypes = $this->getValidEntityTypes( $constraint );
602
+		$validContextTypes = $this->getValidContextTypes($constraint);
603
+		$validEntityTypes = $this->getValidEntityTypes($constraint);
604 604
 		try {
605
-			[ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters(
605
+			[$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters(
606 606
 				$constraint->getConstraintParameters(),
607 607
 				$constraint->getConstraintTypeItemId(),
608 608
 				$validContextTypes,
609 609
 				$validEntityTypes
610 610
 			);
611
-		} catch ( ConstraintParameterException $e ) {
612
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
611
+		} catch (ConstraintParameterException $e) {
612
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
613 613
 		}
614 614
 
615
-		if ( $checkedContextTypes === null ) {
615
+		if ($checkedContextTypes === null) {
616 616
 			$checkedContextTypes = $checker->getDefaultContextTypes();
617 617
 		}
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
-		if ( $checkedEntityTypes === null ) {
626
+		if ($checkedEntityTypes === null) {
627 627
 			$checkedEntityTypes = $validEntityTypes;
628 628
 		}
629 629
 		$entityType = $context->getEntity()->getType();
630
-		if ( !in_array( $entityType, $checkedEntityTypes ) ) {
631
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null );
630
+		if (!in_array($entityType, $checkedEntityTypes)) {
631
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null);
632 632
 		}
633
-		if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) {
634
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
633
+		if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) {
634
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
635 635
 		}
636 636
 
637 637
 		return null;
638 638
 	}
639 639
 
640
-	private function addMetadata( Context $context, CheckResult $result ): void {
641
-		$result->withMetadata( Metadata::merge( [
640
+	private function addMetadata(Context $context, CheckResult $result): void {
641
+		$result->withMetadata(Metadata::merge([
642 642
 			$result->getMetadata(),
643
-			Metadata::ofDependencyMetadata( DependencyMetadata::merge( [
644
-				DependencyMetadata::ofEntityId( $context->getEntity()->getId() ),
645
-				DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ),
646
-			] ) ),
647
-		] ) );
643
+			Metadata::ofDependencyMetadata(DependencyMetadata::merge([
644
+				DependencyMetadata::ofEntityId($context->getEntity()->getId()),
645
+				DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()),
646
+			])),
647
+		]));
648 648
 	}
649 649
 
650
-	private function downgradeResultStatus( CheckResult $result ): void {
650
+	private function downgradeResultStatus(CheckResult $result): void {
651 651
 		$constraint = $result->getConstraint();
652 652
 		try {
653 653
 			$constraintStatus = $this->constraintParameterParser
654
-				->parseConstraintStatusParameter( $constraint->getConstraintParameters() );
655
-		} catch ( ConstraintParameterException $e ) {
656
-			$result->setStatus( CheckResult::STATUS_BAD_PARAMETERS );
657
-			$result->setMessage( $e->getViolationMessage() );
654
+				->parseConstraintStatusParameter($constraint->getConstraintParameters());
655
+		} catch (ConstraintParameterException $e) {
656
+			$result->setStatus(CheckResult::STATUS_BAD_PARAMETERS);
657
+			$result->setMessage($e->getViolationMessage());
658 658
 			return;
659 659
 		}
660
-		if ( $constraintStatus === null ) {
660
+		if ($constraintStatus === null) {
661 661
 			// downgrade violation to warning
662
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
663
-				$result->setStatus( CheckResult::STATUS_WARNING );
662
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
663
+				$result->setStatus(CheckResult::STATUS_WARNING);
664 664
 			}
665
-		} elseif ( $constraintStatus === 'suggestion' ) {
665
+		} elseif ($constraintStatus === 'suggestion') {
666 666
 			// downgrade violation to suggestion
667
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
668
-				$result->setStatus( CheckResult::STATUS_SUGGESTION );
667
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
668
+				$result->setStatus(CheckResult::STATUS_SUGGESTION);
669 669
 			}
670
-			$result->addParameter( 'constraint_status', $constraintStatus );
670
+			$result->addParameter('constraint_status', $constraintStatus);
671 671
 		} else {
672
-			if ( $constraintStatus !== 'mandatory' ) {
672
+			if ($constraintStatus !== 'mandatory') {
673 673
 				// @codeCoverageIgnoreStart
674 674
 				throw new LogicException(
675
-					"Unknown constraint status '$constraintStatus', " .
675
+					"Unknown constraint status '$constraintStatus', ".
676 676
 					"only known statuses are 'mandatory' and 'suggestion'"
677 677
 				);
678 678
 				// @codeCoverageIgnoreEnd
679 679
 			}
680
-			$result->addParameter( 'constraint_status', $constraintStatus );
680
+			$result->addParameter('constraint_status', $constraintStatus);
681 681
 		}
682 682
 	}
683 683
 
@@ -686,12 +686,12 @@  discard block
 block discarded – undo
686 686
 	 *
687 687
 	 * @return CheckResult[]
688 688
 	 */
689
-	private function sortResult( array $result ): array {
690
-		if ( count( $result ) < 2 ) {
689
+	private function sortResult(array $result): array {
690
+		if (count($result) < 2) {
691 691
 			return $result;
692 692
 		}
693 693
 
694
-		$sortFunction = static function ( CheckResult $a, CheckResult $b ) {
694
+		$sortFunction = static function(CheckResult $a, CheckResult $b) {
695 695
 			$orderNum = 0;
696 696
 			$order = [
697 697
 				CheckResult::STATUS_BAD_PARAMETERS => $orderNum++,
@@ -708,55 +708,55 @@  discard block
 block discarded – undo
708 708
 			$statusA = $a->getStatus();
709 709
 			$statusB = $b->getStatus();
710 710
 
711
-			$orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ];
712
-			$orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ];
711
+			$orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other'];
712
+			$orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other'];
713 713
 
714
-			if ( $orderA === $orderB ) {
714
+			if ($orderA === $orderB) {
715 715
 				$cursorA = $a->getContextCursor();
716 716
 				$cursorB = $b->getContextCursor();
717 717
 
718
-				if ( $cursorA instanceof EntityContextCursor ) {
718
+				if ($cursorA instanceof EntityContextCursor) {
719 719
 					return $cursorB instanceof EntityContextCursor ? 0 : -1;
720 720
 				}
721
-				if ( $cursorB instanceof EntityContextCursor ) {
721
+				if ($cursorB instanceof EntityContextCursor) {
722 722
 					return $cursorA instanceof EntityContextCursor ? 0 : 1;
723 723
 				}
724 724
 
725 725
 				$pidA = $cursorA->getSnakPropertyId();
726 726
 				$pidB = $cursorB->getSnakPropertyId();
727 727
 
728
-				if ( $pidA === $pidB ) {
728
+				if ($pidA === $pidB) {
729 729
 					$hashA = $cursorA->getSnakHash();
730 730
 					$hashB = $cursorB->getSnakHash();
731 731
 
732
-					if ( $hashA === $hashB ) {
733
-						if ( $a instanceof NullResult ) {
732
+					if ($hashA === $hashB) {
733
+						if ($a instanceof NullResult) {
734 734
 							return $b instanceof NullResult ? 0 : -1;
735 735
 						}
736
-						if ( $b instanceof NullResult ) {
736
+						if ($b instanceof NullResult) {
737 737
 							return $a instanceof NullResult ? 0 : 1;
738 738
 						}
739 739
 
740 740
 						$typeA = $a->getConstraint()->getConstraintTypeItemId();
741 741
 						$typeB = $b->getConstraint()->getConstraintTypeItemId();
742 742
 
743
-						if ( $typeA == $typeB ) {
743
+						if ($typeA == $typeB) {
744 744
 							return 0;
745 745
 						} else {
746
-							return ( $typeA > $typeB ) ? 1 : -1;
746
+							return ($typeA > $typeB) ? 1 : -1;
747 747
 						}
748 748
 					} else {
749
-						return ( $hashA > $hashB ) ? 1 : -1;
749
+						return ($hashA > $hashB) ? 1 : -1;
750 750
 					}
751 751
 				} else {
752
-					return ( $pidA > $pidB ) ? 1 : -1;
752
+					return ($pidA > $pidB) ? 1 : -1;
753 753
 				}
754 754
 			} else {
755
-				return ( $orderA > $orderB ) ? 1 : -1;
755
+				return ($orderA > $orderB) ? 1 : -1;
756 756
 			}
757 757
 		};
758 758
 
759
-		uasort( $result, $sortFunction );
759
+		uasort($result, $sortFunction);
760 760
 
761 761
 		return $result;
762 762
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Result/CheckResult.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result;
6 6
 
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
 		string $status = self::STATUS_TODO,
115 115
 		ViolationMessage $message = null
116 116
 	) {
117
-		if ( $contextCursor instanceof Context ) {
117
+		if ($contextCursor instanceof Context) {
118 118
 			$context = $contextCursor;
119 119
 			$this->contextCursor = $context->getCursor();
120 120
 			$this->snakType = $context->getSnak()->getType();
121 121
 			$mainSnak = $context->getSnak();
122
-			if ( $mainSnak instanceof PropertyValueSnak ) {
122
+			if ($mainSnak instanceof PropertyValueSnak) {
123 123
 				$this->dataValue = $mainSnak->getDataValue();
124 124
 			} else {
125 125
 				$this->dataValue = null;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		return $this->parameters;
170 170
 	}
171 171
 
172
-	public function addParameter( string $key, string $value ): void {
172
+	public function addParameter(string $key, string $value): void {
173 173
 		$this->parameters[$key][] = $value;
174 174
 	}
175 175
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		return $this->status;
181 181
 	}
182 182
 
183
-	public function setStatus( string $status ): void {
183
+	public function setStatus(string $status): void {
184 184
 		$this->status = $status;
185 185
 	}
186 186
 
@@ -188,11 +188,11 @@  discard block
 block discarded – undo
188 188
 		return $this->message;
189 189
 	}
190 190
 
191
-	public function setMessage( ?ViolationMessage $message ) {
191
+	public function setMessage(?ViolationMessage $message) {
192 192
 		$this->message = $message;
193 193
 	}
194 194
 
195
-	public function withMetadata( Metadata $metadata ): self {
195
+	public function withMetadata(Metadata $metadata): self {
196 196
 		$this->metadata = $metadata;
197 197
 		return $this;
198 198
 	}
Please login to merge, or discard this patch.