Completed
Push — master ( adf32b...5e3780 )
by
unknown
02:41
created
src/ConstraintCheck/DelegatingConstraintChecker.php 1 patch
Spacing   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 		callable $defaultResults = null
138 138
 	) {
139 139
 
140
-		$entity = $this->entityLookup->getEntity( $entityId );
141
-		if ( $entity instanceof StatementListProvider ) {
140
+		$entity = $this->entityLookup->getEntity($entityId);
141
+		if ($entity instanceof StatementListProvider) {
142 142
 			$result = $this->checkEveryStatement(
143
-				$this->entityLookup->getEntity( $entityId ),
143
+				$this->entityLookup->getEntity($entityId),
144 144
 				$constraintIds,
145 145
 				$defaultResults
146 146
 			);
147
-			$output = $this->sortResult( $result );
147
+			$output = $this->sortResult($result);
148 148
 			return $output;
149 149
 		}
150 150
 
@@ -170,19 +170,19 @@  discard block
 block discarded – undo
170 170
 		callable $defaultResults = null
171 171
 	) {
172 172
 
173
-		$parsedGuid = $this->statementGuidParser->parse( $guid );
173
+		$parsedGuid = $this->statementGuidParser->parse($guid);
174 174
 		$entityId = $parsedGuid->getEntityId();
175
-		$entity = $this->entityLookup->getEntity( $entityId );
176
-		if ( $entity instanceof StatementListProvider ) {
177
-			$statement = $entity->getStatements()->getFirstStatementWithGuid( $guid );
178
-			if ( $statement ) {
175
+		$entity = $this->entityLookup->getEntity($entityId);
176
+		if ($entity instanceof StatementListProvider) {
177
+			$statement = $entity->getStatements()->getFirstStatementWithGuid($guid);
178
+			if ($statement) {
179 179
 				$result = $this->checkStatement(
180 180
 					$entity,
181 181
 					$statement,
182 182
 					$constraintIds,
183 183
 					$defaultResults
184 184
 				);
185
-				$output = $this->sortResult( $result );
185
+				$output = $this->sortResult($result);
186 186
 				return $output;
187 187
 			}
188 188
 		}
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 		return [];
191 191
 	}
192 192
 
193
-	private function getAllowedContextTypes( Constraint $constraint ) {
194
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
193
+	private function getAllowedContextTypes(Constraint $constraint) {
194
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
195 195
 			return [
196 196
 				Context::TYPE_STATEMENT,
197 197
 				Context::TYPE_QUALIFIER,
@@ -199,12 +199,12 @@  discard block
 block discarded – undo
199 199
 			];
200 200
 		}
201 201
 
202
-		return array_keys( array_filter(
202
+		return array_keys(array_filter(
203 203
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(),
204
-			function ( $resultStatus ) {
204
+			function($resultStatus) {
205 205
 				return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE;
206 206
 			}
207
-		) );
207
+		));
208 208
 	}
209 209
 
210 210
 	/**
@@ -215,32 +215,32 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return ConstraintParameterException[]
217 217
 	 */
218
-	private function checkCommonConstraintParameters( Constraint $constraint ) {
218
+	private function checkCommonConstraintParameters(Constraint $constraint) {
219 219
 		$constraintParameters = $constraint->getConstraintParameters();
220 220
 		try {
221
-			$this->constraintParameterParser->checkError( $constraintParameters );
222
-		} catch ( ConstraintParameterException $e ) {
223
-			return [ $e ];
221
+			$this->constraintParameterParser->checkError($constraintParameters);
222
+		} catch (ConstraintParameterException $e) {
223
+			return [$e];
224 224
 		}
225 225
 
226 226
 		$problems = [];
227 227
 		try {
228
-			$this->constraintParameterParser->parseExceptionParameter( $constraintParameters );
229
-		} catch ( ConstraintParameterException $e ) {
228
+			$this->constraintParameterParser->parseExceptionParameter($constraintParameters);
229
+		} catch (ConstraintParameterException $e) {
230 230
 			$problems[] = $e;
231 231
 		}
232 232
 		try {
233
-			$this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters );
234
-		} catch ( ConstraintParameterException $e ) {
233
+			$this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters);
234
+		} catch (ConstraintParameterException $e) {
235 235
 			$problems[] = $e;
236 236
 		}
237 237
 		try {
238 238
 			$this->constraintParameterParser->parseConstraintScopeParameter(
239 239
 				$constraintParameters,
240 240
 				$constraint->getConstraintTypeItemId(),
241
-				$this->getAllowedContextTypes( $constraint )
241
+				$this->getAllowedContextTypes($constraint)
242 242
 			);
243
-		} catch ( ConstraintParameterException $e ) {
243
+		} catch (ConstraintParameterException $e) {
244 244
 			$problems[] = $e;
245 245
 		}
246 246
 		return $problems;
@@ -253,16 +253,16 @@  discard block
 block discarded – undo
253 253
 	 * @return ConstraintParameterException[][] first level indexed by constraint ID,
254 254
 	 * second level like checkConstraintParametersOnConstraintId (but without possibility of null)
255 255
 	 */
256
-	public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) {
257
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
256
+	public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) {
257
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
258 258
 		$result = [];
259 259
 
260
-		foreach ( $constraints as $constraint ) {
261
-			$problems = $this->checkCommonConstraintParameters( $constraint );
260
+		foreach ($constraints as $constraint) {
261
+			$problems = $this->checkCommonConstraintParameters($constraint);
262 262
 
263
-			if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
263
+			if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
264 264
 				$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
265
-				$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
265
+				$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
266 266
 			}
267 267
 
268 268
 			$result[$constraint->getConstraintId()] = $problems;
@@ -279,17 +279,17 @@  discard block
 block discarded – undo
279 279
 	 * @return ConstraintParameterException[]|null list of constraint parameter exceptions
280 280
 	 * (empty means all parameters okay), or null if constraint is not found
281 281
 	 */
282
-	public function checkConstraintParametersOnConstraintId( $constraintId ) {
283
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
284
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
282
+	public function checkConstraintParametersOnConstraintId($constraintId) {
283
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
284
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
285 285
 
286
-		foreach ( $constraints as $constraint ) {
287
-			if ( $constraint->getConstraintId() === $constraintId ) {
288
-				$problems = $this->checkCommonConstraintParameters( $constraint );
286
+		foreach ($constraints as $constraint) {
287
+			if ($constraint->getConstraintId() === $constraintId) {
288
+				$problems = $this->checkCommonConstraintParameters($constraint);
289 289
 
290
-				if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
290
+				if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
291 291
 					$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
292
-					$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
292
+					$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
293 293
 				}
294 294
 
295 295
 				return $problems;
@@ -314,14 +314,14 @@  discard block
 block discarded – undo
314 314
 		$result = [];
315 315
 
316 316
 		/** @var Statement $statement */
317
-		foreach ( $entity->getStatements() as $statement ) {
318
-			$result = array_merge( $result,
317
+		foreach ($entity->getStatements() as $statement) {
318
+			$result = array_merge($result,
319 319
 				$this->checkStatement(
320 320
 					$entity,
321 321
 					$statement,
322 322
 					$constraintIds,
323 323
 					$defaultResults
324
-				) );
324
+				));
325 325
 		}
326 326
 
327 327
 		return $result;
@@ -343,32 +343,32 @@  discard block
 block discarded – undo
343 343
 	) {
344 344
 		$result = [];
345 345
 
346
-		$result = array_merge( $result,
346
+		$result = array_merge($result,
347 347
 			$this->checkConstraintsForMainSnak(
348 348
 				$entity,
349 349
 				$statement,
350 350
 				$constraintIds,
351 351
 				$defaultResults
352
-			) );
352
+			));
353 353
 
354
-		if ( $this->checkQualifiers ) {
355
-			$result = array_merge( $result,
354
+		if ($this->checkQualifiers) {
355
+			$result = array_merge($result,
356 356
 				$this->checkConstraintsForQualifiers(
357 357
 					$entity,
358 358
 					$statement,
359 359
 					$constraintIds,
360 360
 					$defaultResults
361
-				) );
361
+				));
362 362
 		}
363 363
 
364
-		if ( $this->checkReferences ) {
365
-			$result = array_merge( $result,
364
+		if ($this->checkReferences) {
365
+			$result = array_merge($result,
366 366
 				$this->checkConstraintsForReferences(
367 367
 					$entity,
368 368
 					$statement,
369 369
 					$constraintIds,
370 370
 					$defaultResults
371
-				) );
371
+				));
372 372
 		}
373 373
 
374 374
 		return $result;
@@ -383,12 +383,12 @@  discard block
 block discarded – undo
383 383
 	 * @param string[]|null $constraintIds
384 384
 	 * @return Constraint[]
385 385
 	 */
386
-	private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) {
387
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
388
-		if ( $constraintIds !== null ) {
386
+	private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) {
387
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
388
+		if ($constraintIds !== null) {
389 389
 			$constraintsToUse = [];
390
-			foreach ( $constraints as $constraint ) {
391
-				if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) {
390
+			foreach ($constraints as $constraint) {
391
+				if (in_array($constraint->getConstraintId(), $constraintIds)) {
392 392
 					$constraintsToUse[] = $constraint;
393 393
 				}
394 394
 			}
@@ -412,29 +412,29 @@  discard block
 block discarded – undo
412 412
 		array $constraintIds = null,
413 413
 		callable $defaultResults = null
414 414
 	) {
415
-		$context = new MainSnakContext( $entity, $statement );
415
+		$context = new MainSnakContext($entity, $statement);
416 416
 		$constraints = $this->getConstraintsToUse(
417 417
 			$statement->getPropertyId(),
418 418
 			$constraintIds
419 419
 		);
420
-		$result = $defaultResults !== null ? $defaultResults( $context ) : [];
420
+		$result = $defaultResults !== null ? $defaultResults($context) : [];
421 421
 
422
-		foreach ( $constraints as $constraint ) {
422
+		foreach ($constraints as $constraint) {
423 423
 			$parameters = $constraint->getConstraintParameters();
424 424
 			try {
425
-				$exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters );
426
-			} catch ( ConstraintParameterException $e ) {
427
-				$result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
425
+				$exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters);
426
+			} catch (ConstraintParameterException $e) {
427
+				$result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
428 428
 				continue;
429 429
 			}
430 430
 
431
-			if ( in_array( $entity->getId(), $exceptions ) ) {
432
-				$message = wfMessage( 'wbqc-exception-message' )->escaped();
433
-				$result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message );
431
+			if (in_array($entity->getId(), $exceptions)) {
432
+				$message = wfMessage('wbqc-exception-message')->escaped();
433
+				$result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message);
434 434
 				continue;
435 435
 			}
436 436
 
437
-			$result[] = $this->getCheckResultFor( $context, $constraint );
437
+			$result[] = $this->getCheckResultFor($context, $constraint);
438 438
 		}
439 439
 
440 440
 		return $result;
@@ -456,24 +456,24 @@  discard block
 block discarded – undo
456 456
 	) {
457 457
 		$result = [];
458 458
 
459
-		if ( in_array(
459
+		if (in_array(
460 460
 			$statement->getPropertyId()->getSerialization(),
461 461
 			$this->propertiesWithViolatingQualifiers
462
-		) ) {
462
+		)) {
463 463
 			return $result;
464 464
 		}
465 465
 
466
-		foreach ( $statement->getQualifiers() as $qualifier ) {
467
-			$qualifierContext = new QualifierContext( $entity, $statement, $qualifier );
468
-			if ( $defaultResults !== null ) {
469
-				$result = array_merge( $result, $defaultResults( $qualifierContext ) );
466
+		foreach ($statement->getQualifiers() as $qualifier) {
467
+			$qualifierContext = new QualifierContext($entity, $statement, $qualifier);
468
+			if ($defaultResults !== null) {
469
+				$result = array_merge($result, $defaultResults($qualifierContext));
470 470
 			}
471 471
 			$qualifierConstraints = $this->getConstraintsToUse(
472 472
 				$qualifierContext->getSnak()->getPropertyId(),
473 473
 				$constraintIds
474 474
 			);
475
-			foreach ( $qualifierConstraints as $qualifierConstraint ) {
476
-				$result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint );
475
+			foreach ($qualifierConstraints as $qualifierConstraint) {
476
+				$result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint);
477 477
 			}
478 478
 		}
479 479
 
@@ -497,19 +497,19 @@  discard block
 block discarded – undo
497 497
 		$result = [];
498 498
 
499 499
 		/** @var Reference $reference */
500
-		foreach ( $statement->getReferences() as $reference ) {
501
-			foreach ( $reference->getSnaks() as $snak ) {
500
+		foreach ($statement->getReferences() as $reference) {
501
+			foreach ($reference->getSnaks() as $snak) {
502 502
 				$referenceContext = new ReferenceContext(
503 503
 					$entity, $statement, $reference, $snak
504 504
 				);
505
-				if ( $defaultResults !== null ) {
506
-					$result = array_merge( $result, $defaultResults( $referenceContext ) );
505
+				if ($defaultResults !== null) {
506
+					$result = array_merge($result, $defaultResults($referenceContext));
507 507
 				}
508 508
 				$referenceConstraints = $this->getConstraintsToUse(
509 509
 					$referenceContext->getSnak()->getPropertyId(),
510 510
 					$constraintIds
511 511
 				);
512
-				foreach ( $referenceConstraints as $referenceConstraint ) {
512
+				foreach ($referenceConstraints as $referenceConstraint) {
513 513
 					$result[] = $this->getCheckResultFor(
514 514
 						$referenceContext,
515 515
 						$referenceConstraint
@@ -528,65 +528,65 @@  discard block
 block discarded – undo
528 528
 	 * @throws InvalidArgumentException
529 529
 	 * @return CheckResult
530 530
 	 */
531
-	private function getCheckResultFor( Context $context, Constraint $constraint ) {
532
-		if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
531
+	private function getCheckResultFor(Context $context, Constraint $constraint) {
532
+		if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
533 533
 			$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
534
-			$result = $this->handleScope( $checker, $context, $constraint );
534
+			$result = $this->handleScope($checker, $context, $constraint);
535 535
 
536
-			if ( $result !== null ) {
537
-				$this->addMetadata( $context, $result );
536
+			if ($result !== null) {
537
+				$this->addMetadata($context, $result);
538 538
 				return $result;
539 539
 			}
540 540
 
541
-			$startTime = microtime( true );
541
+			$startTime = microtime(true);
542 542
 			try {
543
-				$result = $checker->checkConstraint( $context, $constraint );
544
-			} catch ( ConstraintParameterException $e ) {
545
-				$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
546
-			} catch ( SparqlHelperException $e ) {
547
-				$message = new ViolationMessage( 'wbqc-violation-message-sparql-error' );
548
-				$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
543
+				$result = $checker->checkConstraint($context, $constraint);
544
+			} catch (ConstraintParameterException $e) {
545
+				$result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
546
+			} catch (SparqlHelperException $e) {
547
+				$message = new ViolationMessage('wbqc-violation-message-sparql-error');
548
+				$result = new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message);
549 549
 			}
550
-			$endTime = microtime( true );
550
+			$endTime = microtime(true);
551 551
 
552
-			$this->addMetadata( $context, $result );
552
+			$this->addMetadata($context, $result);
553 553
 
554 554
 			try {
555 555
 				$constraintStatus = $this->constraintParameterParser
556
-					->parseConstraintStatusParameter( $constraint->getConstraintParameters() );
557
-			} catch ( ConstraintParameterException $e ) {
558
-				$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
556
+					->parseConstraintStatusParameter($constraint->getConstraintParameters());
557
+			} catch (ConstraintParameterException $e) {
558
+				$result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
559 559
 				$constraintStatus = null;
560 560
 			}
561
-			if ( $constraintStatus === null ) {
561
+			if ($constraintStatus === null) {
562 562
 				// downgrade violation to warning
563
-				if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
564
-					$result->setStatus( CheckResult::STATUS_WARNING );
563
+				if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
564
+					$result->setStatus(CheckResult::STATUS_WARNING);
565 565
 				}
566 566
 			} else {
567
-				if ( $constraintStatus !== 'mandatory' ) {
567
+				if ($constraintStatus !== 'mandatory') {
568 568
 					// @codeCoverageIgnoreStart
569 569
 					throw new LogicException(
570
-						"Unknown constraint status '$constraintStatus', " .
570
+						"Unknown constraint status '$constraintStatus', ".
571 571
 						"only known status is 'mandatory'"
572 572
 					);
573 573
 					// @codeCoverageIgnoreEnd
574 574
 				}
575
-				$result->addParameter( 'constraint_status', $constraintStatus );
575
+				$result->addParameter('constraint_status', $constraintStatus);
576 576
 			}
577 577
 
578 578
 			$this->loggingHelper->logConstraintCheck(
579 579
 				$context,
580 580
 				$constraint,
581 581
 				$result,
582
-				get_class( $checker ),
582
+				get_class($checker),
583 583
 				$endTime - $startTime,
584 584
 				__METHOD__
585 585
 			);
586 586
 
587 587
 			return $result;
588 588
 		} else {
589
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
589
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
590 590
 		}
591 591
 	}
592 592
 
@@ -600,29 +600,29 @@  discard block
 block discarded – undo
600 600
 				$constraint->getConstraintParameters(),
601 601
 				$constraint->getConstraintTypeItemId()
602 602
 			);
603
-		} catch ( ConstraintParameterException $e ) {
604
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
603
+		} catch (ConstraintParameterException $e) {
604
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
605 605
 		}
606
-		if ( $checkedContextTypes === null ) {
606
+		if ($checkedContextTypes === null) {
607 607
 			$checkedContextTypes = $checker->getDefaultContextTypes();
608 608
 		}
609
-		if ( !in_array( $context->getType(), $checkedContextTypes ) ) {
610
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null );
609
+		if (!in_array($context->getType(), $checkedContextTypes)) {
610
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null);
611 611
 		}
612
-		if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) {
613
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
612
+		if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) {
613
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
614 614
 		}
615 615
 		return null;
616 616
 	}
617 617
 
618
-	private function addMetadata( Context $context, CheckResult $result ) {
619
-		$result->withMetadata( Metadata::merge( [
618
+	private function addMetadata(Context $context, CheckResult $result) {
619
+		$result->withMetadata(Metadata::merge([
620 620
 			$result->getMetadata(),
621
-			Metadata::ofDependencyMetadata( DependencyMetadata::merge( [
622
-				DependencyMetadata::ofEntityId( $context->getEntity()->getId() ),
623
-				DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ),
624
-			] ) ),
625
-		] ) );
621
+			Metadata::ofDependencyMetadata(DependencyMetadata::merge([
622
+				DependencyMetadata::ofEntityId($context->getEntity()->getId()),
623
+				DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()),
624
+			])),
625
+		]));
626 626
 	}
627 627
 
628 628
 	/**
@@ -630,12 +630,12 @@  discard block
 block discarded – undo
630 630
 	 *
631 631
 	 * @return CheckResult[]
632 632
 	 */
633
-	private function sortResult( array $result ) {
634
-		if ( count( $result ) < 2 ) {
633
+	private function sortResult(array $result) {
634
+		if (count($result) < 2) {
635 635
 			return $result;
636 636
 		}
637 637
 
638
-		$sortFunction = function ( CheckResult $a, CheckResult $b ) {
638
+		$sortFunction = function(CheckResult $a, CheckResult $b) {
639 639
 			$orderNum = 0;
640 640
 			$order = [
641 641
 				CheckResult::STATUS_BAD_PARAMETERS => $orderNum++,
@@ -651,45 +651,45 @@  discard block
 block discarded – undo
651 651
 			$statusA = $a->getStatus();
652 652
 			$statusB = $b->getStatus();
653 653
 
654
-			$orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ];
655
-			$orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ];
654
+			$orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other'];
655
+			$orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other'];
656 656
 
657
-			if ( $orderA === $orderB ) {
657
+			if ($orderA === $orderB) {
658 658
 				$pidA = $a->getContextCursor()->getSnakPropertyId();
659 659
 				$pidB = $b->getContextCursor()->getSnakPropertyId();
660 660
 
661
-				if ( $pidA === $pidB ) {
661
+				if ($pidA === $pidB) {
662 662
 					$hashA = $a->getContextCursor()->getSnakHash();
663 663
 					$hashB = $b->getContextCursor()->getSnakHash();
664 664
 
665
-					if ( $hashA === $hashB ) {
666
-						if ( $a instanceof NullResult ) {
665
+					if ($hashA === $hashB) {
666
+						if ($a instanceof NullResult) {
667 667
 							return $b instanceof NullResult ? 0 : -1;
668 668
 						}
669
-						if ( $b instanceof NullResult ) {
669
+						if ($b instanceof NullResult) {
670 670
 							return $a instanceof NullResult ? 0 : 1;
671 671
 						}
672 672
 
673 673
 						$typeA = $a->getConstraint()->getConstraintTypeItemId();
674 674
 						$typeB = $b->getConstraint()->getConstraintTypeItemId();
675 675
 
676
-						if ( $typeA == $typeB ) {
676
+						if ($typeA == $typeB) {
677 677
 							return 0;
678 678
 						} else {
679
-							return ( $typeA > $typeB ) ? 1 : -1;
679
+							return ($typeA > $typeB) ? 1 : -1;
680 680
 						}
681 681
 					} else {
682
-						return ( $hashA > $hashB ) ? 1 : -1;
682
+						return ($hashA > $hashB) ? 1 : -1;
683 683
 					}
684 684
 				} else {
685
-					return ( $pidA > $pidB ) ? 1 : -1;
685
+					return ($pidA > $pidB) ? 1 : -1;
686 686
 				}
687 687
 			} else {
688
-				return ( $orderA > $orderB ) ? 1 : -1;
688
+				return ($orderA > $orderB) ? 1 : -1;
689 689
 			}
690 690
 		};
691 691
 
692
-		uasort( $result, $sortFunction );
692
+		uasort($result, $sortFunction);
693 693
 
694 694
 		return $result;
695 695
 	}
Please login to merge, or discard this patch.
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +111 added lines, -112 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		Config $config,
135 135
 		IBufferingStatsdDataFactory $dataFactory
136 136
 	) {
137
-		parent::__construct( 'ConstraintReport' );
137
+		parent::__construct('ConstraintReport');
138 138
 
139 139
 		$this->entityLookup = $entityLookup;
140 140
 		$this->entityTitleLookup = $entityTitleLookup;
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
143 143
 		$language = $this->getLanguage();
144 144
 
145 145
 		$formatterOptions = new FormatterOptions();
146
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
146
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
147 147
 		$this->dataValueFormatter = $valueFormatterFactory->getValueFormatter(
148 148
 			SnakFormatter::FORMAT_HTML,
149 149
 			$formatterOptions
150 150
 		);
151 151
 
152
-		$labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup( $language );
152
+		$labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup($language);
153 153
 
154 154
 		$this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter(
155 155
 			$labelLookup
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @return array
183 183
 	 */
184 184
 	private function getModules() {
185
-		return [ 'SpecialConstraintReportPage' ];
185
+		return ['SpecialConstraintReportPage'];
186 186
 	}
187 187
 
188 188
 	/**
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @return string
201 201
 	 */
202 202
 	public function getDescription() {
203
-		return $this->msg( 'wbqc-constraintreport' )->escaped();
203
+		return $this->msg('wbqc-constraintreport')->escaped();
204 204
 	}
205 205
 
206 206
 	/**
@@ -212,42 +212,42 @@  discard block
 block discarded – undo
212 212
 	 * @throws EntityIdParsingException
213 213
 	 * @throws UnexpectedValueException
214 214
 	 */
215
-	public function execute( $subPage ) {
215
+	public function execute($subPage) {
216 216
 		$out = $this->getOutput();
217 217
 
218
-		$postRequest = $this->getContext()->getRequest()->getVal( 'entityid' );
219
-		if ( $postRequest ) {
220
-			$out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() );
218
+		$postRequest = $this->getContext()->getRequest()->getVal('entityid');
219
+		if ($postRequest) {
220
+			$out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL());
221 221
 			return;
222 222
 		}
223 223
 
224
-		$out->addModules( $this->getModules() );
224
+		$out->addModules($this->getModules());
225 225
 
226 226
 		$this->setHeaders();
227 227
 
228
-		$out->addHTML( $this->getExplanationText() );
228
+		$out->addHTML($this->getExplanationText());
229 229
 		$this->buildEntityIdForm();
230 230
 
231
-		if ( !$subPage ) {
231
+		if (!$subPage) {
232 232
 			return;
233 233
 		}
234 234
 
235
-		if ( !is_string( $subPage ) ) {
236
-			throw new InvalidArgumentException( '$subPage must be string.' );
235
+		if (!is_string($subPage)) {
236
+			throw new InvalidArgumentException('$subPage must be string.');
237 237
 		}
238 238
 
239 239
 		try {
240
-			$entityId = $this->entityIdParser->parse( $subPage );
241
-		} catch ( EntityIdParsingException $e ) {
240
+			$entityId = $this->entityIdParser->parse($subPage);
241
+		} catch (EntityIdParsingException $e) {
242 242
 			$out->addHTML(
243
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
243
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
244 244
 			);
245 245
 			return;
246 246
 		}
247 247
 
248
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
248
+		if (!$this->entityLookup->hasEntity($entityId)) {
249 249
 			$out->addHTML(
250
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
250
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
251 251
 			);
252 252
 			return;
253 253
 		}
@@ -255,18 +255,18 @@  discard block
 block discarded – undo
255 255
 		$this->dataFactory->increment(
256 256
 			'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck'
257 257
 		);
258
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
258
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
259 259
 
260
-		if ( count( $results ) > 0 ) {
260
+		if (count($results) > 0) {
261 261
 			$out->addHTML(
262
-				$this->buildResultHeader( $entityId )
263
-				. $this->buildSummary( $results )
264
-				. $this->buildResultTable( $entityId, $results )
262
+				$this->buildResultHeader($entityId)
263
+				. $this->buildSummary($results)
264
+				. $this->buildResultTable($entityId, $results)
265 265
 			);
266 266
 		} else {
267 267
 			$out->addHTML(
268
-				$this->buildResultHeader( $entityId )
269
-				. $this->buildNotice( 'wbqc-constraintreport-empty-result' )
268
+				$this->buildResultHeader($entityId)
269
+				. $this->buildNotice('wbqc-constraintreport-empty-result')
270 270
 			);
271 271
 		}
272 272
 	}
@@ -282,15 +282,15 @@  discard block
 block discarded – undo
282 282
 				'name' => 'entityid',
283 283
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
284 284
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
285
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped()
285
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped()
286 286
 			]
287 287
 		];
288
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' );
289
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() );
290
-		$htmlForm->setSubmitCallback( function() {
288
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form');
289
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped());
290
+		$htmlForm->setSubmitCallback(function() {
291 291
 			return false;
292 292
 		} );
293
-		$htmlForm->setMethod( 'post' );
293
+		$htmlForm->setMethod('post');
294 294
 		$htmlForm->show();
295 295
 	}
296 296
 
@@ -304,16 +304,16 @@  discard block
 block discarded – undo
304 304
 	 *
305 305
 	 * @return string HTML
306 306
 	 */
307
-	private function buildNotice( $messageKey, $error = false ) {
308
-		if ( !is_string( $messageKey ) ) {
309
-			throw new InvalidArgumentException( '$message must be string.' );
307
+	private function buildNotice($messageKey, $error = false) {
308
+		if (!is_string($messageKey)) {
309
+			throw new InvalidArgumentException('$message must be string.');
310 310
 		}
311
-		if ( !is_bool( $error ) ) {
312
-			throw new InvalidArgumentException( '$error must be bool.' );
311
+		if (!is_bool($error)) {
312
+			throw new InvalidArgumentException('$error must be bool.');
313 313
 		}
314 314
 
315 315
 		$cssClasses = 'wbqc-constraintreport-notice';
316
-		if ( $error ) {
316
+		if ($error) {
317 317
 			$cssClasses .= ' wbqc-constraintreport-notice-error';
318 318
 		}
319 319
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 				[
323 323
 					'class' => $cssClasses
324 324
 				],
325
-				$this->msg( $messageKey )->escaped()
325
+				$this->msg($messageKey)->escaped()
326 326
 			);
327 327
 	}
328 328
 
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
 	private function getExplanationText() {
333 333
 		return Html::rawElement(
334 334
 			'div',
335
-			[ 'class' => 'wbqc-explanation' ],
335
+			['class' => 'wbqc-explanation'],
336 336
 			Html::rawElement(
337 337
 				'p',
338 338
 				[],
339
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped()
339
+				$this->msg('wbqc-constraintreport-explanation-part-one')->escaped()
340 340
 			)
341 341
 			. Html::rawElement(
342 342
 				'p',
343 343
 				[],
344
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped()
344
+				$this->msg('wbqc-constraintreport-explanation-part-two')->escaped()
345 345
 			)
346 346
 		);
347 347
 	}
@@ -352,73 +352,72 @@  discard block
 block discarded – undo
352 352
 	 *
353 353
 	 * @return string HTML
354 354
 	 */
355
-	private function buildResultTable( EntityId $entityId, array $results ) {
355
+	private function buildResultTable(EntityId $entityId, array $results) {
356 356
 		// Set table headers
357 357
 		$table = new HtmlTableBuilder(
358 358
 			[
359 359
 				new HtmlTableHeaderBuilder(
360
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(),
360
+					$this->msg('wbqc-constraintreport-result-table-header-status')->escaped(),
361 361
 					true
362 362
 				),
363 363
 				new HtmlTableHeaderBuilder(
364
-					$this->msg( 'wbqc-constraintreport-result-table-header-claim' )->escaped(),
364
+					$this->msg('wbqc-constraintreport-result-table-header-claim')->escaped(),
365 365
 					true
366 366
 				),
367 367
 				new HtmlTableHeaderBuilder(
368
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(),
368
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(),
369 369
 					true
370 370
 				)
371 371
 			]
372 372
 		);
373 373
 
374
-		foreach ( $results as $result ) {
375
-			$table = $this->appendToResultTable( $table, $entityId, $result );
374
+		foreach ($results as $result) {
375
+			$table = $this->appendToResultTable($table, $entityId, $result);
376 376
 		}
377 377
 
378 378
 		return $table->toHtml();
379 379
 	}
380 380
 
381
-	private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) {
381
+	private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) {
382 382
 		// Status column
383 383
 		$statusColumn = $this->buildTooltipElement(
384
-			$this->formatStatus( $result->getStatus() ),
384
+			$this->formatStatus($result->getStatus()),
385 385
 			$result->getMessage() !== null ?
386
-				$this->violationMessageRenderer->render( $result->getMessage() ) :
387
-				null,
386
+				$this->violationMessageRenderer->render($result->getMessage()) : null,
388 387
 			'[?]'
389 388
 		);
390 389
 
391 390
 		// Claim column
392 391
 		$property = $this->entityIdLabelFormatter->formatEntityId(
393
-			new PropertyId( $result->getContextCursor()->getSnakPropertyId() )
392
+			new PropertyId($result->getContextCursor()->getSnakPropertyId())
394 393
 		);
395
-		if ( $result->getSnakType() === 'value' ) {
396
-			$value = $this->constraintParameterRenderer->formatValue( $result->getDataValue() );
394
+		if ($result->getSnakType() === 'value') {
395
+			$value = $this->constraintParameterRenderer->formatValue($result->getDataValue());
397 396
 		} else {
398
-			$value = htmlspecialchars( $result->getSnakType() );
397
+			$value = htmlspecialchars($result->getSnakType());
399 398
 		}
400 399
 
401 400
 		$claimColumn = $this->getClaimLink(
402 401
 			$entityId,
403
-			new PropertyId( $result->getContextCursor()->getSnakPropertyId() ),
404
-			$property . ': ' . $value
402
+			new PropertyId($result->getContextCursor()->getSnakPropertyId()),
403
+			$property.': '.$value
405 404
 		);
406 405
 
407 406
 		// Constraint column
408 407
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
409 408
 		try {
410
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
411
-		} catch ( InvalidArgumentException $e ) {
412
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
409
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
410
+		} catch (InvalidArgumentException $e) {
411
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
413 412
 		}
414 413
 		$constraintLink = $this->getClaimLink(
415
-			new PropertyId( $result->getContextCursor()->getSnakPropertyId() ),
416
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
414
+			new PropertyId($result->getContextCursor()->getSnakPropertyId()),
415
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
417 416
 			$constraintTypeLabel
418 417
 		);
419 418
 		$constraintColumn = $this->buildExpandableElement(
420 419
 			$constraintLink,
421
-			$this->constraintParameterRenderer->formatParameters( $result->getParameters() ),
420
+			$this->constraintParameterRenderer->formatParameters($result->getParameters()),
422 421
 			'[...]'
423 422
 		);
424 423
 
@@ -453,15 +452,15 @@  discard block
 block discarded – undo
453 452
 	 *
454 453
 	 * @return string HTML
455 454
 	 */
456
-	protected function buildResultHeader( EntityId $entityId ) {
457
-		$entityLink = sprintf( '%s (%s)',
458
-							   $this->entityIdLinkFormatter->formatEntityId( $entityId ),
459
-							   htmlspecialchars( $entityId->getSerialization() ) );
455
+	protected function buildResultHeader(EntityId $entityId) {
456
+		$entityLink = sprintf('%s (%s)',
457
+							   $this->entityIdLinkFormatter->formatEntityId($entityId),
458
+							   htmlspecialchars($entityId->getSerialization()));
460 459
 
461 460
 		return Html::rawElement(
462 461
 			'h3',
463 462
 			[],
464
-			sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink )
463
+			sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink)
465 464
 		);
466 465
 	}
467 466
 
@@ -472,24 +471,24 @@  discard block
 block discarded – undo
472 471
 	 *
473 472
 	 * @return string HTML
474 473
 	 */
475
-	protected function buildSummary( array $results ) {
474
+	protected function buildSummary(array $results) {
476 475
 		$statuses = [];
477
-		foreach ( $results as $result ) {
478
-			$status = strtolower( $result->getStatus() );
479
-			$statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1;
476
+		foreach ($results as $result) {
477
+			$status = strtolower($result->getStatus());
478
+			$statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1;
480 479
 		}
481 480
 
482 481
 		$statusElements = [];
483
-		foreach ( $statuses as $status => $count ) {
484
-			if ( $count > 0 ) {
482
+		foreach ($statuses as $status => $count) {
483
+			if ($count > 0) {
485 484
 				$statusElements[] =
486
-					$this->formatStatus( $status )
485
+					$this->formatStatus($status)
487 486
 					. ': '
488 487
 					. $count;
489 488
 			}
490 489
 		}
491 490
 
492
-		return Html::rawElement( 'p', [], implode( ', ', $statusElements ) );
491
+		return Html::rawElement('p', [], implode(', ', $statusElements));
493 492
 	}
494 493
 
495 494
 	/**
@@ -504,15 +503,15 @@  discard block
 block discarded – undo
504 503
 	 *
505 504
 	 * @return string HTML
506 505
 	 */
507
-	protected function buildTooltipElement( $content, $tooltipContent, $indicator ) {
508
-		if ( !is_string( $content ) ) {
509
-			throw new InvalidArgumentException( '$content has to be string.' );
506
+	protected function buildTooltipElement($content, $tooltipContent, $indicator) {
507
+		if (!is_string($content)) {
508
+			throw new InvalidArgumentException('$content has to be string.');
510 509
 		}
511
-		if ( $tooltipContent && ( !is_string( $tooltipContent ) ) ) {
512
-			throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' );
510
+		if ($tooltipContent && (!is_string($tooltipContent))) {
511
+			throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.');
513 512
 		}
514 513
 
515
-		if ( empty( $tooltipContent ) ) {
514
+		if (empty($tooltipContent)) {
516 515
 			return $content;
517 516
 		}
518 517
 
@@ -529,13 +528,13 @@  discard block
 block discarded – undo
529 528
 			[
530 529
 				'class' => 'wbqc-indicator'
531 530
 			],
532
-			htmlspecialchars( $indicator ) . $tooltip
531
+			htmlspecialchars($indicator).$tooltip
533 532
 		);
534 533
 
535 534
 		return Html::rawElement(
536 535
 			'span',
537 536
 			[],
538
-			sprintf( '%s %s', $content, $tooltipIndicator )
537
+			sprintf('%s %s', $content, $tooltipIndicator)
539 538
 		);
540 539
 	}
541 540
 
@@ -551,15 +550,15 @@  discard block
 block discarded – undo
551 550
 	 *
552 551
 	 * @return string HTML
553 552
 	 */
554
-	protected function buildExpandableElement( $content, $expandableContent, $indicator ) {
555
-		if ( !is_string( $content ) ) {
556
-			throw new InvalidArgumentException( '$content has to be string.' );
553
+	protected function buildExpandableElement($content, $expandableContent, $indicator) {
554
+		if (!is_string($content)) {
555
+			throw new InvalidArgumentException('$content has to be string.');
557 556
 		}
558
-		if ( $expandableContent && ( !is_string( $expandableContent ) ) ) {
559
-			throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' );
557
+		if ($expandableContent && (!is_string($expandableContent))) {
558
+			throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.');
560 559
 		}
561 560
 
562
-		if ( empty( $expandableContent ) ) {
561
+		if (empty($expandableContent)) {
563 562
 			return $content;
564 563
 		}
565 564
 
@@ -579,7 +578,7 @@  discard block
 block discarded – undo
579 578
 			$expandableContent
580 579
 		);
581 580
 
582
-		return sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent );
581
+		return sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent);
583 582
 	}
584 583
 
585 584
 	/**
@@ -591,16 +590,16 @@  discard block
 block discarded – undo
591 590
 	 *
592 591
 	 * @return string HTML
593 592
 	 */
594
-	private function formatStatus( $status ) {
595
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
593
+	private function formatStatus($status) {
594
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
596 595
 
597 596
 		$formattedStatus =
598 597
 			Html::element(
599 598
 				'span',
600 599
 				[
601
-					'class' => 'wbqc-status wbqc-status-' . $status
600
+					'class' => 'wbqc-status wbqc-status-'.$status
602 601
 				],
603
-				$this->msg( $messageName )->text()
602
+				$this->msg($messageName)->text()
604 603
 			);
605 604
 
606 605
 		return $formattedStatus;
@@ -616,26 +615,26 @@  discard block
 block discarded – undo
616 615
 	 *
617 616
 	 * @return string HTML
618 617
 	 */
619
-	protected function formatDataValues( $dataValues, $separator = ', ' ) {
620
-		if ( $dataValues instanceof DataValue ) {
621
-			$dataValues = [ $dataValues ];
622
-		} elseif ( !is_array( $dataValues ) ) {
623
-			throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' );
618
+	protected function formatDataValues($dataValues, $separator = ', ') {
619
+		if ($dataValues instanceof DataValue) {
620
+			$dataValues = [$dataValues];
621
+		} elseif (!is_array($dataValues)) {
622
+			throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.');
624 623
 		}
625 624
 
626 625
 		$formattedDataValues = [];
627
-		foreach ( $dataValues as $dataValue ) {
628
-			if ( !( $dataValue instanceof DataValue ) ) {
629
-				throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' );
626
+		foreach ($dataValues as $dataValue) {
627
+			if (!($dataValue instanceof DataValue)) {
628
+				throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.');
630 629
 			}
631
-			if ( $dataValue instanceof EntityIdValue ) {
632
-				$formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() );
630
+			if ($dataValue instanceof EntityIdValue) {
631
+				$formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId());
633 632
 			} else {
634
-				$formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue );
633
+				$formattedDataValues[] = $this->dataValueFormatter->format($dataValue);
635 634
 			}
636 635
 		}
637 636
 
638
-		return implode( $separator, $formattedDataValues );
637
+		return implode($separator, $formattedDataValues);
639 638
 	}
640 639
 
641 640
 	/**
@@ -647,11 +646,11 @@  discard block
 block discarded – undo
647 646
 	 *
648 647
 	 * @return string HTML
649 648
 	 */
650
-	private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) {
649
+	private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) {
651 650
 		return Html::rawElement(
652 651
 			'a',
653 652
 			[
654
-				'href' => $this->getClaimUrl( $entityId, $propertyId ),
653
+				'href' => $this->getClaimUrl($entityId, $propertyId),
655 654
 				'target' => '_blank'
656 655
 			],
657 656
 			$text
@@ -666,9 +665,9 @@  discard block
 block discarded – undo
666 665
 	 *
667 666
 	 * @return string
668 667
 	 */
669
-	private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) {
670
-		$title = $this->entityTitleLookup->getTitleForId( $entityId );
671
-		$entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() );
668
+	private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) {
669
+		$title = $this->entityTitleLookup->getTitleForId($entityId);
670
+		$entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization());
672 671
 
673 672
 		return $entityUrl;
674 673
 	}
Please login to merge, or discard this patch.
src/Api/CheckingResultsBuilder.php 1 patch
Spacing   +30 added lines, -31 removed lines patch added patch discarded remove patch
@@ -84,65 +84,64 @@  discard block
 block discarded – undo
84 84
 	) {
85 85
 		$response = [];
86 86
 		$metadatas = [];
87
-		$statusesFlipped = array_flip( $statuses );
88
-		foreach ( $entityIds as $entityId ) {
87
+		$statusesFlipped = array_flip($statuses);
88
+		foreach ($entityIds as $entityId) {
89 89
 			$results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnEntityId(
90 90
 				$entityId,
91 91
 				$constraintIds,
92
-				[ $this, 'defaultResults' ]
92
+				[$this, 'defaultResults']
93 93
 			);
94
-			foreach ( $results as $result ) {
94
+			foreach ($results as $result) {
95 95
 				$metadatas[] = $result->getMetadata();
96
-				if ( $this->statusSelected( $statusesFlipped, $result ) ) {
97
-					$resultArray = $this->checkResultToArray( $result );
98
-					$result->getContextCursor()->storeCheckResultInArray( $resultArray, $response );
96
+				if ($this->statusSelected($statusesFlipped, $result)) {
97
+					$resultArray = $this->checkResultToArray($result);
98
+					$result->getContextCursor()->storeCheckResultInArray($resultArray, $response);
99 99
 				}
100 100
 			}
101 101
 		}
102
-		foreach ( $claimIds as $claimId ) {
102
+		foreach ($claimIds as $claimId) {
103 103
 			$results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnClaimId(
104 104
 				$claimId,
105 105
 				$constraintIds,
106
-				[ $this, 'defaultResults' ]
106
+				[$this, 'defaultResults']
107 107
 			);
108
-			foreach ( $results as $result ) {
108
+			foreach ($results as $result) {
109 109
 				$metadatas[] = $result->getMetadata();
110
-				if ( $this->statusSelected( $statusesFlipped, $result ) ) {
111
-					$resultArray = $this->checkResultToArray( $result );
112
-					$result->getContextCursor()->storeCheckResultInArray( $resultArray, $response );
110
+				if ($this->statusSelected($statusesFlipped, $result)) {
111
+					$resultArray = $this->checkResultToArray($result);
112
+					$result->getContextCursor()->storeCheckResultInArray($resultArray, $response);
113 113
 				}
114 114
 			}
115 115
 		}
116 116
 		return new CachedCheckConstraintsResponse(
117 117
 			$response,
118
-			Metadata::merge( $metadatas )
118
+			Metadata::merge($metadatas)
119 119
 		);
120 120
 	}
121 121
 
122
-	public function defaultResults( Context $context ) {
122
+	public function defaultResults(Context $context) {
123 123
 		return $context->getType() === Context::TYPE_STATEMENT ?
124
-			[ new NullResult( $context ) ] :
125
-			[];
124
+			[new NullResult($context)] : [];
126 125
 	}
127 126
 
128
-	public function statusSelected( array $statusesFlipped, CheckResult $result ) {
129
-		return array_key_exists( $result->getStatus(), $statusesFlipped ) ||
127
+	public function statusSelected(array $statusesFlipped, CheckResult $result) {
128
+		return array_key_exists($result->getStatus(), $statusesFlipped) ||
130 129
 			$result instanceof NullResult;
131 130
 	}
132 131
 
133
-	public function checkResultToArray( CheckResult $checkResult ) {
134
-		if ( $checkResult instanceof NullResult ) {
132
+	public function checkResultToArray(CheckResult $checkResult) {
133
+		if ($checkResult instanceof NullResult) {
135 134
 			return null;
136 135
 		}
137 136
 
138 137
 		$constraintId = $checkResult->getConstraint()->getConstraintId();
139 138
 		$typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId();
140
-		$constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() );
139
+		$constraintPropertyId = new PropertyId($checkResult->getContextCursor()->getSnakPropertyId());
141 140
 
142
-		$title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId );
143
-		$typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) );
141
+		$title = $this->entityTitleLookup->getTitleForId($constraintPropertyId);
142
+		$typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId));
144 143
 		// TODO link to the statement when possible (T169224)
145
-		$link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' );
144
+		$link = $title->getFullURL().'#'.$this->config->get('WBQualityConstraintsPropertyConstraintId');
146 145
 
147 146
 		$constraint = [
148 147
 			'id' => $constraintId,
@@ -151,11 +150,11 @@  discard block
 block discarded – undo
151 150
 			'link' => $link,
152 151
 			'discussLink' => $title->getTalkPage()->getFullURL(),
153 152
 		];
154
-		if ( $this->config->get( 'WBQualityConstraintsIncludeDetailInApi' ) ) {
153
+		if ($this->config->get('WBQualityConstraintsIncludeDetailInApi')) {
155 154
 			$parameters = $checkResult->getParameters();
156 155
 			$constraint += [
157 156
 				'detail' => $parameters,
158
-				'detailHTML' => $this->constraintParameterRenderer->formatParameters( $parameters ),
157
+				'detailHTML' => $this->constraintParameterRenderer->formatParameters($parameters),
159 158
 			];
160 159
 		}
161 160
 
@@ -165,14 +164,14 @@  discard block
 block discarded – undo
165 164
 			'constraint' => $constraint
166 165
 		];
167 166
 		$message = $checkResult->getMessage();
168
-		if ( $message ) {
169
-			$result['message-html'] = $this->violationMessageRenderer->render( $message );
167
+		if ($message) {
168
+			$result['message-html'] = $this->violationMessageRenderer->render($message);
170 169
 		}
171
-		if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) {
170
+		if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) {
172 171
 			$result['claim'] = $checkResult->getContextCursor()->getStatementGuid();
173 172
 		}
174 173
 		$cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray();
175
-		if ( $cachingMetadataArray !== null ) {
174
+		if ($cachingMetadataArray !== null) {
176 175
 			$result['cached'] = $cachingMetadataArray;
177 176
 		}
178 177
 
Please login to merge, or discard this patch.