Completed
Push — master ( a9da56...aa4c74 )
by
unknown
14s
created
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +78 added lines, -78 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
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		Config $config,
90 90
 		IBufferingStatsdDataFactory $dataFactory
91 91
 	) {
92
-		parent::__construct( 'ConstraintReport' );
92
+		parent::__construct('ConstraintReport');
93 93
 
94 94
 		$this->entityLookup = $entityLookup;
95 95
 		$this->entityTitleLookup = $entityTitleLookup;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
 		$this->violationMessageRenderer = $violationMessageRendererFactory->getViolationMessageRenderer(
111 111
 			$language,
112
-			$languageFallbackChainFactory->newFromLanguage( $language ),
112
+			$languageFallbackChainFactory->newFromLanguage($language),
113 113
 			$this->getContext()
114 114
 		);
115 115
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @return string
146 146
 	 */
147 147
 	public function getDescription() {
148
-		return $this->msg( 'wbqc-constraintreport' )->text();
148
+		return $this->msg('wbqc-constraintreport')->text();
149 149
 	}
150 150
 
151 151
 	/**
@@ -157,43 +157,43 @@  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 ) {
165
-			$out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() );
163
+		$postRequest = $this->getContext()->getRequest()->getVal('entityid');
164
+		if ($postRequest) {
165
+			$out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL());
166 166
 			return;
167 167
 		}
168 168
 
169 169
 		$out->enableOOUI();
170
-		$out->addModules( $this->getModules() );
170
+		$out->addModules($this->getModules());
171 171
 
172 172
 		$this->setHeaders();
173 173
 
174
-		$out->addHTML( $this->getExplanationText() );
174
+		$out->addHTML($this->getExplanationText());
175 175
 		$this->buildEntityIdForm();
176 176
 
177
-		if ( !$subPage ) {
177
+		if (!$subPage) {
178 178
 			return;
179 179
 		}
180 180
 
181
-		if ( !is_string( $subPage ) ) {
182
-			throw new InvalidArgumentException( '$subPage must be string.' );
181
+		if (!is_string($subPage)) {
182
+			throw new InvalidArgumentException('$subPage must be string.');
183 183
 		}
184 184
 
185 185
 		try {
186
-			$entityId = $this->entityIdParser->parse( $subPage );
187
-		} catch ( EntityIdParsingException $e ) {
186
+			$entityId = $this->entityIdParser->parse($subPage);
187
+		} catch (EntityIdParsingException $e) {
188 188
 			$out->addHTML(
189
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
189
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
190 190
 			);
191 191
 			return;
192 192
 		}
193 193
 
194
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
194
+		if (!$this->entityLookup->hasEntity($entityId)) {
195 195
 			$out->addHTML(
196
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
196
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
197 197
 			);
198 198
 			return;
199 199
 		}
@@ -201,18 +201,18 @@  discard block
 block discarded – undo
201 201
 		$this->dataFactory->increment(
202 202
 			'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck'
203 203
 		);
204
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
204
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
205 205
 
206
-		if ( $results !== [] ) {
206
+		if ($results !== []) {
207 207
 			$out->addHTML(
208
-				$this->buildResultHeader( $entityId )
209
-				. $this->buildSummary( $results )
210
-				. $this->buildResultTable( $entityId, $results )
208
+				$this->buildResultHeader($entityId)
209
+				. $this->buildSummary($results)
210
+				. $this->buildResultTable($entityId, $results)
211 211
 			);
212 212
 		} else {
213 213
 			$out->addHTML(
214
-				$this->buildResultHeader( $entityId )
215
-				. $this->buildNotice( 'wbqc-constraintreport-empty-result' )
214
+				$this->buildResultHeader($entityId)
215
+				. $this->buildNotice('wbqc-constraintreport-empty-result')
216 216
 			);
217 217
 		}
218 218
 	}
@@ -228,15 +228,15 @@  discard block
 block discarded – undo
228 228
 				'name' => 'entityid',
229 229
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
230 230
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
231
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped(),
231
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped(),
232 232
 			],
233 233
 		];
234
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' );
235
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() );
236
-		$htmlForm->setSubmitCallback( static function () {
234
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form');
235
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped());
236
+		$htmlForm->setSubmitCallback(static function() {
237 237
 			return false;
238 238
 		} );
239
-		$htmlForm->setMethod( 'post' );
239
+		$htmlForm->setMethod('post');
240 240
 		$htmlForm->show();
241 241
 	}
242 242
 
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
 	 *
251 251
 	 * @return string HTML
252 252
 	 */
253
-	private function buildNotice( string $messageKey, bool $error = false ): string {
253
+	private function buildNotice(string $messageKey, bool $error = false): string {
254 254
 		$cssClasses = 'wbqc-constraintreport-notice';
255
-		if ( $error ) {
255
+		if ($error) {
256 256
 			$cssClasses .= ' wbqc-constraintreport-notice-error';
257 257
 		}
258 258
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 				[
262 262
 					'class' => $cssClasses,
263 263
 				],
264
-				$this->msg( $messageKey )->escaped()
264
+				$this->msg($messageKey)->escaped()
265 265
 			);
266 266
 	}
267 267
 
@@ -271,16 +271,16 @@  discard block
 block discarded – undo
271 271
 	private function getExplanationText(): string {
272 272
 		return Html::rawElement(
273 273
 			'div',
274
-			[ 'class' => 'wbqc-explanation' ],
274
+			['class' => 'wbqc-explanation'],
275 275
 			Html::rawElement(
276 276
 				'p',
277 277
 				[],
278
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped()
278
+				$this->msg('wbqc-constraintreport-explanation-part-one')->escaped()
279 279
 			)
280 280
 			. Html::rawElement(
281 281
 				'p',
282 282
 				[],
283
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped()
283
+				$this->msg('wbqc-constraintreport-explanation-part-two')->escaped()
284 284
 			)
285 285
 		);
286 286
 	}
@@ -292,31 +292,31 @@  discard block
 block discarded – undo
292 292
 	 * @return string HTML
293 293
 	 * @suppress SecurityCheck-DoubleEscaped
294 294
 	 */
295
-	private function buildResultTable( EntityId $entityId, array $results ): string {
295
+	private function buildResultTable(EntityId $entityId, array $results): string {
296 296
 		// Set table headers
297 297
 		$table = new HtmlTableBuilder(
298 298
 			[
299 299
 				new HtmlTableHeaderBuilder(
300
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(),
300
+					$this->msg('wbqc-constraintreport-result-table-header-status')->escaped(),
301 301
 					true
302 302
 				),
303 303
 				new HtmlTableHeaderBuilder(
304
-					$this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(),
304
+					$this->msg('wbqc-constraintreport-result-table-header-property')->escaped(),
305 305
 					true
306 306
 				),
307 307
 				new HtmlTableHeaderBuilder(
308
-					$this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(),
308
+					$this->msg('wbqc-constraintreport-result-table-header-message')->escaped(),
309 309
 					true
310 310
 				),
311 311
 				new HtmlTableHeaderBuilder(
312
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(),
312
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(),
313 313
 					true
314 314
 				),
315 315
 			]
316 316
 		);
317 317
 
318
-		foreach ( $results as $result ) {
319
-			$table = $this->appendToResultTable( $table, $entityId, $result );
318
+		foreach ($results as $result) {
319
+			$table = $this->appendToResultTable($table, $entityId, $result);
320 320
 		}
321 321
 
322 322
 		return $table->toHtml();
@@ -328,35 +328,35 @@  discard block
 block discarded – undo
328 328
 		CheckResult $result
329 329
 	): HtmlTableBuilder {
330 330
 		$message = $result->getMessage();
331
-		if ( $message === null ) {
331
+		if ($message === null) {
332 332
 			// no row for this result
333 333
 			return $table;
334 334
 		}
335 335
 
336 336
 		// Status column
337
-		$statusColumn = $this->formatStatus( $result->getStatus() );
337
+		$statusColumn = $this->formatStatus($result->getStatus());
338 338
 
339 339
 		// Property column
340
-		$propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() );
340
+		$propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId());
341 341
 		$propertyColumn = $this->getClaimLink(
342 342
 			$entityId,
343 343
 			$propertyId,
344
-			$this->entityIdLabelFormatter->formatEntityId( $propertyId )
344
+			$this->entityIdLabelFormatter->formatEntityId($propertyId)
345 345
 		);
346 346
 
347 347
 		// Message column
348
-		$messageColumn = $this->violationMessageRenderer->render( $message );
348
+		$messageColumn = $this->violationMessageRenderer->render($message);
349 349
 
350 350
 		// Constraint column
351 351
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
352 352
 		try {
353
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
354
-		} catch ( InvalidArgumentException $e ) {
355
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
353
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
354
+		} catch (InvalidArgumentException $e) {
355
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
356 356
 		}
357 357
 		$constraintColumn = $this->getClaimLink(
358 358
 			$propertyId,
359
-			new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
359
+			new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
360 360
 			$constraintTypeLabel
361 361
 		);
362 362
 
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
 	 *
397 397
 	 * @return string HTML
398 398
 	 */
399
-	protected function buildResultHeader( EntityId $entityId ): string {
400
-		$entityLink = sprintf( '%s (%s)',
401
-							   $this->entityIdLinkFormatter->formatEntityId( $entityId ),
402
-							   htmlspecialchars( $entityId->getSerialization() ) );
399
+	protected function buildResultHeader(EntityId $entityId): string {
400
+		$entityLink = sprintf('%s (%s)',
401
+							   $this->entityIdLinkFormatter->formatEntityId($entityId),
402
+							   htmlspecialchars($entityId->getSerialization()));
403 403
 
404 404
 		return Html::rawElement(
405 405
 			'h3',
406 406
 			[],
407
-			sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink )
407
+			sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink)
408 408
 		);
409 409
 	}
410 410
 
@@ -415,24 +415,24 @@  discard block
 block discarded – undo
415 415
 	 *
416 416
 	 * @return string HTML
417 417
 	 */
418
-	protected function buildSummary( array $results ): string {
418
+	protected function buildSummary(array $results): string {
419 419
 		$statuses = [];
420
-		foreach ( $results as $result ) {
421
-			$status = strtolower( $result->getStatus() );
422
-			$statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1;
420
+		foreach ($results as $result) {
421
+			$status = strtolower($result->getStatus());
422
+			$statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1;
423 423
 		}
424 424
 
425 425
 		$statusElements = [];
426
-		foreach ( $statuses as $status => $count ) {
427
-			if ( $count > 0 ) {
426
+		foreach ($statuses as $status => $count) {
427
+			if ($count > 0) {
428 428
 				$statusElements[] =
429
-					$this->formatStatus( $status )
429
+					$this->formatStatus($status)
430 430
 					. ': '
431 431
 					. $count;
432 432
 			}
433 433
 		}
434 434
 
435
-		return Html::rawElement( 'p', [], implode( ', ', $statusElements ) );
435
+		return Html::rawElement('p', [], implode(', ', $statusElements));
436 436
 	}
437 437
 
438 438
 	/**
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
 	 *
445 445
 	 * @return string HTML
446 446
 	 */
447
-	private function formatStatus( string $status ): string {
448
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
447
+	private function formatStatus(string $status): string {
448
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
449 449
 		$statusIcons = [
450 450
 			CheckResult::STATUS_SUGGESTION => [
451 451
 				'icon' => 'suggestion-constraint-violation',
@@ -462,25 +462,25 @@  discard block
 block discarded – undo
462 462
 			],
463 463
 		];
464 464
 
465
-		if ( array_key_exists( $status, $statusIcons ) ) {
466
-			$iconWidget = new IconWidget( $statusIcons[$status] );
467
-			$iconHtml = $iconWidget->toString() . ' ';
465
+		if (array_key_exists($status, $statusIcons)) {
466
+			$iconWidget = new IconWidget($statusIcons[$status]);
467
+			$iconHtml = $iconWidget->toString().' ';
468 468
 		} else {
469 469
 			$iconHtml = '';
470 470
 		}
471 471
 
472
-		$labelWidget = new LabelWidget( [
473
-			'label' => $this->msg( $messageName )->text(),
474
-		] );
472
+		$labelWidget = new LabelWidget([
473
+			'label' => $this->msg($messageName)->text(),
474
+		]);
475 475
 		$labelHtml = $labelWidget->toString();
476 476
 
477 477
 		$formattedStatus =
478 478
 			Html::rawElement(
479 479
 				'span',
480 480
 				[
481
-					'class' => 'wbqc-status wbqc-status-' . $status,
481
+					'class' => 'wbqc-status wbqc-status-'.$status,
482 482
 				],
483
-				$iconHtml . $labelHtml
483
+				$iconHtml.$labelHtml
484 484
 			);
485 485
 
486 486
 		return $formattedStatus;
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		return Html::rawElement(
504 504
 			'a',
505 505
 			[
506
-				'href' => $this->getClaimUrl( $entityId, $propertyId ),
506
+				'href' => $this->getClaimUrl($entityId, $propertyId),
507 507
 				'target' => '_blank',
508 508
 			],
509 509
 			$text
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
 		EntityId $entityId,
518 518
 		NumericPropertyId $propertyId
519 519
 	): string {
520
-		$title = $this->entityTitleLookup->getTitleForId( $entityId );
521
-		$entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() );
520
+		$title = $this->entityTitleLookup->getTitleForId($entityId);
521
+		$entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization());
522 522
 
523 523
 		return $entityUrl;
524 524
 	}
Please login to merge, or discard this patch.