Completed
Push — master ( 344392...132694 )
by
unknown
22s
created
src/ConstraintCheck/DelegatingConstraintChecker.php 1 patch
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 		callable $defaultResultsPerEntity = null
145 145
 	) {
146 146
 		$checkResults = [];
147
-		$entity = $this->entityLookup->getEntity( $entityId );
147
+		$entity = $this->entityLookup->getEntity($entityId);
148 148
 
149
-		if ( $entity instanceof StatementListProvidingEntity ) {
150
-			$startTime = microtime( true );
149
+		if ($entity instanceof StatementListProvidingEntity) {
150
+			$startTime = microtime(true);
151 151
 
152 152
 			$checkResults = $this->checkEveryStatement(
153 153
 				$entity,
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 				$defaultResultsPerContext
156 156
 			);
157 157
 
158
-			$endTime = microtime( true );
158
+			$endTime = microtime(true);
159 159
 
160
-			if ( $constraintIds === null ) { // only log full constraint checks
160
+			if ($constraintIds === null) { // only log full constraint checks
161 161
 				$this->loggingHelper->logConstraintCheckOnEntity(
162 162
 					$entityId,
163 163
 					$checkResults,
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 			}
168 168
 		}
169 169
 
170
-		if ( $defaultResultsPerEntity !== null ) {
171
-			$checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults );
170
+		if ($defaultResultsPerEntity !== null) {
171
+			$checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults);
172 172
 		}
173 173
 
174
-		return $this->sortResult( $checkResults );
174
+		return $this->sortResult($checkResults);
175 175
 	}
176 176
 
177 177
 	/**
@@ -193,19 +193,19 @@  discard block
 block discarded – undo
193 193
 		callable $defaultResults = null
194 194
 	) {
195 195
 
196
-		$parsedGuid = $this->statementGuidParser->parse( $guid );
196
+		$parsedGuid = $this->statementGuidParser->parse($guid);
197 197
 		$entityId = $parsedGuid->getEntityId();
198
-		$entity = $this->entityLookup->getEntity( $entityId );
199
-		if ( $entity instanceof StatementListProvidingEntity ) {
200
-			$statement = $entity->getStatements()->getFirstStatementWithGuid( $guid );
201
-			if ( $statement ) {
198
+		$entity = $this->entityLookup->getEntity($entityId);
199
+		if ($entity instanceof StatementListProvidingEntity) {
200
+			$statement = $entity->getStatements()->getFirstStatementWithGuid($guid);
201
+			if ($statement) {
202 202
 				$result = $this->checkStatement(
203 203
 					$entity,
204 204
 					$statement,
205 205
 					$constraintIds,
206 206
 					$defaultResults
207 207
 				);
208
-				$output = $this->sortResult( $result );
208
+				$output = $this->sortResult($result);
209 209
 				return $output;
210 210
 			}
211 211
 		}
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
 		return [];
214 214
 	}
215 215
 
216
-	private function getValidContextTypes( Constraint $constraint ) {
217
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
216
+	private function getValidContextTypes(Constraint $constraint) {
217
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
218 218
 			return [
219 219
 				Context::TYPE_STATEMENT,
220 220
 				Context::TYPE_QUALIFIER,
@@ -222,25 +222,25 @@  discard block
 block discarded – undo
222 222
 			];
223 223
 		}
224 224
 
225
-		return array_keys( array_filter(
225
+		return array_keys(array_filter(
226 226
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(),
227
-			static function ( $resultStatus ) {
227
+			static function($resultStatus) {
228 228
 				return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE;
229 229
 			}
230
-		) );
230
+		));
231 231
 	}
232 232
 
233
-	private function getValidEntityTypes( Constraint $constraint ) {
234
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
235
-			return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED );
233
+	private function getValidEntityTypes(Constraint $constraint) {
234
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
235
+			return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED);
236 236
 		}
237 237
 
238
-		return array_keys( array_filter(
238
+		return array_keys(array_filter(
239 239
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(),
240
-			static function ( $resultStatus ) {
240
+			static function($resultStatus) {
241 241
 				return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE;
242 242
 			}
243
-		) );
243
+		));
244 244
 	}
245 245
 
246 246
 	/**
@@ -251,33 +251,33 @@  discard block
 block discarded – undo
251 251
 	 *
252 252
 	 * @return ConstraintParameterException[]
253 253
 	 */
254
-	private function checkCommonConstraintParameters( Constraint $constraint ) {
254
+	private function checkCommonConstraintParameters(Constraint $constraint) {
255 255
 		$constraintParameters = $constraint->getConstraintParameters();
256 256
 		try {
257
-			$this->constraintParameterParser->checkError( $constraintParameters );
258
-		} catch ( ConstraintParameterException $e ) {
259
-			return [ $e ];
257
+			$this->constraintParameterParser->checkError($constraintParameters);
258
+		} catch (ConstraintParameterException $e) {
259
+			return [$e];
260 260
 		}
261 261
 
262 262
 		$problems = [];
263 263
 		try {
264
-			$this->constraintParameterParser->parseExceptionParameter( $constraintParameters );
265
-		} catch ( ConstraintParameterException $e ) {
264
+			$this->constraintParameterParser->parseExceptionParameter($constraintParameters);
265
+		} catch (ConstraintParameterException $e) {
266 266
 			$problems[] = $e;
267 267
 		}
268 268
 		try {
269
-			$this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters );
270
-		} catch ( ConstraintParameterException $e ) {
269
+			$this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters);
270
+		} catch (ConstraintParameterException $e) {
271 271
 			$problems[] = $e;
272 272
 		}
273 273
 		try {
274 274
 			$this->constraintParameterParser->parseConstraintScopeParameters(
275 275
 				$constraintParameters,
276 276
 				$constraint->getConstraintTypeItemId(),
277
-				$this->getValidContextTypes( $constraint ),
278
-				$this->getValidEntityTypes( $constraint )
277
+				$this->getValidContextTypes($constraint),
278
+				$this->getValidEntityTypes($constraint)
279 279
 			);
280
-		} catch ( ConstraintParameterException $e ) {
280
+		} catch (ConstraintParameterException $e) {
281 281
 			$problems[] = $e;
282 282
 		}
283 283
 		return $problems;
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
 	 * @return ConstraintParameterException[][] first level indexed by constraint ID,
291 291
 	 * second level like checkConstraintParametersOnConstraintId (but without possibility of null)
292 292
 	 */
293
-	public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ) {
294
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
293
+	public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId) {
294
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
295 295
 		$result = [];
296 296
 
297
-		foreach ( $constraints as $constraint ) {
298
-			$problems = $this->checkCommonConstraintParameters( $constraint );
297
+		foreach ($constraints as $constraint) {
298
+			$problems = $this->checkCommonConstraintParameters($constraint);
299 299
 
300
-			if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
300
+			if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
301 301
 				$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
302
-				$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
302
+				$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
303 303
 			}
304 304
 
305 305
 			$result[$constraint->getConstraintId()] = $problems;
@@ -316,18 +316,18 @@  discard block
 block discarded – undo
316 316
 	 * @return ConstraintParameterException[]|null list of constraint parameter exceptions
317 317
 	 * (empty means all parameters okay), or null if constraint is not found
318 318
 	 */
319
-	public function checkConstraintParametersOnConstraintId( $constraintId ) {
320
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
319
+	public function checkConstraintParametersOnConstraintId($constraintId) {
320
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
321 321
 		'@phan-var NumericPropertyId $propertyId';
322
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
322
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
323 323
 
324
-		foreach ( $constraints as $constraint ) {
325
-			if ( $constraint->getConstraintId() === $constraintId ) {
326
-				$problems = $this->checkCommonConstraintParameters( $constraint );
324
+		foreach ($constraints as $constraint) {
325
+			if ($constraint->getConstraintId() === $constraintId) {
326
+				$problems = $this->checkCommonConstraintParameters($constraint);
327 327
 
328
-				if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
328
+				if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
329 329
 					$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
330
-					$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
330
+					$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
331 331
 				}
332 332
 
333 333
 				return $problems;
@@ -352,14 +352,14 @@  discard block
 block discarded – undo
352 352
 		$result = [];
353 353
 
354 354
 		/** @var Statement $statement */
355
-		foreach ( $entity->getStatements() as $statement ) {
356
-			$result = array_merge( $result,
355
+		foreach ($entity->getStatements() as $statement) {
356
+			$result = array_merge($result,
357 357
 				$this->checkStatement(
358 358
 					$entity,
359 359
 					$statement,
360 360
 					$constraintIds,
361 361
 					$defaultResultsPerContext
362
-				) );
362
+				));
363 363
 		}
364 364
 
365 365
 		return $result;
@@ -381,32 +381,32 @@  discard block
 block discarded – undo
381 381
 	) {
382 382
 		$result = [];
383 383
 
384
-		$result = array_merge( $result,
384
+		$result = array_merge($result,
385 385
 			$this->checkConstraintsForMainSnak(
386 386
 				$entity,
387 387
 				$statement,
388 388
 				$constraintIds,
389 389
 				$defaultResultsPerContext
390
-			) );
390
+			));
391 391
 
392
-		if ( $this->checkQualifiers ) {
393
-			$result = array_merge( $result,
392
+		if ($this->checkQualifiers) {
393
+			$result = array_merge($result,
394 394
 				$this->checkConstraintsForQualifiers(
395 395
 					$entity,
396 396
 					$statement,
397 397
 					$constraintIds,
398 398
 					$defaultResultsPerContext
399
-				) );
399
+				));
400 400
 		}
401 401
 
402
-		if ( $this->checkReferences ) {
403
-			$result = array_merge( $result,
402
+		if ($this->checkReferences) {
403
+			$result = array_merge($result,
404 404
 				$this->checkConstraintsForReferences(
405 405
 					$entity,
406 406
 					$statement,
407 407
 					$constraintIds,
408 408
 					$defaultResultsPerContext
409
-				) );
409
+				));
410 410
 		}
411 411
 
412 412
 		return $result;
@@ -421,17 +421,17 @@  discard block
 block discarded – undo
421 421
 	 * @param string[]|null $constraintIds
422 422
 	 * @return Constraint[]
423 423
 	 */
424
-	private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) {
425
-		if ( !( $propertyId instanceof NumericPropertyId ) ) {
424
+	private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) {
425
+		if (!($propertyId instanceof NumericPropertyId)) {
426 426
 			throw new InvalidArgumentException(
427
-				'Non-numeric property ID not supported:' . $propertyId->getSerialization()
427
+				'Non-numeric property ID not supported:'.$propertyId->getSerialization()
428 428
 			);
429 429
 		}
430
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
431
-		if ( $constraintIds !== null ) {
430
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
431
+		if ($constraintIds !== null) {
432 432
 			$constraintsToUse = [];
433
-			foreach ( $constraints as $constraint ) {
434
-				if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) {
433
+			foreach ($constraints as $constraint) {
434
+				if (in_array($constraint->getConstraintId(), $constraintIds)) {
435 435
 					$constraintsToUse[] = $constraint;
436 436
 				}
437 437
 			}
@@ -455,18 +455,18 @@  discard block
 block discarded – undo
455 455
 		array $constraintIds = null,
456 456
 		callable $defaultResults = null
457 457
 	) {
458
-		$context = new MainSnakContext( $entity, $statement );
458
+		$context = new MainSnakContext($entity, $statement);
459 459
 		$constraints = $this->getConstraintsToUse(
460 460
 			$statement->getPropertyId(),
461 461
 			$constraintIds
462 462
 		);
463
-		$result = $defaultResults !== null ? $defaultResults( $context ) : [];
463
+		$result = $defaultResults !== null ? $defaultResults($context) : [];
464 464
 
465
-		foreach ( $constraints as $constraint ) {
465
+		foreach ($constraints as $constraint) {
466 466
 			$parameters = $constraint->getConstraintParameters();
467 467
 			try {
468
-				$exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters );
469
-			} catch ( ConstraintParameterException $e ) {
468
+				$exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters);
469
+			} catch (ConstraintParameterException $e) {
470 470
 				$result[] = new CheckResult(
471 471
 					$context,
472 472
 					$constraint,
@@ -476,13 +476,13 @@  discard block
 block discarded – undo
476 476
 				continue;
477 477
 			}
478 478
 
479
-			if ( in_array( $entity->getId(), $exceptions ) ) {
480
-				$message = new ViolationMessage( 'wbqc-violation-message-exception' );
481
-				$result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message );
479
+			if (in_array($entity->getId(), $exceptions)) {
480
+				$message = new ViolationMessage('wbqc-violation-message-exception');
481
+				$result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message);
482 482
 				continue;
483 483
 			}
484 484
 
485
-			$result[] = $this->getCheckResultFor( $context, $constraint );
485
+			$result[] = $this->getCheckResultFor($context, $constraint);
486 486
 		}
487 487
 
488 488
 		return $result;
@@ -504,24 +504,24 @@  discard block
 block discarded – undo
504 504
 	) {
505 505
 		$result = [];
506 506
 
507
-		if ( in_array(
507
+		if (in_array(
508 508
 			$statement->getPropertyId()->getSerialization(),
509 509
 			$this->propertiesWithViolatingQualifiers
510
-		) ) {
510
+		)) {
511 511
 			return $result;
512 512
 		}
513 513
 
514
-		foreach ( $statement->getQualifiers() as $qualifier ) {
515
-			$qualifierContext = new QualifierContext( $entity, $statement, $qualifier );
516
-			if ( $defaultResultsPerContext !== null ) {
517
-				$result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) );
514
+		foreach ($statement->getQualifiers() as $qualifier) {
515
+			$qualifierContext = new QualifierContext($entity, $statement, $qualifier);
516
+			if ($defaultResultsPerContext !== null) {
517
+				$result = array_merge($result, $defaultResultsPerContext($qualifierContext));
518 518
 			}
519 519
 			$qualifierConstraints = $this->getConstraintsToUse(
520 520
 				$qualifierContext->getSnak()->getPropertyId(),
521 521
 				$constraintIds
522 522
 			);
523
-			foreach ( $qualifierConstraints as $qualifierConstraint ) {
524
-				$result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint );
523
+			foreach ($qualifierConstraints as $qualifierConstraint) {
524
+				$result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint);
525 525
 			}
526 526
 		}
527 527
 
@@ -545,19 +545,19 @@  discard block
 block discarded – undo
545 545
 		$result = [];
546 546
 
547 547
 		/** @var Reference $reference */
548
-		foreach ( $statement->getReferences() as $reference ) {
549
-			foreach ( $reference->getSnaks() as $snak ) {
548
+		foreach ($statement->getReferences() as $reference) {
549
+			foreach ($reference->getSnaks() as $snak) {
550 550
 				$referenceContext = new ReferenceContext(
551 551
 					$entity, $statement, $reference, $snak
552 552
 				);
553
-				if ( $defaultResultsPerContext !== null ) {
554
-					$result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) );
553
+				if ($defaultResultsPerContext !== null) {
554
+					$result = array_merge($result, $defaultResultsPerContext($referenceContext));
555 555
 				}
556 556
 				$referenceConstraints = $this->getConstraintsToUse(
557 557
 					$referenceContext->getSnak()->getPropertyId(),
558 558
 					$constraintIds
559 559
 				);
560
-				foreach ( $referenceConstraints as $referenceConstraint ) {
560
+				foreach ($referenceConstraints as $referenceConstraint) {
561 561
 					$result[] = $this->getCheckResultFor(
562 562
 						$referenceContext,
563 563
 						$referenceConstraint
@@ -575,20 +575,20 @@  discard block
 block discarded – undo
575 575
 	 *
576 576
 	 * @return CheckResult
577 577
 	 */
578
-	private function getCheckResultFor( Context $context, Constraint $constraint ) {
579
-		if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
578
+	private function getCheckResultFor(Context $context, Constraint $constraint) {
579
+		if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
580 580
 			$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
581
-			$result = $this->handleScope( $checker, $context, $constraint );
581
+			$result = $this->handleScope($checker, $context, $constraint);
582 582
 
583
-			if ( $result !== null ) {
584
-				$this->addMetadata( $context, $result );
583
+			if ($result !== null) {
584
+				$this->addMetadata($context, $result);
585 585
 				return $result;
586 586
 			}
587 587
 
588
-			$startTime = microtime( true );
588
+			$startTime = microtime(true);
589 589
 			try {
590
-				$result = $checker->checkConstraint( $context, $constraint );
591
-			} catch ( ConstraintParameterException $e ) {
590
+				$result = $checker->checkConstraint($context, $constraint);
591
+			} catch (ConstraintParameterException $e) {
592 592
 				$result = new CheckResult(
593 593
 					$context,
594 594
 					$constraint,
@@ -596,28 +596,28 @@  discard block
 block discarded – undo
596 596
 					CheckResult::STATUS_BAD_PARAMETERS,
597 597
 					$e->getViolationMessage()
598 598
 				);
599
-			} catch ( SparqlHelperException $e ) {
600
-				$message = new ViolationMessage( 'wbqc-violation-message-sparql-error' );
601
-				$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message );
599
+			} catch (SparqlHelperException $e) {
600
+				$message = new ViolationMessage('wbqc-violation-message-sparql-error');
601
+				$result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message);
602 602
 			}
603
-			$endTime = microtime( true );
603
+			$endTime = microtime(true);
604 604
 
605
-			$this->addMetadata( $context, $result );
605
+			$this->addMetadata($context, $result);
606 606
 
607
-			$this->downgradeResultStatus( $context, $result );
607
+			$this->downgradeResultStatus($context, $result);
608 608
 
609 609
 			$this->loggingHelper->logConstraintCheck(
610 610
 				$context,
611 611
 				$constraint,
612 612
 				$result,
613
-				get_class( $checker ),
613
+				get_class($checker),
614 614
 				$endTime - $startTime,
615 615
 				__METHOD__
616 616
 			);
617 617
 
618 618
 			return $result;
619 619
 		} else {
620
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
620
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
621 621
 		}
622 622
 	}
623 623
 
@@ -626,84 +626,84 @@  discard block
 block discarded – undo
626 626
 		Context $context,
627 627
 		Constraint $constraint
628 628
 	): ?CheckResult {
629
-		$validContextTypes = $this->getValidContextTypes( $constraint );
630
-		$validEntityTypes = $this->getValidEntityTypes( $constraint );
629
+		$validContextTypes = $this->getValidContextTypes($constraint);
630
+		$validEntityTypes = $this->getValidEntityTypes($constraint);
631 631
 		try {
632
-			[ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters(
632
+			[$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters(
633 633
 				$constraint->getConstraintParameters(),
634 634
 				$constraint->getConstraintTypeItemId(),
635 635
 				$validContextTypes,
636 636
 				$validEntityTypes
637 637
 			);
638
-		} catch ( ConstraintParameterException $e ) {
639
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
638
+		} catch (ConstraintParameterException $e) {
639
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
640 640
 		}
641 641
 
642
-		if ( $checkedContextTypes === null ) {
642
+		if ($checkedContextTypes === null) {
643 643
 			$checkedContextTypes = $checker->getDefaultContextTypes();
644 644
 		}
645 645
 		$contextType = $context->getType();
646
-		if ( !in_array( $contextType, $checkedContextTypes ) ) {
647
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null );
646
+		if (!in_array($contextType, $checkedContextTypes)) {
647
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null);
648 648
 		}
649
-		if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) {
650
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
649
+		if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) {
650
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
651 651
 		}
652 652
 
653
-		if ( $checkedEntityTypes === null ) {
653
+		if ($checkedEntityTypes === null) {
654 654
 			$checkedEntityTypes = $validEntityTypes;
655 655
 		}
656 656
 		$entityType = $context->getEntity()->getType();
657
-		if ( !in_array( $entityType, $checkedEntityTypes ) ) {
658
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null );
657
+		if (!in_array($entityType, $checkedEntityTypes)) {
658
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null);
659 659
 		}
660
-		if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) {
661
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
660
+		if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) {
661
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
662 662
 		}
663 663
 
664 664
 		return null;
665 665
 	}
666 666
 
667
-	private function addMetadata( Context $context, CheckResult $result ) {
668
-		$result->withMetadata( Metadata::merge( [
667
+	private function addMetadata(Context $context, CheckResult $result) {
668
+		$result->withMetadata(Metadata::merge([
669 669
 			$result->getMetadata(),
670
-			Metadata::ofDependencyMetadata( DependencyMetadata::merge( [
671
-				DependencyMetadata::ofEntityId( $context->getEntity()->getId() ),
672
-				DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ),
673
-			] ) ),
674
-		] ) );
670
+			Metadata::ofDependencyMetadata(DependencyMetadata::merge([
671
+				DependencyMetadata::ofEntityId($context->getEntity()->getId()),
672
+				DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()),
673
+			])),
674
+		]));
675 675
 	}
676 676
 
677
-	private function downgradeResultStatus( Context $context, CheckResult &$result ) {
677
+	private function downgradeResultStatus(Context $context, CheckResult & $result) {
678 678
 		$constraint = $result->getConstraint();
679 679
 		try {
680 680
 			$constraintStatus = $this->constraintParameterParser
681
-				->parseConstraintStatusParameter( $constraint->getConstraintParameters() );
682
-		} catch ( ConstraintParameterException $e ) {
683
-			$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
681
+				->parseConstraintStatusParameter($constraint->getConstraintParameters());
682
+		} catch (ConstraintParameterException $e) {
683
+			$result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
684 684
 			$constraintStatus = null;
685 685
 		}
686
-		if ( $constraintStatus === null ) {
686
+		if ($constraintStatus === null) {
687 687
 			// downgrade violation to warning
688
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
689
-				$result->setStatus( CheckResult::STATUS_WARNING );
688
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
689
+				$result->setStatus(CheckResult::STATUS_WARNING);
690 690
 			}
691
-		} elseif ( $constraintStatus === 'suggestion' ) {
691
+		} elseif ($constraintStatus === 'suggestion') {
692 692
 			// downgrade violation to suggestion
693
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
694
-				$result->setStatus( CheckResult::STATUS_SUGGESTION );
693
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
694
+				$result->setStatus(CheckResult::STATUS_SUGGESTION);
695 695
 			}
696
-			$result->addParameter( 'constraint_status', $constraintStatus );
696
+			$result->addParameter('constraint_status', $constraintStatus);
697 697
 		} else {
698
-			if ( $constraintStatus !== 'mandatory' ) {
698
+			if ($constraintStatus !== 'mandatory') {
699 699
 				// @codeCoverageIgnoreStart
700 700
 				throw new LogicException(
701
-					"Unknown constraint status '$constraintStatus', " .
701
+					"Unknown constraint status '$constraintStatus', ".
702 702
 					"only known statuses are 'mandatory' and 'suggestion'"
703 703
 				);
704 704
 				// @codeCoverageIgnoreEnd
705 705
 			}
706
-			$result->addParameter( 'constraint_status', $constraintStatus );
706
+			$result->addParameter('constraint_status', $constraintStatus);
707 707
 		}
708 708
 	}
709 709
 
@@ -712,12 +712,12 @@  discard block
 block discarded – undo
712 712
 	 *
713 713
 	 * @return CheckResult[]
714 714
 	 */
715
-	private function sortResult( array $result ) {
716
-		if ( count( $result ) < 2 ) {
715
+	private function sortResult(array $result) {
716
+		if (count($result) < 2) {
717 717
 			return $result;
718 718
 		}
719 719
 
720
-		$sortFunction = static function ( CheckResult $a, CheckResult $b ) {
720
+		$sortFunction = static function(CheckResult $a, CheckResult $b) {
721 721
 			$orderNum = 0;
722 722
 			$order = [
723 723
 				CheckResult::STATUS_BAD_PARAMETERS => $orderNum++,
@@ -734,55 +734,55 @@  discard block
 block discarded – undo
734 734
 			$statusA = $a->getStatus();
735 735
 			$statusB = $b->getStatus();
736 736
 
737
-			$orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ];
738
-			$orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ];
737
+			$orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other'];
738
+			$orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other'];
739 739
 
740
-			if ( $orderA === $orderB ) {
740
+			if ($orderA === $orderB) {
741 741
 				$cursorA = $a->getContextCursor();
742 742
 				$cursorB = $b->getContextCursor();
743 743
 
744
-				if ( $cursorA instanceof EntityContextCursor ) {
744
+				if ($cursorA instanceof EntityContextCursor) {
745 745
 					return $cursorB instanceof EntityContextCursor ? 0 : -1;
746 746
 				}
747
-				if ( $cursorB instanceof EntityContextCursor ) {
747
+				if ($cursorB instanceof EntityContextCursor) {
748 748
 					return $cursorA instanceof EntityContextCursor ? 0 : 1;
749 749
 				}
750 750
 
751 751
 				$pidA = $cursorA->getSnakPropertyId();
752 752
 				$pidB = $cursorB->getSnakPropertyId();
753 753
 
754
-				if ( $pidA === $pidB ) {
754
+				if ($pidA === $pidB) {
755 755
 					$hashA = $cursorA->getSnakHash();
756 756
 					$hashB = $cursorB->getSnakHash();
757 757
 
758
-					if ( $hashA === $hashB ) {
759
-						if ( $a instanceof NullResult ) {
758
+					if ($hashA === $hashB) {
759
+						if ($a instanceof NullResult) {
760 760
 							return $b instanceof NullResult ? 0 : -1;
761 761
 						}
762
-						if ( $b instanceof NullResult ) {
762
+						if ($b instanceof NullResult) {
763 763
 							return $a instanceof NullResult ? 0 : 1;
764 764
 						}
765 765
 
766 766
 						$typeA = $a->getConstraint()->getConstraintTypeItemId();
767 767
 						$typeB = $b->getConstraint()->getConstraintTypeItemId();
768 768
 
769
-						if ( $typeA == $typeB ) {
769
+						if ($typeA == $typeB) {
770 770
 							return 0;
771 771
 						} else {
772
-							return ( $typeA > $typeB ) ? 1 : -1;
772
+							return ($typeA > $typeB) ? 1 : -1;
773 773
 						}
774 774
 					} else {
775
-						return ( $hashA > $hashB ) ? 1 : -1;
775
+						return ($hashA > $hashB) ? 1 : -1;
776 776
 					}
777 777
 				} else {
778
-					return ( $pidA > $pidB ) ? 1 : -1;
778
+					return ($pidA > $pidB) ? 1 : -1;
779 779
 				}
780 780
 			} else {
781
-				return ( $orderA > $orderB ) ? 1 : -1;
781
+				return ($orderA > $orderB) ? 1 : -1;
782 782
 			}
783 783
 		};
784 784
 
785
-		uasort( $result, $sortFunction );
785
+		uasort($result, $sortFunction);
786 786
 
787 787
 		return $result;
788 788
 	}
Please login to merge, or discard this patch.