Completed
Push — master ( 66a8d7...54b0e6 )
by
unknown
02:31
created
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		Config $config,
137 137
 		IBufferingStatsdDataFactory $dataFactory
138 138
 	) {
139
-		parent::__construct( 'ConstraintReport' );
139
+		parent::__construct('ConstraintReport');
140 140
 
141 141
 		$this->entityLookup = $entityLookup;
142 142
 		$this->entityTitleLookup = $entityTitleLookup;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$language = $this->getLanguage();
146 146
 
147 147
 		$formatterOptions = new FormatterOptions();
148
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
148
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
149 149
 		$this->dataValueFormatter = $valueFormatterFactory->getValueFormatter(
150 150
 			SnakFormatter::FORMAT_HTML,
151 151
 			$formatterOptions
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 * @return string
206 206
 	 */
207 207
 	public function getDescription() {
208
-		return $this->msg( 'wbqc-constraintreport' )->escaped();
208
+		return $this->msg('wbqc-constraintreport')->escaped();
209 209
 	}
210 210
 
211 211
 	/**
@@ -217,43 +217,43 @@  discard block
 block discarded – undo
217 217
 	 * @throws EntityIdParsingException
218 218
 	 * @throws UnexpectedValueException
219 219
 	 */
220
-	public function execute( $subPage ) {
220
+	public function execute($subPage) {
221 221
 		$out = $this->getOutput();
222 222
 
223
-		$postRequest = $this->getContext()->getRequest()->getVal( 'entityid' );
224
-		if ( $postRequest ) {
225
-			$out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() );
223
+		$postRequest = $this->getContext()->getRequest()->getVal('entityid');
224
+		if ($postRequest) {
225
+			$out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL());
226 226
 			return;
227 227
 		}
228 228
 
229 229
 		$out->enableOOUI();
230
-		$out->addModules( $this->getModules() );
230
+		$out->addModules($this->getModules());
231 231
 
232 232
 		$this->setHeaders();
233 233
 
234
-		$out->addHTML( $this->getExplanationText() );
234
+		$out->addHTML($this->getExplanationText());
235 235
 		$this->buildEntityIdForm();
236 236
 
237
-		if ( !$subPage ) {
237
+		if (!$subPage) {
238 238
 			return;
239 239
 		}
240 240
 
241
-		if ( !is_string( $subPage ) ) {
242
-			throw new InvalidArgumentException( '$subPage must be string.' );
241
+		if (!is_string($subPage)) {
242
+			throw new InvalidArgumentException('$subPage must be string.');
243 243
 		}
244 244
 
245 245
 		try {
246
-			$entityId = $this->entityIdParser->parse( $subPage );
247
-		} catch ( EntityIdParsingException $e ) {
246
+			$entityId = $this->entityIdParser->parse($subPage);
247
+		} catch (EntityIdParsingException $e) {
248 248
 			$out->addHTML(
249
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
249
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
250 250
 			);
251 251
 			return;
252 252
 		}
253 253
 
254
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
254
+		if (!$this->entityLookup->hasEntity($entityId)) {
255 255
 			$out->addHTML(
256
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
256
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
257 257
 			);
258 258
 			return;
259 259
 		}
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
 		$this->dataFactory->increment(
262 262
 			'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck'
263 263
 		);
264
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
264
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
265 265
 
266
-		if ( $results !== [] ) {
266
+		if ($results !== []) {
267 267
 			$out->addHTML(
268
-				$this->buildResultHeader( $entityId )
269
-				. $this->buildSummary( $results )
270
-				. $this->buildResultTable( $entityId, $results )
268
+				$this->buildResultHeader($entityId)
269
+				. $this->buildSummary($results)
270
+				. $this->buildResultTable($entityId, $results)
271 271
 			);
272 272
 		} else {
273 273
 			$out->addHTML(
274
-				$this->buildResultHeader( $entityId )
275
-				. $this->buildNotice( 'wbqc-constraintreport-empty-result' )
274
+				$this->buildResultHeader($entityId)
275
+				. $this->buildNotice('wbqc-constraintreport-empty-result')
276 276
 			);
277 277
 		}
278 278
 	}
@@ -288,15 +288,15 @@  discard block
 block discarded – undo
288 288
 				'name' => 'entityid',
289 289
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
290 290
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
291
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped()
291
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped()
292 292
 			]
293 293
 		];
294
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' );
295
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() );
296
-		$htmlForm->setSubmitCallback( function() {
294
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form');
295
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped());
296
+		$htmlForm->setSubmitCallback(function() {
297 297
 			return false;
298 298
 		} );
299
-		$htmlForm->setMethod( 'post' );
299
+		$htmlForm->setMethod('post');
300 300
 		$htmlForm->show();
301 301
 	}
302 302
 
@@ -310,16 +310,16 @@  discard block
 block discarded – undo
310 310
 	 *
311 311
 	 * @return string HTML
312 312
 	 */
313
-	private function buildNotice( $messageKey, $error = false ) {
314
-		if ( !is_string( $messageKey ) ) {
315
-			throw new InvalidArgumentException( '$message must be string.' );
313
+	private function buildNotice($messageKey, $error = false) {
314
+		if (!is_string($messageKey)) {
315
+			throw new InvalidArgumentException('$message must be string.');
316 316
 		}
317
-		if ( !is_bool( $error ) ) {
318
-			throw new InvalidArgumentException( '$error must be bool.' );
317
+		if (!is_bool($error)) {
318
+			throw new InvalidArgumentException('$error must be bool.');
319 319
 		}
320 320
 
321 321
 		$cssClasses = 'wbqc-constraintreport-notice';
322
-		if ( $error ) {
322
+		if ($error) {
323 323
 			$cssClasses .= ' wbqc-constraintreport-notice-error';
324 324
 		}
325 325
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 				[
329 329
 					'class' => $cssClasses
330 330
 				],
331
-				$this->msg( $messageKey )->escaped()
331
+				$this->msg($messageKey)->escaped()
332 332
 			);
333 333
 	}
334 334
 
@@ -338,16 +338,16 @@  discard block
 block discarded – undo
338 338
 	private function getExplanationText() {
339 339
 		return Html::rawElement(
340 340
 			'div',
341
-			[ 'class' => 'wbqc-explanation' ],
341
+			['class' => 'wbqc-explanation'],
342 342
 			Html::rawElement(
343 343
 				'p',
344 344
 				[],
345
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped()
345
+				$this->msg('wbqc-constraintreport-explanation-part-one')->escaped()
346 346
 			)
347 347
 			. Html::rawElement(
348 348
 				'p',
349 349
 				[],
350
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped()
350
+				$this->msg('wbqc-constraintreport-explanation-part-two')->escaped()
351 351
 			)
352 352
 		);
353 353
 	}
@@ -358,72 +358,72 @@  discard block
 block discarded – undo
358 358
 	 *
359 359
 	 * @return string HTML
360 360
 	 */
361
-	private function buildResultTable( EntityId $entityId, array $results ) {
361
+	private function buildResultTable(EntityId $entityId, array $results) {
362 362
 		// Set table headers
363 363
 		$table = new HtmlTableBuilder(
364 364
 			[
365 365
 				new HtmlTableHeaderBuilder(
366
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(),
366
+					$this->msg('wbqc-constraintreport-result-table-header-status')->escaped(),
367 367
 					true
368 368
 				),
369 369
 				new HtmlTableHeaderBuilder(
370
-					$this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(),
370
+					$this->msg('wbqc-constraintreport-result-table-header-property')->escaped(),
371 371
 					true
372 372
 				),
373 373
 				new HtmlTableHeaderBuilder(
374
-					$this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(),
374
+					$this->msg('wbqc-constraintreport-result-table-header-message')->escaped(),
375 375
 					true
376 376
 				),
377 377
 				new HtmlTableHeaderBuilder(
378
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(),
378
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(),
379 379
 					true
380 380
 				)
381 381
 			]
382 382
 		);
383 383
 
384
-		foreach ( $results as $result ) {
385
-			$table = $this->appendToResultTable( $table, $entityId, $result );
384
+		foreach ($results as $result) {
385
+			$table = $this->appendToResultTable($table, $entityId, $result);
386 386
 		}
387 387
 
388 388
 		return $table->toHtml();
389 389
 	}
390 390
 
391
-	private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) {
391
+	private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) {
392 392
 		$message = $result->getMessage();
393
-		if ( $message === null ) {
393
+		if ($message === null) {
394 394
 			// no row for this result
395 395
 			return $table;
396 396
 		}
397 397
 
398 398
 		// Status column
399
-		$statusColumn = $this->formatStatus( $result->getStatus() );
399
+		$statusColumn = $this->formatStatus($result->getStatus());
400 400
 
401 401
 		// Property column
402
-		$propertyId = new PropertyId( $result->getContextCursor()->getSnakPropertyId() );
402
+		$propertyId = new PropertyId($result->getContextCursor()->getSnakPropertyId());
403 403
 		$propertyColumn = $this->getClaimLink(
404 404
 			$entityId,
405 405
 			$propertyId,
406
-			$this->entityIdLabelFormatter->formatEntityId( $propertyId )
406
+			$this->entityIdLabelFormatter->formatEntityId($propertyId)
407 407
 		);
408 408
 
409 409
 		// Message column
410
-		$messageColumn = $this->violationMessageRenderer->render( $message );
410
+		$messageColumn = $this->violationMessageRenderer->render($message);
411 411
 
412 412
 		// Constraint column
413 413
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
414 414
 		try {
415
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
416
-		} catch ( InvalidArgumentException $e ) {
417
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
415
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
416
+		} catch (InvalidArgumentException $e) {
417
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
418 418
 		}
419 419
 		$constraintLink = $this->getClaimLink(
420 420
 			$propertyId,
421
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
421
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
422 422
 			$constraintTypeLabel
423 423
 		);
424 424
 		$constraintColumn = $this->buildExpandableElement(
425 425
 			$constraintLink,
426
-			$this->constraintParameterRenderer->formatParameters( $result->getParameters() ),
426
+			$this->constraintParameterRenderer->formatParameters($result->getParameters()),
427 427
 			'[...]'
428 428
 		);
429 429
 
@@ -463,15 +463,15 @@  discard block
 block discarded – undo
463 463
 	 *
464 464
 	 * @return string HTML
465 465
 	 */
466
-	protected function buildResultHeader( EntityId $entityId ) {
467
-		$entityLink = sprintf( '%s (%s)',
468
-							   $this->entityIdLinkFormatter->formatEntityId( $entityId ),
469
-							   htmlspecialchars( $entityId->getSerialization() ) );
466
+	protected function buildResultHeader(EntityId $entityId) {
467
+		$entityLink = sprintf('%s (%s)',
468
+							   $this->entityIdLinkFormatter->formatEntityId($entityId),
469
+							   htmlspecialchars($entityId->getSerialization()));
470 470
 
471 471
 		return Html::rawElement(
472 472
 			'h3',
473 473
 			[],
474
-			sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink )
474
+			sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink)
475 475
 		);
476 476
 	}
477 477
 
@@ -482,24 +482,24 @@  discard block
 block discarded – undo
482 482
 	 *
483 483
 	 * @return string HTML
484 484
 	 */
485
-	protected function buildSummary( array $results ) {
485
+	protected function buildSummary(array $results) {
486 486
 		$statuses = [];
487
-		foreach ( $results as $result ) {
488
-			$status = strtolower( $result->getStatus() );
489
-			$statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1;
487
+		foreach ($results as $result) {
488
+			$status = strtolower($result->getStatus());
489
+			$statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1;
490 490
 		}
491 491
 
492 492
 		$statusElements = [];
493
-		foreach ( $statuses as $status => $count ) {
494
-			if ( $count > 0 ) {
493
+		foreach ($statuses as $status => $count) {
494
+			if ($count > 0) {
495 495
 				$statusElements[] =
496
-					$this->formatStatus( $status )
496
+					$this->formatStatus($status)
497 497
 					. ': '
498 498
 					. $count;
499 499
 			}
500 500
 		}
501 501
 
502
-		return Html::rawElement( 'p', [], implode( ', ', $statusElements ) );
502
+		return Html::rawElement('p', [], implode(', ', $statusElements));
503 503
 	}
504 504
 
505 505
 	/**
@@ -514,15 +514,15 @@  discard block
 block discarded – undo
514 514
 	 *
515 515
 	 * @return string HTML
516 516
 	 */
517
-	protected function buildExpandableElement( $content, $expandableContent, $indicator ) {
518
-		if ( !is_string( $content ) ) {
519
-			throw new InvalidArgumentException( '$content has to be string.' );
517
+	protected function buildExpandableElement($content, $expandableContent, $indicator) {
518
+		if (!is_string($content)) {
519
+			throw new InvalidArgumentException('$content has to be string.');
520 520
 		}
521
-		if ( $expandableContent && ( !is_string( $expandableContent ) ) ) {
522
-			throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' );
521
+		if ($expandableContent && (!is_string($expandableContent))) {
522
+			throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.');
523 523
 		}
524 524
 
525
-		if ( empty( $expandableContent ) ) {
525
+		if (empty($expandableContent)) {
526 526
 			return $content;
527 527
 		}
528 528
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 			$expandableContent
543 543
 		);
544 544
 
545
-		return sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent );
545
+		return sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent);
546 546
 	}
547 547
 
548 548
 	/**
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 	 *
555 555
 	 * @return string HTML
556 556
 	 */
557
-	private function formatStatus( $status ) {
558
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
557
+	private function formatStatus($status) {
558
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
559 559
 		$statusIcons = [
560 560
 			CheckResult::STATUS_WARNING => [
561 561
 				'icon' => 'non-mandatory-constraint-violation',
@@ -569,25 +569,25 @@  discard block
 block discarded – undo
569 569
 			],
570 570
 		];
571 571
 
572
-		if ( array_key_exists( $status, $statusIcons ) ) {
573
-			$iconWidget = new IconWidget( $statusIcons[$status] );
574
-			$iconHtml = $iconWidget->toString() . ' ';
572
+		if (array_key_exists($status, $statusIcons)) {
573
+			$iconWidget = new IconWidget($statusIcons[$status]);
574
+			$iconHtml = $iconWidget->toString().' ';
575 575
 		} else {
576 576
 			$iconHtml = '';
577 577
 		}
578 578
 
579
-		$labelWidget = new LabelWidget( [
580
-			'label' => $this->msg( $messageName )->text(),
581
-		] );
579
+		$labelWidget = new LabelWidget([
580
+			'label' => $this->msg($messageName)->text(),
581
+		]);
582 582
 		$labelHtml = $labelWidget->toString();
583 583
 
584 584
 		$formattedStatus =
585 585
 			Html::rawElement(
586 586
 				'span',
587 587
 				[
588
-					'class' => 'wbqc-status wbqc-status-' . $status
588
+					'class' => 'wbqc-status wbqc-status-'.$status
589 589
 				],
590
-				$iconHtml . $labelHtml
590
+				$iconHtml.$labelHtml
591 591
 			);
592 592
 
593 593
 		return $formattedStatus;
@@ -603,26 +603,26 @@  discard block
 block discarded – undo
603 603
 	 *
604 604
 	 * @return string HTML
605 605
 	 */
606
-	protected function formatDataValues( $dataValues, $separator = ', ' ) {
607
-		if ( $dataValues instanceof DataValue ) {
608
-			$dataValues = [ $dataValues ];
609
-		} elseif ( !is_array( $dataValues ) ) {
610
-			throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' );
606
+	protected function formatDataValues($dataValues, $separator = ', ') {
607
+		if ($dataValues instanceof DataValue) {
608
+			$dataValues = [$dataValues];
609
+		} elseif (!is_array($dataValues)) {
610
+			throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.');
611 611
 		}
612 612
 
613 613
 		$formattedDataValues = [];
614
-		foreach ( $dataValues as $dataValue ) {
615
-			if ( !( $dataValue instanceof DataValue ) ) {
616
-				throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' );
614
+		foreach ($dataValues as $dataValue) {
615
+			if (!($dataValue instanceof DataValue)) {
616
+				throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.');
617 617
 			}
618
-			if ( $dataValue instanceof EntityIdValue ) {
619
-				$formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() );
618
+			if ($dataValue instanceof EntityIdValue) {
619
+				$formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId());
620 620
 			} else {
621
-				$formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue );
621
+				$formattedDataValues[] = $this->dataValueFormatter->format($dataValue);
622 622
 			}
623 623
 		}
624 624
 
625
-		return implode( $separator, $formattedDataValues );
625
+		return implode($separator, $formattedDataValues);
626 626
 	}
627 627
 
628 628
 	/**
@@ -634,11 +634,11 @@  discard block
 block discarded – undo
634 634
 	 *
635 635
 	 * @return string HTML
636 636
 	 */
637
-	private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) {
637
+	private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) {
638 638
 		return Html::rawElement(
639 639
 			'a',
640 640
 			[
641
-				'href' => $this->getClaimUrl( $entityId, $propertyId ),
641
+				'href' => $this->getClaimUrl($entityId, $propertyId),
642 642
 				'target' => '_blank'
643 643
 			],
644 644
 			$text
@@ -653,9 +653,9 @@  discard block
 block discarded – undo
653 653
 	 *
654 654
 	 * @return string
655 655
 	 */
656
-	private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) {
657
-		$title = $this->entityTitleLookup->getTitleForId( $entityId );
658
-		$entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() );
656
+	private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) {
657
+		$title = $this->entityTitleLookup->getTitleForId($entityId);
658
+		$entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization());
659 659
 
660 660
 		return $entityUrl;
661 661
 	}
Please login to merge, or discard this patch.
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return self
76 76
 	 */
77
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
77
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
78 78
 		$constraintReportFactory = ConstraintReportFactory::getDefaultInstance();
79 79
 		$repo = WikibaseRepo::getDefaultInstance();
80
-		$helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() );
80
+		$helperFactory = $repo->getApiHelperFactory(RequestContext::getMain());
81 81
 		$language = $repo->getUserLanguage();
82 82
 
83 83
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
84
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language );
84
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language);
85 85
 		$formatterOptions = new FormatterOptions();
86
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
86
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
87 87
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
88
-		$dataValueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
88
+		$dataValueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
89 89
 		$config = MediaWikiServices::getInstance()->getMainConfig();
90 90
 		$violationMessageRenderer = new MultilingualTextViolationMessageRenderer(
91 91
 			$entityIdHtmlLinkFormatter,
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 		StatementGuidParser $statementGuidParser,
126 126
 		IBufferingStatsdDataFactory $dataFactory
127 127
 	) {
128
-		parent::__construct( $main, $name, $prefix );
128
+		parent::__construct($main, $name, $prefix);
129 129
 
130
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
130
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
131 131
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
132 132
 		$this->violationMessageRenderer = $violationMessageRenderer;
133 133
 		$this->statementGuidParser = $statementGuidParser;
@@ -142,39 +142,39 @@  discard block
 block discarded – undo
142 142
 		$params = $this->extractRequestParams();
143 143
 		$result = $this->getResult();
144 144
 
145
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
146
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
145
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
146
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
147 147
 
148
-		$this->checkPropertyIds( $propertyIds, $result );
149
-		$this->checkConstraintIds( $constraintIds, $result );
148
+		$this->checkPropertyIds($propertyIds, $result);
149
+		$this->checkConstraintIds($constraintIds, $result);
150 150
 
151
-		$result->addValue( null, 'success', 1 );
151
+		$result->addValue(null, 'success', 1);
152 152
 	}
153 153
 
154 154
 	/**
155 155
 	 * @param array|null $propertyIdSerializations
156 156
 	 * @return PropertyId[]
157 157
 	 */
158
-	private function parsePropertyIds( $propertyIdSerializations ) {
159
-		if ( $propertyIdSerializations === null ) {
158
+	private function parsePropertyIds($propertyIdSerializations) {
159
+		if ($propertyIdSerializations === null) {
160 160
 			return [];
161
-		} elseif ( empty( $propertyIdSerializations ) ) {
161
+		} elseif (empty($propertyIdSerializations)) {
162 162
 			$this->apiErrorReporter->dieError(
163
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
163
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
164 164
 				'no-data'
165 165
 			);
166 166
 		}
167 167
 
168 168
 		return array_map(
169
-			function( $propertyIdSerialization ) {
169
+			function($propertyIdSerialization) {
170 170
 				try {
171
-					return new PropertyId( $propertyIdSerialization );
172
-				} catch ( InvalidArgumentException $e ) {
171
+					return new PropertyId($propertyIdSerialization);
172
+				} catch (InvalidArgumentException $e) {
173 173
 					$this->apiErrorReporter->dieError(
174 174
 						"Invalid id: $propertyIdSerialization",
175 175
 						'invalid-property-id',
176 176
 						0, // default argument
177
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
177
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
178 178
 					);
179 179
 				}
180 180
 			},
@@ -186,35 +186,35 @@  discard block
 block discarded – undo
186 186
 	 * @param array|null $constraintIds
187 187
 	 * @return string[]
188 188
 	 */
189
-	private function parseConstraintIds( $constraintIds ) {
190
-		if ( $constraintIds === null ) {
189
+	private function parseConstraintIds($constraintIds) {
190
+		if ($constraintIds === null) {
191 191
 			return [];
192
-		} elseif ( empty( $constraintIds ) ) {
192
+		} elseif (empty($constraintIds)) {
193 193
 			$this->apiErrorReporter->dieError(
194
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
194
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
195 195
 				'no-data'
196 196
 			);
197 197
 		}
198 198
 
199 199
 		return array_map(
200
-			function( $constraintId ) {
200
+			function($constraintId) {
201 201
 				try {
202
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
203
-					if ( !$propertyId instanceof PropertyId ) {
202
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
203
+					if (!$propertyId instanceof PropertyId) {
204 204
 						$this->apiErrorReporter->dieError(
205 205
 							"Invalid property ID: {$propertyId->getSerialization()}",
206 206
 							'invalid-property-id',
207 207
 							0, // default argument
208
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
208
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
209 209
 						);
210 210
 					}
211 211
 					return $constraintId;
212
-				} catch ( StatementGuidParsingException $e ) {
212
+				} catch (StatementGuidParsingException $e) {
213 213
 					$this->apiErrorReporter->dieError(
214 214
 						"Invalid statement GUID: $constraintId",
215 215
 						'invalid-guid',
216 216
 						0, // default argument
217
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
217
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
218 218
 					);
219 219
 				}
220 220
 			},
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
 	 * @param PropertyId[] $propertyIds
227 227
 	 * @param ApiResult $result
228 228
 	 */
229
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ) {
230
-		foreach ( $propertyIds as $propertyId ) {
231
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
232
-			$allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId( $propertyId );
233
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
234
-				$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
229
+	private function checkPropertyIds(array $propertyIds, ApiResult $result) {
230
+		foreach ($propertyIds as $propertyId) {
231
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
232
+			$allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId($propertyId);
233
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
234
+				$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
235 235
 			}
236 236
 		}
237 237
 	}
@@ -240,14 +240,14 @@  discard block
 block discarded – undo
240 240
 	 * @param string[] $constraintIds
241 241
 	 * @param ApiResult $result
242 242
 	 */
243
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ) {
244
-		foreach ( $constraintIds as $constraintId ) {
245
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
243
+	private function checkConstraintIds(array $constraintIds, ApiResult $result) {
244
+		foreach ($constraintIds as $constraintId) {
245
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
246 246
 				// already checked as part of checkPropertyIds()
247 247
 				continue;
248 248
 			}
249
-			$constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId( $constraintId );
250
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
249
+			$constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId($constraintId);
250
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
251 251
 		}
252 252
 	}
253 253
 
@@ -255,17 +255,17 @@  discard block
 block discarded – undo
255 255
 	 * @param PropertyId $propertyId
256 256
 	 * @return string[]
257 257
 	 */
258
-	private function getResultPathForPropertyId( PropertyId $propertyId ) {
259
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
258
+	private function getResultPathForPropertyId(PropertyId $propertyId) {
259
+		return [$this->getModuleName(), $propertyId->getSerialization()];
260 260
 	}
261 261
 
262 262
 	/**
263 263
 	 * @param string $constraintId
264 264
 	 * @return string[]
265 265
 	 */
266
-	private function getResultPathForConstraintId( $constraintId ) {
267
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
268
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
266
+	private function getResultPathForConstraintId($constraintId) {
267
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
268
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
269 269
 	}
270 270
 
271 271
 	/**
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 	 * @param ConstraintParameterException[]|null $constraintParameterExceptions
276 276
 	 * @param ApiResult $result
277 277
 	 */
278
-	private function addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, ApiResult $result ) {
279
-		$path = $this->getResultPathForConstraintId( $constraintId );
280
-		if ( $constraintParameterExceptions === null ) {
278
+	private function addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, ApiResult $result) {
279
+		$path = $this->getResultPathForConstraintId($constraintId);
280
+		if ($constraintParameterExceptions === null) {
281 281
 			$result->addValue(
282 282
 				$path,
283 283
 				self::KEY_STATUS,
@@ -287,12 +287,12 @@  discard block
 block discarded – undo
287 287
 			$result->addValue(
288 288
 				$path,
289 289
 				self::KEY_STATUS,
290
-				empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
290
+				empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
291 291
 			);
292 292
 			$result->addValue(
293 293
 				$path,
294 294
 				self::KEY_PROBLEMS,
295
-				array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions )
295
+				array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions)
296 296
 			);
297 297
 		}
298 298
 	}
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	 * @param ConstraintParameterException $e
304 304
 	 * @return string[]
305 305
 	 */
306
-	private function formatConstraintParameterException( ConstraintParameterException $e ) {
306
+	private function formatConstraintParameterException(ConstraintParameterException $e) {
307 307
 		return [
308 308
 			self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render(
309 309
 				$e->getViolationMessage()
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -79,19 +79,19 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @return self
81 81
 	 */
82
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
82
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
83 83
 		$repo = WikibaseRepo::getDefaultInstance();
84 84
 
85 85
 		$language = $repo->getUserLanguage();
86 86
 		$formatterOptions = new FormatterOptions();
87
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
87
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
88 88
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
89
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
89
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
90 90
 
91 91
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
92
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language );
92
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language);
93 93
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
94
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language );
94
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language);
95 95
 		$config = MediaWikiServices::getInstance()->getMainConfig();
96 96
 		$dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory();
97 97
 		$constraintReportFactory = ConstraintReportFactory::getDefaultInstance();
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 			$prefix,
115 115
 			$repo->getEntityIdParser(),
116 116
 			$repo->getStatementGuidValidator(),
117
-			$repo->getApiHelperFactory( RequestContext::getMain() ),
117
+			$repo->getApiHelperFactory(RequestContext::getMain()),
118 118
 			$resultsSource,
119 119
 			$checkResultsRenderer,
120 120
 			$dataFactory
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 		CheckResultsRenderer $checkResultsRenderer,
144 144
 		IBufferingStatsdDataFactory $dataFactory
145 145
 	) {
146
-		parent::__construct( $main, $name, $prefix );
146
+		parent::__construct($main, $name, $prefix);
147 147
 		$this->entityIdParser = $entityIdParser;
148 148
 		$this->statementGuidValidator = $statementGuidValidator;
149
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
150
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
149
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
150
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
151 151
 		$this->resultsSource = $resultsSource;
152 152
 		$this->checkResultsRenderer = $checkResultsRenderer;
153 153
 		$this->dataFactory = $dataFactory;
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 
164 164
 		$params = $this->extractRequestParams();
165 165
 
166
-		$this->validateParameters( $params );
167
-		$entityIds = $this->parseEntityIds( $params );
168
-		$claimIds = $this->parseClaimIds( $params );
166
+		$this->validateParameters($params);
167
+		$entityIds = $this->parseEntityIds($params);
168
+		$claimIds = $this->parseClaimIds($params);
169 169
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
170 170
 		$statuses = $params[self::PARAM_STATUS];
171 171
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 				)
182 182
 			)->getArray()
183 183
 		);
184
-		$this->resultBuilder->markSuccess( 1 );
184
+		$this->resultBuilder->markSuccess(1);
185 185
 	}
186 186
 
187 187
 	/**
@@ -189,24 +189,24 @@  discard block
 block discarded – undo
189 189
 	 *
190 190
 	 * @return EntityId[]
191 191
 	 */
192
-	private function parseEntityIds( array $params ) {
192
+	private function parseEntityIds(array $params) {
193 193
 		$ids = $params[self::PARAM_ID];
194 194
 
195
-		if ( $ids === null ) {
195
+		if ($ids === null) {
196 196
 			return [];
197
-		} elseif ( $ids === [] ) {
197
+		} elseif ($ids === []) {
198 198
 			$this->errorReporter->dieError(
199
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
199
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
200 200
 		}
201 201
 
202
-		return array_map( function ( $id ) {
202
+		return array_map(function($id) {
203 203
 			try {
204
-				return $this->entityIdParser->parse( $id );
205
-			} catch ( EntityIdParsingException $e ) {
204
+				return $this->entityIdParser->parse($id);
205
+			} catch (EntityIdParsingException $e) {
206 206
 				$this->errorReporter->dieError(
207
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
207
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
208 208
 			}
209
-		}, $ids );
209
+		}, $ids);
210 210
 	}
211 211
 
212 212
 	/**
@@ -214,35 +214,35 @@  discard block
 block discarded – undo
214 214
 	 *
215 215
 	 * @return string[]
216 216
 	 */
217
-	private function parseClaimIds( array $params ) {
217
+	private function parseClaimIds(array $params) {
218 218
 		$ids = $params[self::PARAM_CLAIM_ID];
219 219
 
220
-		if ( $ids === null ) {
220
+		if ($ids === null) {
221 221
 			return [];
222
-		} elseif ( $ids === [] ) {
222
+		} elseif ($ids === []) {
223 223
 			$this->errorReporter->dieError(
224
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
224
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
225 225
 		}
226 226
 
227
-		foreach ( $ids as $id ) {
228
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
227
+		foreach ($ids as $id) {
228
+			if (!$this->statementGuidValidator->validate($id)) {
229 229
 				$this->errorReporter->dieError(
230
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
230
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
231 231
 			}
232 232
 		}
233 233
 
234 234
 		return $ids;
235 235
 	}
236 236
 
237
-	private function validateParameters( array $params ) {
238
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
239
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
237
+	private function validateParameters(array $params) {
238
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
239
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
240 240
 		) {
241 241
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
242 242
 			$this->errorReporter->dieError(
243 243
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
244 244
 		}
245
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
245
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
246 246
 			$paramId = self::PARAM_ID;
247 247
 			$paramClaimId = self::PARAM_CLAIM_ID;
248 248
 			$this->errorReporter->dieError(
@@ -282,11 +282,11 @@  discard block
 block discarded – undo
282 282
 				],
283 283
 				ApiBase::PARAM_ISMULTI => true,
284 284
 				ApiBase::PARAM_ALL => true,
285
-				ApiBase::PARAM_DFLT => implode( '|', [
285
+				ApiBase::PARAM_DFLT => implode('|', [
286 286
 					CheckResult::STATUS_VIOLATION,
287 287
 					CheckResult::STATUS_WARNING,
288 288
 					CheckResult::STATUS_BAD_PARAMETERS,
289
-				] ),
289
+				]),
290 290
 				ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
291 291
 			],
292 292
 		];
Please login to merge, or discard this patch.