Completed
Push — master ( 1095ca...14d27f )
by
unknown
22s
created
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +87 added lines, -87 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,72 +157,72 @@  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 ) {
169
+			} catch (EntityIdParsingException) {
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 194
 		try {
195
-			$entityId = $this->entityIdParser->parse( $subPage );
196
-		} catch ( EntityIdParsingException ) {
195
+			$entityId = $this->entityIdParser->parse($subPage);
196
+		} catch (EntityIdParsingException) {
197 197
 			$out->addHTML(
198
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
198
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
199 199
 			);
200 200
 			return;
201 201
 		}
202 202
 
203
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
203
+		if (!$this->entityLookup->hasEntity($entityId)) {
204 204
 			$out->addHTML(
205
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
205
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
206 206
 			);
207 207
 			return;
208 208
 		}
209 209
 
210 210
 		$baseKey = 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck';
211
-		$metric = $this->statsFactory->getCounter( 'special_constraint_report_execute_check_total' );
212
-		$metric->copyToStatsdAt( $baseKey )->increment();
213
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
211
+		$metric = $this->statsFactory->getCounter('special_constraint_report_execute_check_total');
212
+		$metric->copyToStatsdAt($baseKey)->increment();
213
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
214 214
 
215
-		if ( !$results ) {
216
-			$out->addHTML( $this->buildResultHeader( $entityId ) .
217
-				$this->buildNotice( 'wbqc-constraintreport-empty-result' )
215
+		if (!$results) {
216
+			$out->addHTML($this->buildResultHeader($entityId).
217
+				$this->buildNotice('wbqc-constraintreport-empty-result')
218 218
 			);
219 219
 			return;
220 220
 		}
221 221
 
222 222
 		$out->addHTML(
223
-			$this->buildResultHeader( $entityId )
224
-			. $this->buildSummary( $results )
225
-			. $this->buildResultTable( $entityId, $results )
223
+			$this->buildResultHeader($entityId)
224
+			. $this->buildSummary($results)
225
+			. $this->buildResultTable($entityId, $results)
226 226
 		);
227 227
 	}
228 228
 
@@ -237,15 +237,15 @@  discard block
 block discarded – undo
237 237
 				'name' => 'entityid',
238 238
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
239 239
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
240
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->text(),
240
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->text(),
241 241
 				'required' => true,
242 242
 			],
243 243
 		];
244
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(),
244
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(),
245 245
 			'wbqc-constraintreport-form'
246 246
 		);
247
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->text() );
248
-		$htmlForm->setSubmitCallback( static fn () => false );
247
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->text());
248
+		$htmlForm->setSubmitCallback(static fn () => false);
249 249
 		$htmlForm->show();
250 250
 	}
251 251
 
@@ -259,16 +259,16 @@  discard block
 block discarded – undo
259 259
 	 *
260 260
 	 * @return string HTML
261 261
 	 */
