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