Completed
Push — master ( 8e6d16...f06835 )
by
unknown
41s
created
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		Config $config,
127 127
 		IBufferingStatsdDataFactory $dataFactory
128 128
 	) {
129
-		parent::__construct( 'ConstraintReport' );
129
+		parent::__construct('ConstraintReport');
130 130
 
131 131
 		$this->entityLookup = $entityLookup;
132 132
 		$this->entityTitleLookup = $entityTitleLookup;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		$language = $this->getLanguage();
136 136
 
137 137
 		$formatterOptions = new FormatterOptions();
138
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
138
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
139 139
 		$dataValueFormatter = $valueFormatterFactory->getValueFormatter(
140 140
 			SnakFormatter::FORMAT_HTML,
141 141
 			$formatterOptions
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @return string
196 196
 	 */
197 197
 	public function getDescription() {
198
-		return $this->msg( 'wbqc-constraintreport' )->text();
198
+		return $this->msg('wbqc-constraintreport')->text();
199 199
 	}
200 200
 
201 201
 	/**
@@ -207,43 +207,43 @@  discard block
 block discarded – undo
207 207
 	 * @throws EntityIdParsingException
208 208
 	 * @throws UnexpectedValueException
209 209
 	 */
210
-	public function execute( $subPage ) {
210
+	public function execute($subPage) {
211 211
 		$out = $this->getOutput();
212 212
 
213
-		$postRequest = $this->getContext()->getRequest()->getVal( 'entityid' );
214
-		if ( $postRequest ) {
215
-			$out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() );
213
+		$postRequest = $this->getContext()->getRequest()->getVal('entityid');
214
+		if ($postRequest) {
215
+			$out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL());
216 216
 			return;
217 217
 		}
218 218
 
219 219
 		$out->enableOOUI();
220
-		$out->addModules( $this->getModules() );
220
+		$out->addModules($this->getModules());
221 221
 
222 222
 		$this->setHeaders();
223 223
 
224
-		$out->addHTML( $this->getExplanationText() );
224
+		$out->addHTML($this->getExplanationText());
225 225
 		$this->buildEntityIdForm();
226 226
 
227
-		if ( !$subPage ) {
227
+		if (!$subPage) {
228 228
 			return;
229 229
 		}
230 230
 
231
-		if ( !is_string( $subPage ) ) {
232
-			throw new InvalidArgumentException( '$subPage must be string.' );
231
+		if (!is_string($subPage)) {
232
+			throw new InvalidArgumentException('$subPage must be string.');
233 233
 		}
234 234
 
235 235
 		try {
236
-			$entityId = $this->entityIdParser->parse( $subPage );
237
-		} catch ( EntityIdParsingException $e ) {
236
+			$entityId = $this->entityIdParser->parse($subPage);
237
+		} catch (EntityIdParsingException $e) {
238 238
 			$out->addHTML(
239
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
239
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
240 240
 			);
241 241
 			return;
242 242
 		}
243 243
 
244
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
244
+		if (!$this->entityLookup->hasEntity($entityId)) {
245 245
 			$out->addHTML(
246
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
246
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
247 247
 			);
248 248
 			return;
249 249
 		}
@@ -251,18 +251,18 @@  discard block
 block discarded – undo
251 251
 		$this->dataFactory->increment(
252 252
 			'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck'
253 253
 		);
254
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
254
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
255 255
 
256
-		if ( $results !== [] ) {
256
+		if ($results !== []) {
257 257
 			$out->addHTML(
258
-				$this->buildResultHeader( $entityId )
259
-				. $this->buildSummary( $results )
260
-				. $this->buildResultTable( $entityId, $results )
258
+				$this->buildResultHeader($entityId)
259
+				. $this->buildSummary($results)
260
+				. $this->buildResultTable($entityId, $results)
261 261
 			);
262 262
 		} else {
263 263
 			$out->addHTML(
264
-				$this->buildResultHeader( $entityId )
265
-				. $this->buildNotice( 'wbqc-constraintreport-empty-result' )
264
+				$this->buildResultHeader($entityId)
265
+				. $this->buildNotice('wbqc-constraintreport-empty-result')
266 266
 			);
267 267
 		}
268 268
 	}
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
 				'name' => 'entityid',
279 279
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
280 280
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
281
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped()
281
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped()
282 282
 			]
283 283
 		];
284
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' );
285
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() );
286
-		$htmlForm->setSubmitCallback( static function () {
284
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form');
285
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped());
286
+		$htmlForm->setSubmitCallback(static function() {
287 287
 			return false;
288 288
 		} );
289
-		$htmlForm->setMethod( 'post' );
289
+		$htmlForm->setMethod('post');
290 290
 		$htmlForm->show();
291 291
 	}
292 292
 
@@ -300,16 +300,16 @@  discard block
 block discarded – undo
300 300
 	 *
301 301
 	 * @return string HTML
302 302
 	 */
303
-	private function buildNotice( $messageKey, $error = false ) {
304
-		if ( !is_string( $messageKey ) ) {
305
-			throw new InvalidArgumentException( '$message must be string.' );
303
+	private function buildNotice($messageKey, $error = false) {
304
+		if (!is_string($messageKey)) {
305
+			throw new InvalidArgumentException('$message must be string.');
306 306
 		}
307
-		if ( !is_bool( $error ) ) {
308
-			throw new InvalidArgumentException( '$error must be bool.' );
307
+		if (!is_bool($error)) {
308
+			throw new InvalidArgumentException('$error must be bool.');
309 309
 		}
310 310
 
311 311
 		$cssClasses = 'wbqc-constraintreport-notice';
312
-		if ( $error ) {
312
+		if ($error) {
313 313
 			$cssClasses .= ' wbqc-constraintreport-notice-error';
314 314
 		}
315 315
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 				[
319 319
 					'class' => $cssClasses
320 320
 				],
321
-				$this->msg( $messageKey )->escaped()
321
+				$this->msg($messageKey)->escaped()
322 322
 			);
323 323
 	}
324 324
 
@@ -328,16 +328,16 @@  discard block
 block discarded – undo
328 328
 	private function getExplanationText() {
329 329
 		return Html::rawElement(
330 330
 			'div',
331
-			[ 'class' => 'wbqc-explanation' ],
331
+			['class' => 'wbqc-explanation'],
332 332
 			Html::rawElement(
333 333
 				'p',
334 334
 				[],
335
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped()
335
+				$this->msg('wbqc-constraintreport-explanation-part-one')->escaped()
336 336
 			)
337 337
 			. Html::rawElement(
338 338
 				'p',
339 339
 				[],
340
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped()
340
+				$this->msg('wbqc-constraintreport-explanation-part-two')->escaped()
341 341
 			)
342 342
 		);
343 343
 	}
@@ -349,72 +349,72 @@  discard block
 block discarded – undo
349 349
 	 * @return string HTML
350 350
 	 * @suppress SecurityCheck-DoubleEscaped
351 351
 	 */
352
-	private function buildResultTable( EntityId $entityId, array $results ) {
352
+	private function buildResultTable(EntityId $entityId, array $results) {
353 353
 		// Set table headers
354 354
 		$table = new HtmlTableBuilder(
355 355
 			[
356 356
 				new HtmlTableHeaderBuilder(
357
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(),
357
+					$this->msg('wbqc-constraintreport-result-table-header-status')->escaped(),
358 358
 					true
359 359
 				),
360 360
 				new HtmlTableHeaderBuilder(
361
-					$this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(),
361
+					$this->msg('wbqc-constraintreport-result-table-header-property')->escaped(),
362 362
 					true
363 363
 				),
364 364
 				new HtmlTableHeaderBuilder(
365
-					$this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(),
365
+					$this->msg('wbqc-constraintreport-result-table-header-message')->escaped(),
366 366
 					true
367 367
 				),
368 368
 				new HtmlTableHeaderBuilder(
369
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(),
369
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(),
370 370
 					true
371 371
 				)
372 372
 			]
373 373
 		);
374 374
 
375
-		foreach ( $results as $result ) {
376
-			$table = $this->appendToResultTable( $table, $entityId, $result );
375
+		foreach ($results as $result) {
376
+			$table = $this->appendToResultTable($table, $entityId, $result);
377 377
 		}
378 378
 
379 379
 		return $table->toHtml();
380 380
 	}
381 381
 
382
-	private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) {
382
+	private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) {
383 383
 		$message = $result->getMessage();
384
-		if ( $message === null ) {
384
+		if ($message === null) {
385 385
 			// no row for this result
386 386
 			return $table;
387 387
 		}
388 388
 
389 389
 		// Status column
390
-		$statusColumn = $this->formatStatus( $result->getStatus() );
390
+		$statusColumn = $this->formatStatus($result->getStatus());
391 391
 
392 392
 		// Property column
393
-		$propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() );
393
+		$propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId());
394 394
 		$propertyColumn = $this->getClaimLink(
395 395
 			$entityId,
396 396
 			$propertyId,
397
-			$this->entityIdLabelFormatter->formatEntityId( $propertyId )
397
+			$this->entityIdLabelFormatter->formatEntityId($propertyId)
398 398
 		);
399 399
 
400 400
 		// Message column
401
-		$messageColumn = $this->violationMessageRenderer->render( $message );
401
+		$messageColumn = $this->violationMessageRenderer->render($message);
402 402
 
403 403
 		// Constraint column
404 404
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
405 405
 		try {
406
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
407
-		} catch ( InvalidArgumentException $e ) {
408
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
406
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
407
+		} catch (InvalidArgumentException $e) {
408
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
409 409
 		}
410 410
 		$constraintLink = $this->getClaimLink(
411 411
 			$propertyId,
412
-			new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
412
+			new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
413 413
 			$constraintTypeLabel
414 414
 		);
415 415
 		$constraintColumn = $this->buildExpandableElement(
416 416
 			$constraintLink,
417
-			$this->constraintParameterRenderer->formatParameters( $result->getParameters() ),
417
+			$this->constraintParameterRenderer->formatParameters($result->getParameters()),
418 418
 			'[...]'
419 419
 		);
420 420
 
@@ -454,15 +454,15 @@  discard block
 block discarded – undo
454 454
 	 *
455 455
 	 * @return string HTML
456 456
 	 */
457
-	protected function buildResultHeader( EntityId $entityId ) {
458
-		$entityLink = sprintf( '%s (%s)',
459
-							   $this->entityIdLinkFormatter->formatEntityId( $entityId ),
460
-							   htmlspecialchars( $entityId->getSerialization() ) );
457
+	protected function buildResultHeader(EntityId $entityId) {
458
+		$entityLink = sprintf('%s (%s)',
459
+							   $this->entityIdLinkFormatter->formatEntityId($entityId),
460
+							   htmlspecialchars($entityId->getSerialization()));
461 461
 
462 462
 		return Html::rawElement(
463 463
 			'h3',
464 464
 			[],
465
-			sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink )
465
+			sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink)
466 466
 		);
467 467
 	}
468 468
 
@@ -473,24 +473,24 @@  discard block
 block discarded – undo
473 473
 	 *
474 474
 	 * @return string HTML
475 475
 	 */
476
-	protected function buildSummary( array $results ) {
476
+	protected function buildSummary(array $results) {
477 477
 		$statuses = [];
478
-		foreach ( $results as $result ) {
479
-			$status = strtolower( $result->getStatus() );
480
-			$statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1;
478
+		foreach ($results as $result) {
479
+			$status = strtolower($result->getStatus());
480
+			$statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1;
481 481
 		}
482 482
 
483 483
 		$statusElements = [];
484
-		foreach ( $statuses as $status => $count ) {
485
-			if ( $count > 0 ) {
484
+		foreach ($statuses as $status => $count) {
485
+			if ($count > 0) {
486 486
 				$statusElements[] =
487
-					$this->formatStatus( $status )
487
+					$this->formatStatus($status)
488 488
 					. ': '
489 489
 					. $count;
490 490
 			}
491 491
 		}
492 492
 
493
-		return Html::rawElement( 'p', [], implode( ', ', $statusElements ) );
493
+		return Html::rawElement('p', [], implode(', ', $statusElements));
494 494
 	}
495 495
 
496 496
 	/**
@@ -505,15 +505,15 @@  discard block
 block discarded – undo
505 505
 	 *
506 506
 	 * @return string HTML
507 507
 	 */
508
-	protected function buildExpandableElement( $content, $expandableContent, $indicator ) {
509
-		if ( !is_string( $content ) ) {
510
-			throw new InvalidArgumentException( '$content has to be string.' );
508
+	protected function buildExpandableElement($content, $expandableContent, $indicator) {
509
+		if (!is_string($content)) {
510
+			throw new InvalidArgumentException('$content has to be string.');
511 511
 		}
512
-		if ( $expandableContent && ( !is_string( $expandableContent ) ) ) {
513
-			throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' );
512
+		if ($expandableContent && (!is_string($expandableContent))) {
513
+			throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.');
514 514
 		}
515 515
 
516
-		if ( empty( $expandableContent ) ) {
516
+		if (empty($expandableContent)) {
517 517
 			return $content;
518 518
 		}
519 519
 
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 			$expandableContent
534 534
 		);
535 535
 
536
-		return sprintf( '%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent );
536
+		return sprintf('%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent);
537 537
 	}
538 538
 
539 539
 	/**
@@ -545,8 +545,8 @@  discard block
 block discarded – undo
545 545
 	 *
546 546
 	 * @return string HTML
547 547
 	 */
548
-	private function formatStatus( $status ) {
549
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
548
+	private function formatStatus($status) {
549
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
550 550
 		$statusIcons = [
551 551
 			CheckResult::STATUS_SUGGESTION => [
552 552
 				'icon' => 'suggestion-constraint-violation',
@@ -563,25 +563,25 @@  discard block
 block discarded – undo
563 563
 			],
564 564
 		];
565 565
 
566
-		if ( array_key_exists( $status, $statusIcons ) ) {
567
-			$iconWidget = new IconWidget( $statusIcons[$status] );
568
-			$iconHtml = $iconWidget->toString() . ' ';
566
+		if (array_key_exists($status, $statusIcons)) {
567
+			$iconWidget = new IconWidget($statusIcons[$status]);
568
+			$iconHtml = $iconWidget->toString().' ';
569 569
 		} else {
570 570
 			$iconHtml = '';
571 571
 		}
572 572
 
573
-		$labelWidget = new LabelWidget( [
574
-			'label' => $this->msg( $messageName )->text(),
575
-		] );
573
+		$labelWidget = new LabelWidget([
574
+			'label' => $this->msg($messageName)->text(),
575
+		]);
576 576
 		$labelHtml = $labelWidget->toString();
577 577
 
578 578
 		$formattedStatus =
579 579
 			Html::rawElement(
580 580
 				'span',
581 581
 				[
582
-					'class' => 'wbqc-status wbqc-status-' . $status
582
+					'class' => 'wbqc-status wbqc-status-'.$status
583 583
 				],
584
-				$iconHtml . $labelHtml
584
+				$iconHtml.$labelHtml
585 585
 			);
586 586
 
587 587
 		return $formattedStatus;
@@ -596,11 +596,11 @@  discard block
 block discarded – undo
596 596
 	 *
597 597
 	 * @return string HTML
598 598
 	 */
599
-	private function getClaimLink( EntityId $entityId, NumericPropertyId $propertyId, $text ) {
599
+	private function getClaimLink(EntityId $entityId, NumericPropertyId $propertyId, $text) {
600 600
 		return Html::rawElement(
601 601
 			'a',
602 602
 			[
603
-				'href' => $this->getClaimUrl( $entityId, $propertyId ),
603
+				'href' => $this->getClaimUrl($entityId, $propertyId),
604 604
 				'target' => '_blank'
605 605
 			],
606 606
 			$text
@@ -615,9 +615,9 @@  discard block
 block discarded – undo
615 615
 	 *
616 616
 	 * @return string
617 617
 	 */
618
-	private function getClaimUrl( EntityId $entityId, NumericPropertyId $propertyId ) {
619
-		$title = $this->entityTitleLookup->getTitleForId( $entityId );
620
-		$entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() );
618
+	private function getClaimUrl(EntityId $entityId, NumericPropertyId $propertyId) {
619
+		$title = $this->entityTitleLookup->getTitleForId($entityId);
620
+		$entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization());
621 621
 
622 622
 		return $entityUrl;
623 623
 	}
Please login to merge, or discard this patch.