262
-	private function buildNotice( string $messageKey, bool $error = false ): string {
263
-		$cssClasses = [ 'wbqc-constraintreport-notice' ];
264
-		if ( $error ) {
262
+	private function buildNotice(string $messageKey, bool $error = false): string {
263
+		$cssClasses = ['wbqc-constraintreport-notice'];
264
+		if ($error) {
265 265
 			$cssClasses[] = ' wbqc-constraintreport-notice-error';
266 266
 		}
267 267
 
268 268
 		return Html::element(
269 269
 			'p',
270
-			[ 'class' => $cssClasses ],
271
-			$this->msg( $messageKey )->text()
270
+			['class' => $cssClasses],
271
+			$this->msg($messageKey)->text()
272 272
 		);
273 273
 	}
274 274
 
@@ -278,16 +278,16 @@  discard block
 block discarded – undo
278 278
 	private function getExplanationText(): string {
279 279
 		return Html::rawElement(
280 280
 			'div',
281
-			[ 'class' => 'wbqc-explanation' ],
281
+			['class' => 'wbqc-explanation'],
282 282
 			Html::element(
283 283
 				'p',
284 284
 				[],
285
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->text()
285
+				$this->msg('wbqc-constraintreport-explanation-part-one')->text()
286 286
 			)
287 287
 			. Html::element(
288 288
 				'p',
289 289
 				[],
290
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->text()
290
+				$this->msg('wbqc-constraintreport-explanation-part-two')->text()
291 291
 			)
292 292
 		);
293 293
 	}
@@ -298,31 +298,31 @@  discard block
 block discarded – undo
298 298
 	 *
299 299
 	 * @return string HTML
300 300
 	 */
301
-	private function buildResultTable( EntityId $entityId, array $results ): string {
301
+	private function buildResultTable(EntityId $entityId, array $results): string {
302 302
 		// Set table headers
303 303
 		$table = new HtmlTableBuilder(
304 304
 			[
305 305
 				new HtmlTableHeaderBuilder(
306
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->text(),
306
+					$this->msg('wbqc-constraintreport-result-table-header-status')->text(),
307 307
 					true
308 308
 				),
309 309
 				new HtmlTableHeaderBuilder(
310
-					$this->msg( 'wbqc-constraintreport-result-table-header-property' )->text(),
310
+					$this->msg('wbqc-constraintreport-result-table-header-property')->text(),
311 311
 					true
312 312
 				),
313 313
 				new HtmlTableHeaderBuilder(
314
-					$this->msg( 'wbqc-constraintreport-result-table-header-message' )->text(),
314
+					$this->msg('wbqc-constraintreport-result-table-header-message')->text(),
315 315
 					true
316 316
 				),
317 317
 				new HtmlTableHeaderBuilder(
318
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->text(),
318
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->text(),
319 319
 					true
320 320
 				),
321 321
 			]
322 322
 		);
323 323
 
324
-		foreach ( $results as $result ) {
325
-			$this->appendToResultTable( $table, $entityId, $result );
324
+		foreach ($results as $result) {
325
+			$this->appendToResultTable($table, $entityId, $result);
326 326
 		}
327 327
 
328 328
 		return $table->toHtml();
@@ -334,35 +334,35 @@  discard block
 block discarded – undo
334 334
 		CheckResult $result
335 335
 	): void {
336 336
 		$message = $result->getMessage();
337
-		if ( !$message ) {
337
+		if (!$message) {
338 338
 			// no row for this result
339 339
 			return;
340 340
 		}
341 341
 
342 342
 		// Status column
343
-		$statusColumn = $this->formatStatus( $result->getStatus() );
343
+		$statusColumn = $this->formatStatus($result->getStatus());
344 344
 
345 345
 		// Property column
346
-		$propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() );
346
+		$propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId());
347 347
 		$propertyColumn = $this->getClaimLink(
348 348
 			$entityId,
349 349
 			$propertyId,
350
-			$this->entityIdLabelFormatter->formatEntityId( $propertyId )
350
+			$this->entityIdLabelFormatter->formatEntityId($propertyId)
351 351
 		);
352 352
 
353 353
 		// Message column
354
-		$messageColumn = $this->violationMessageRenderer->render( $message );
354
+		$messageColumn = $this->violationMessageRenderer->render($message);
355 355
 
356 356
 		// Constraint column
357 357
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
358 358
 		try {
359
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
360
-		} catch ( InvalidArgumentException ) {
361
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
359
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
360
+		} catch (InvalidArgumentException) {
361
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
362 362
 		}
363 363
 		$constraintColumn = $this->getClaimLink(
364 364
 			$propertyId,
365
-			new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
365
+			new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
366 366
 			$constraintTypeLabel
367 367
 		);
368 368
 
@@ -370,16 +370,16 @@  discard block
 block discarded – undo
370 370
 		$table->appendRow(
371 371
 			[
372 372
 				new HtmlTableCellBuilder(
373
-					new HtmlArmor( $statusColumn )
373
+					new HtmlArmor($statusColumn)
374 374
 				),
375 375
 				new HtmlTableCellBuilder(
376
-					new HtmlArmor( $propertyColumn )
376
+					new HtmlArmor($propertyColumn)
377 377
 				),
378 378
 				new HtmlTableCellBuilder(
379
-					new HtmlArmor( $messageColumn )
379
+					new HtmlArmor($messageColumn)
380 380
 				),
381 381
 				new HtmlTableCellBuilder(
382
-					new HtmlArmor( $constraintColumn )
382
+					new HtmlArmor($constraintColumn)
383 383
 				),
384 384
 			]
385 385
 		);
@@ -392,15 +392,15 @@  discard block
 block discarded – undo
392 392
 	 *
393 393
 	 * @return string HTML
394 394
 	 */
395
-	protected function buildResultHeader( EntityId $entityId ): string {
395
+	protected function buildResultHeader(EntityId $entityId): string {
396 396
 		return Html::rawElement(
397 397
 			'h3',
398 398
 			[],
399
-			$this->msg( 'wbqc-constraintreport-result-headline' )->escaped() .
400
-				$this->msg( 'word-separator' )->escaped() .
401
-				$this->entityIdLinkFormatter->formatEntityId( $entityId ) .
402
-				$this->msg( 'word-separator' )->escaped() .
403
-				$this->msg( 'parentheses', $entityId->getSerialization() )->escaped()
399
+			$this->msg('wbqc-constraintreport-result-headline')->escaped().
400
+				$this->msg('word-separator')->escaped().
401
+				$this->entityIdLinkFormatter->formatEntityId($entityId).
402
+				$this->msg('word-separator')->escaped().
403
+				$this->msg('parentheses', $entityId->getSerialization())->escaped()
404 404
 		);
405 405
 	}
406 406
 
@@ -411,23 +411,23 @@  discard block
 block discarded – undo
411 411
 	 *
412 412
 	 * @return string HTML
413 413
 	 */
414
-	protected function buildSummary( array $results ): string {
414
+	protected function buildSummary(array $results): string {
415 415
 		$statuses = [];
416
-		foreach ( $results as $result ) {
417
-			$status = strtolower( $result->getStatus() );
416
+		foreach ($results as $result) {
417
+			$status = strtolower($result->getStatus());
418 418
 			$statuses[$status] ??= 0;
419 419
 			$statuses[$status]++;
420 420
 		}
421 421
 
422 422
 		$statusElements = [];
423
-		foreach ( $statuses as $status => $count ) {
424
-			$statusElements[] = $this->formatStatus( $status ) .
425
-				$this->msg( 'colon-separator' )->escaped() .
426
-				htmlspecialchars( $this->getLanguage()->formatNum( $count ) );
423
+		foreach ($statuses as $status => $count) {
424
+			$statusElements[] = $this->formatStatus($status).
425
+				$this->msg('colon-separator')->escaped().
426
+				htmlspecialchars($this->getLanguage()->formatNum($count));
427 427
 		}
428 428
 
429
-		return Html::rawElement( 'p', [],
430
-			implode( $this->msg( 'comma-separator' )->escaped(), $statusElements )
429
+		return Html::rawElement('p', [],
430
+			implode($this->msg('comma-separator')->escaped(), $statusElements)
431 431
 		);
432 432
 	}
433 433
 
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 	 *
441 441
 	 * @return string HTML
442 442
 	 */
443
-	private function formatStatus( string $status ): string {
444
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
443
+	private function formatStatus(string $status): string {
444
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
445 445
 		$statusIcons = [
446 446
 			CheckResult::STATUS_SUGGESTION => [
447 447
 				'icon' => 'suggestion-constraint-violation',
@@ -458,21 +458,21 @@  discard block
 block discarded – undo
458 458
 			],
459 459
 		];
460 460
 
461
-		if ( array_key_exists( $status, $statusIcons ) ) {
462
-			$iconHtml = new IconWidget( $statusIcons[$status] ) .
463
-				$this->msg( 'word-separator' )->escaped();
461
+		if (array_key_exists($status, $statusIcons)) {
462
+			$iconHtml = new IconWidget($statusIcons[$status]).
463
+				$this->msg('word-separator')->escaped();
464 464
 		} else {
465 465
 			$iconHtml = '';
466 466
 		}
467 467
 
468
-		$labelWidget = new LabelWidget( [ 'label' => $this->msg( $messageName )->text() ] );
468
+		$labelWidget = new LabelWidget(['label' => $this->msg($messageName)->text()]);
469 469
 
470 470
 		return Html::rawElement(
471 471
 			'span',
472 472
 			[
473
-				'class' => 'wbqc-status wbqc-status-' . $status,
473
+				'class' => 'wbqc-status wbqc-status-'.$status,
474 474
 			],
475
-			$iconHtml . $labelWidget
475
+			$iconHtml.$labelWidget
476 476
 		);
477 477
 	}
478 478
 
@@ -490,10 +490,10 @@  discard block
 block discarded – undo
490 490
 		NumericPropertyId $propertyId,
491 491
 		string $text
492 492
 	): string {
493
-		$title = clone $this->entityTitleLookup->getTitleForId( $entityId );
494
-		$title->setFragment( $propertyId->getSerialization() );
493
+		$title = clone $this->entityTitleLookup->getTitleForId($entityId);
494
+		$title->setFragment($propertyId->getSerialization());
495 495
 
496
-		return Html::rawElement( 'a',
496
+		return Html::rawElement('a',
497 497
 			[
498 498
 				'href' => $title->getLinkURL(),
499 499
 				'target' => '_blank',
Please login to merge, or discard this patch.