Completed
Push — master ( 33611a...17dea9 )
by
unknown
39s queued 15s
created
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\Specials;
6 6
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 		Config $config,
92 92
 		StatsFactory $statsFactory
93 93
 	) {
94
-		parent::__construct( 'ConstraintReport' );
94
+		parent::__construct('ConstraintReport');
95 95
 
96 96
 		$this->entityLookup = $entityLookup;
97 97
 		$this->entityTitleLookup = $entityTitleLookup;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 
112 112
 		$this->violationMessageRenderer = $violationMessageRendererFactory->getViolationMessageRenderer(
113 113
 			$language,
114
-			$languageFallbackChainFactory->newFromLanguage( $language ),
114
+			$languageFallbackChainFactory->newFromLanguage($language),
115 115
 			$this->getContext()
116 116
 		);
117 117
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @inheritDoc
146 146
 	 */
147 147
 	public function getDescription() {
148
-		return $this->msg( 'wbqc-constraintreport' );
148
+		return $this->msg('wbqc-constraintreport');
149 149
 	}
150 150
 
151 151
 	/**
@@ -157,75 +157,75 @@  discard block
 block discarded – undo
157 157
 	 * @throws EntityIdParsingException
158 158
 	 * @throws UnexpectedValueException
159 159
 	 */
160
-	public function execute( $subPage ) {
160
+	public function execute($subPage) {
161 161
 		$out = $this->getOutput();
162 162
 
163
-		$postRequest = $this->getContext()->getRequest()->getVal( 'entityid' );
164
-		if ( $postRequest ) {
163
+		$postRequest = $this->getContext()->getRequest()->getVal('entityid');
164
+		if ($postRequest) {
165 165
 			try {
166
-				$entityId = $this->entityIdParser->parse( $postRequest );
167
-				$out->redirect( $this->getPageTitle( $entityId->getSerialization() )->getLocalURL() );
166
+				$entityId = $this->entityIdParser->parse($postRequest);
167
+				$out->redirect($this->getPageTitle($entityId->getSerialization())->getLocalURL());
168 168
 				return;
169
-			} catch ( EntityIdParsingException $e ) {
169
+			} catch (EntityIdParsingException $e) {
170 170
 				// fall through, error is shown later
171 171
 			}
172 172
 		}
173 173
 
174 174
 		$out->enableOOUI();
175
-		$out->addModules( $this->getModules() );
175
+		$out->addModules($this->getModules());
176 176
 
177 177
 		$this->setHeaders();
178 178
 
179
-		$out->addHTML( $this->getExplanationText() );
179
+		$out->addHTML($this->getExplanationText());
180 180
 		$this->buildEntityIdForm();
181 181
 
182
-		if ( $postRequest ) {
182
+		if ($postRequest) {
183 183
 			// must be an invalid entity ID (otherwise we would have redirected and returned above)
184 184
 			$out->addHTML(
185
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
185
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
186 186
 			);
187 187
 			return;
188 188
 		}
189 189
 
190
-		if ( !$subPage ) {
190
+		if (!$subPage) {
191 191
 			return;
192 192
 		}
193 193
 
194
-		if ( !is_string( $subPage ) ) {
195
-			throw new InvalidArgumentException( '$subPage must be string.' );
194
+		if (!is_string($subPage)) {
195
+			throw new InvalidArgumentException('$subPage must be string.');
196 196
 		}
197 197
 
198 198
 		try {
199
-			$entityId = $this->entityIdParser->parse( $subPage );
200
-		} catch ( EntityIdParsingException $e ) {
199
+			$entityId = $this->entityIdParser->parse($subPage);
200
+		} catch (EntityIdParsingException $e) {
201 201
 			$out->addHTML(
202
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
202
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
203 203
 			);
204 204
 			return;
205 205
 		}
206 206
 
207
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
207
+		if (!$this->entityLookup->hasEntity($entityId)) {
208 208
 			$out->addHTML(
209
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
209
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
210 210
 			);
211 211
 			return;
212 212
 		}
213 213
 
214 214
 		$baseKey = 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck';
215
-		$metric = $this->statsFactory->getCounter( 'special_constraint_report_execute_check_total' );
216
-		$metric->copyToStatsdAt( $baseKey )->increment();
217
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
215
+		$metric = $this->statsFactory->getCounter('special_constraint_report_execute_check_total');
216
+		$metric->copyToStatsdAt($baseKey)->increment();
217
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
218 218
 
219
-		if ( $results !== [] ) {
219
+		if ($results !== []) {
220 220
 			$out->addHTML(
221
-				$this->buildResultHeader( $entityId )
222
-				. $this->buildSummary( $results )
223
-				. $this->buildResultTable( $entityId, $results )
221
+				$this->buildResultHeader($entityId)
222
+				. $this->buildSummary($results)
223
+				. $this->buildResultTable($entityId, $results)
224 224
 			);
225 225
 		} else {
226 226
 			$out->addHTML(
227
-				$this->buildResultHeader( $entityId )
228
-				. $this->buildNotice( 'wbqc-constraintreport-empty-result' )
227
+				$this->buildResultHeader($entityId)
228
+				. $this->buildNotice('wbqc-constraintreport-empty-result')
229 229
 			);
230 230
 		}
231 231
 	}
@@ -241,16 +241,16 @@  discard block
 block discarded – undo
241 241
 				'name' => 'entityid',
242 242
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
243 243
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
244
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped(),
244
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped(),
245 245
 				'required' => true,
246 246
 			],
247 247
 		];
248
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' );
249
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() );
250
-		$htmlForm->setSubmitCallback( static function () {
248
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form');
249
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped());
250
+		$htmlForm->setSubmitCallback(static function() {
251 251
 			return false;
252 252
 		} );
253
-		$htmlForm->setMethod( 'post' );
253
+		$htmlForm->setMethod('post');
254 254
 		$htmlForm->show();
255 255
 	}
256 256
 
@@ -264,9 +264,9 @@  discard block
 block discarded – undo
264 264
 	 *
265 265
 	 * @return string HTML
266 266
 	 */
267
-	private function buildNotice( string $messageKey, bool $error = false ): string {
267
+	private function buildNotice(string $messageKey, bool $error = false): string {
268 268
 		$cssClasses = 'wbqc-constraintreport-notice';
269
-		if ( $error ) {
269
+		if ($error) {
270 270
 			$cssClasses .= ' wbqc-constraintreport-notice-error';
271 271
 		}
272 272
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 				[
276 276
 					'class' => $cssClasses,
277 277
 				],
278
-				$this->msg( $messageKey )->escaped()
278
+				$this->msg($messageKey)->escaped()
279 279
 			);
280 280
 	}
281 281
 
@@ -285,16 +285,16 @@  discard block
 block discarded – undo
285 285
 	private function getExplanationText(): string {
286 286
 		return Html::rawElement(
287 287
 			'div',
288
-			[ 'class' => 'wbqc-explanation' ],
288
+			['class' => 'wbqc-explanation'],
289 289
 			Html::rawElement(
290 290
 				'p',
291 291
 				[],
292
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped()
292
+				$this->msg('wbqc-constraintreport-explanation-part-one')->escaped()
293 293
 			)
294 294
 			. Html::rawElement(
295 295
 				'p',
296 296
 				[],
297
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped()
297
+				$this->msg('wbqc-constraintreport-explanation-part-two')->escaped()
298 298
 			)
299 299
 		);
300 300
 	}
@@ -305,31 +305,31 @@  discard block
 block discarded – undo
305 305
 	 *
306 306
 	 * @return string HTML
307 307
 	 */
308
-	private function buildResultTable( EntityId $entityId, array $results ): string {
308
+	private function buildResultTable(EntityId $entityId, array $results): string {
309 309
 		// Set table headers
310 310
 		$table = new HtmlTableBuilder(
311 311
 			[
312 312
 				new HtmlTableHeaderBuilder(
313
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->text(),
313
+					$this->msg('wbqc-constraintreport-result-table-header-status')->text(),
314 314
 					true
315 315
 				),
316 316
 				new HtmlTableHeaderBuilder(
317
-					$this->msg( 'wbqc-constraintreport-result-table-header-property' )->text(),
317
+					$this->msg('wbqc-constraintreport-result-table-header-property')->text(),
318 318
 					true
319 319
 				),
320 320
 				new HtmlTableHeaderBuilder(
321
-					$this->msg( 'wbqc-constraintreport-result-table-header-message' )->text(),
321
+					$this->msg('wbqc-constraintreport-result-table-header-message')->text(),
322 322
 					true
323 323
 				),
324 324
 				new HtmlTableHeaderBuilder(
325
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->text(),
325
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->text(),
326 326
 					true
327 327
 				),
328 328
 			]
329 329
 		);
330 330
 
331
-		foreach ( $results as $result ) {
332
-			$table = $this->appendToResultTable( $table, $entityId, $result );
331
+		foreach ($results as $result) {
332
+			$table = $this->appendToResultTable($table, $entityId, $result);
333 333
 		}
334 334
 
335 335
 		return $table->toHtml();
@@ -341,35 +341,35 @@  discard block
 block discarded – undo
341 341
 		CheckResult $result
342 342
 	): HtmlTableBuilder {
343 343
 		$message = $result->getMessage();
344
-		if ( $message === null ) {
344
+		if ($message === null) {
345 345
 			// no row for this result
346 346
 			return $table;
347 347
 		}
348 348
 
349 349
 		// Status column
350
-		$statusColumn = $this->formatStatus( $result->getStatus() );
350
+		$statusColumn = $this->formatStatus($result->getStatus());
351 351
 
352 352
 		// Property column
353
-		$propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() );
353
+		$propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId());
354 354
 		$propertyColumn = $this->getClaimLink(
355 355
 			$entityId,
356 356
 			$propertyId,
357
-			$this->entityIdLabelFormatter->formatEntityId( $propertyId )
357
+			$this->entityIdLabelFormatter->formatEntityId($propertyId)
358 358
 		);
359 359
 
360 360
 		// Message column
361
-		$messageColumn = $this->violationMessageRenderer->render( $message );
361
+		$messageColumn = $this->violationMessageRenderer->render($message);
362 362
 
363 363
 		// Constraint column
364 364
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
365 365
 		try {
366
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
367
-		} catch ( InvalidArgumentException $e ) {
368
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
366
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
367
+		} catch (InvalidArgumentException $e) {
368
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
369 369
 		}
370 370
 		$constraintColumn = $this->getClaimLink(
371 371
 			$propertyId,
372
-			new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
372
+			new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
373 373
 			$constraintTypeLabel
374 374
 		);
375 375
 
@@ -377,16 +377,16 @@  discard block
 block discarded – undo
377 377
 		$table->appendRow(
378 378
 			[
379 379
 				new HtmlTableCellBuilder(
380
-					new HtmlArmor( $statusColumn )
380
+					new HtmlArmor($statusColumn)
381 381
 				),
382 382
 				new HtmlTableCellBuilder(
383
-					new HtmlArmor( $propertyColumn )
383
+					new HtmlArmor($propertyColumn)
384 384
 				),
385 385
 				new HtmlTableCellBuilder(
386
-					new HtmlArmor( $messageColumn )
386
+					new HtmlArmor($messageColumn)
387 387
 				),
388 388
 				new HtmlTableCellBuilder(
389
-					new HtmlArmor( $constraintColumn )
389
+					new HtmlArmor($constraintColumn)
390 390
 				),
391 391
 			]
392 392
 		);
@@ -401,15 +401,15 @@  discard block
 block discarded – undo
401 401
 	 *
402 402
 	 * @return string HTML
403 403
 	 */
404
-	protected function buildResultHeader( EntityId $entityId ): string {
405
-		$entityLink = sprintf( '%s (%s)',
406
-							   $this->entityIdLinkFormatter->formatEntityId( $entityId ),
407
-							   htmlspecialchars( $entityId->getSerialization() ) );
404
+	protected function buildResultHeader(EntityId $entityId): string {
405
+		$entityLink = sprintf('%s (%s)',
406
+							   $this->entityIdLinkFormatter->formatEntityId($entityId),
407
+							   htmlspecialchars($entityId->getSerialization()));
408 408
 
409 409
 		return Html::rawElement(
410 410
 			'h3',
411 411
 			[],
412
-			sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink )
412
+			sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink)
413 413
 		);
414 414
 	}
415 415
 
@@ -420,24 +420,24 @@  discard block
 block discarded – undo
420 420
 	 *
421 421
 	 * @return string HTML
422 422
 	 */
423
-	protected function buildSummary( array $results ): string {
423
+	protected function buildSummary(array $results): string {
424 424
 		$statuses = [];
425
-		foreach ( $results as $result ) {
426
-			$status = strtolower( $result->getStatus() );
427
-			$statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1;
425
+		foreach ($results as $result) {
426
+			$status = strtolower($result->getStatus());
427
+			$statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1;
428 428
 		}
429 429
 
430 430
 		$statusElements = [];
431
-		foreach ( $statuses as $status => $count ) {
432
-			if ( $count > 0 ) {
431
+		foreach ($statuses as $status => $count) {
432
+			if ($count > 0) {
433 433
 				$statusElements[] =
434
-					$this->formatStatus( $status )
434
+					$this->formatStatus($status)
435 435
 					. ': '
436 436
 					. $count;
437 437
 			}
438 438
 		}
439 439
 
440
-		return Html::rawElement( 'p', [], implode( ', ', $statusElements ) );
440
+		return Html::rawElement('p', [], implode(', ', $statusElements));
441 441
 	}
442 442
 
443 443
 	/**
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	 *
450 450
 	 * @return string HTML
451 451
 	 */
452
-	private function formatStatus( string $status ): string {
453
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
452
+	private function formatStatus(string $status): string {
453
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
454 454
 		$statusIcons = [
455 455
 			CheckResult::STATUS_SUGGESTION => [
456 456
 				'icon' => 'suggestion-constraint-violation',
@@ -467,25 +467,25 @@  discard block
 block discarded – undo
467 467
 			],
468 468
 		];
469 469
 
470
-		if ( array_key_exists( $status, $statusIcons ) ) {
471
-			$iconWidget = new IconWidget( $statusIcons[$status] );
472
-			$iconHtml = $iconWidget->toString() . ' ';
470
+		if (array_key_exists($status, $statusIcons)) {
471
+			$iconWidget = new IconWidget($statusIcons[$status]);
472
+			$iconHtml = $iconWidget->toString().' ';
473 473
 		} else {
474 474
 			$iconHtml = '';
475 475
 		}
476 476
 
477
-		$labelWidget = new LabelWidget( [
478
-			'label' => $this->msg( $messageName )->text(),
479
-		] );
477
+		$labelWidget = new LabelWidget([
478
+			'label' => $this->msg($messageName)->text(),
479
+		]);
480 480
 		$labelHtml = $labelWidget->toString();
481 481
 
482 482
 		$formattedStatus =
483 483
 			Html::rawElement(
484 484
 				'span',
485 485
 				[
486
-					'class' => 'wbqc-status wbqc-status-' . $status,
486
+					'class' => 'wbqc-status wbqc-status-'.$status,
487 487
 				],
488
-				$iconHtml . $labelHtml
488
+				$iconHtml.$labelHtml
489 489
 			);
490 490
 
491 491
 		return $formattedStatus;
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 		return Html::rawElement(
509 509
 			'a',
510 510
 			[
511
-				'href' => $this->getClaimUrl( $entityId, $propertyId ),
511
+				'href' => $this->getClaimUrl($entityId, $propertyId),
512 512
 				'target' => '_blank',
513 513
 			],
514 514
 			$text
@@ -522,8 +522,8 @@  discard block
 block discarded – undo
522 522
 		EntityId $entityId,
523 523
 		NumericPropertyId $propertyId
524 524
 	): string {
525
-		$title = $this->entityTitleLookup->getTitleForId( $entityId );
526
-		$entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() );
525
+		$title = $this->entityTitleLookup->getTitleForId($entityId);
526
+		$entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization());
527 527
 
528 528
 		return $entityUrl;
529 529
 	}
Please login to merge, or discard this patch.