@@ -1,6 +1,6 @@ discard block |
||
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 |
||
91 | 91 | Config $config, |
92 | 92 | IBufferingStatsdDataFactory $dataFactory |
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 |
||
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 |
||
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,43 +157,43 @@ discard block |
||
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 |
||
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,16 +228,16 @@ discard block |
||
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 | 'required' => true, |
233 | 233 | ], |
234 | 234 | ]; |
235 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
236 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
237 | - $htmlForm->setSubmitCallback( static function () { |
|
235 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
236 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
237 | + $htmlForm->setSubmitCallback(static function() { |
|
238 | 238 | return false; |
239 | 239 | } ); |
240 | - $htmlForm->setMethod( 'post' ); |
|
240 | + $htmlForm->setMethod('post'); |
|
241 | 241 | $htmlForm->show(); |
242 | 242 | } |
243 | 243 | |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return string HTML |
253 | 253 | */ |
254 | - private function buildNotice( string $messageKey, bool $error = false ): string { |
|
254 | + private function buildNotice(string $messageKey, bool $error = false): string { |
|
255 | 255 | $cssClasses = 'wbqc-constraintreport-notice'; |
256 | - if ( $error ) { |
|
256 | + if ($error) { |
|
257 | 257 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
258 | 258 | } |
259 | 259 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | [ |
263 | 263 | 'class' => $cssClasses, |
264 | 264 | ], |
265 | - $this->msg( $messageKey )->escaped() |
|
265 | + $this->msg($messageKey)->escaped() |
|
266 | 266 | ); |
267 | 267 | } |
268 | 268 | |
@@ -272,16 +272,16 @@ discard block |
||
272 | 272 | private function getExplanationText(): string { |
273 | 273 | return Html::rawElement( |
274 | 274 | 'div', |
275 | - [ 'class' => 'wbqc-explanation' ], |
|
275 | + ['class' => 'wbqc-explanation'], |
|
276 | 276 | Html::rawElement( |
277 | 277 | 'p', |
278 | 278 | [], |
279 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
279 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
280 | 280 | ) |
281 | 281 | . Html::rawElement( |
282 | 282 | 'p', |
283 | 283 | [], |
284 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
284 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
285 | 285 | ) |
286 | 286 | ); |
287 | 287 | } |
@@ -292,31 +292,31 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @return string HTML |
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' )->text(), |
|
300 | + $this->msg('wbqc-constraintreport-result-table-header-status')->text(), |
|
301 | 301 | true |
302 | 302 | ), |
303 | 303 | new HtmlTableHeaderBuilder( |
304 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->text(), |
|
304 | + $this->msg('wbqc-constraintreport-result-table-header-property')->text(), |
|
305 | 305 | true |
306 | 306 | ), |
307 | 307 | new HtmlTableHeaderBuilder( |
308 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->text(), |
|
308 | + $this->msg('wbqc-constraintreport-result-table-header-message')->text(), |
|
309 | 309 | true |
310 | 310 | ), |
311 | 311 | new HtmlTableHeaderBuilder( |
312 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->text(), |
|
312 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->text(), |
|
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 |
||
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 | |
@@ -364,16 +364,16 @@ discard block |
||
364 | 364 | $table->appendRow( |
365 | 365 | [ |
366 | 366 | new HtmlTableCellBuilder( |
367 | - new HtmlArmor( $statusColumn ) |
|
367 | + new HtmlArmor($statusColumn) |
|
368 | 368 | ), |
369 | 369 | new HtmlTableCellBuilder( |
370 | - new HtmlArmor( $propertyColumn ) |
|
370 | + new HtmlArmor($propertyColumn) |
|
371 | 371 | ), |
372 | 372 | new HtmlTableCellBuilder( |
373 | - new HtmlArmor( $messageColumn ) |
|
373 | + new HtmlArmor($messageColumn) |
|
374 | 374 | ), |
375 | 375 | new HtmlTableCellBuilder( |
376 | - new HtmlArmor( $constraintColumn ) |
|
376 | + new HtmlArmor($constraintColumn) |
|
377 | 377 | ), |
378 | 378 | ] |
379 | 379 | ); |
@@ -388,15 +388,15 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @return string HTML |
390 | 390 | */ |
391 | - protected function buildResultHeader( EntityId $entityId ): string { |
|
392 | - $entityLink = sprintf( '%s (%s)', |
|
393 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
394 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
391 | + protected function buildResultHeader(EntityId $entityId): string { |
|
392 | + $entityLink = sprintf('%s (%s)', |
|
393 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
394 | + htmlspecialchars($entityId->getSerialization())); |
|
395 | 395 | |
396 | 396 | return Html::rawElement( |
397 | 397 | 'h3', |
398 | 398 | [], |
399 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
399 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
400 | 400 | ); |
401 | 401 | } |
402 | 402 | |
@@ -407,24 +407,24 @@ discard block |
||
407 | 407 | * |
408 | 408 | * @return string HTML |
409 | 409 | */ |
410 | - protected function buildSummary( array $results ): string { |
|
410 | + protected function buildSummary(array $results): string { |
|
411 | 411 | $statuses = []; |
412 | - foreach ( $results as $result ) { |
|
413 | - $status = strtolower( $result->getStatus() ); |
|
414 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
412 | + foreach ($results as $result) { |
|
413 | + $status = strtolower($result->getStatus()); |
|
414 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | $statusElements = []; |
418 | - foreach ( $statuses as $status => $count ) { |
|
419 | - if ( $count > 0 ) { |
|
418 | + foreach ($statuses as $status => $count) { |
|
419 | + if ($count > 0) { |
|
420 | 420 | $statusElements[] = |
421 | - $this->formatStatus( $status ) |
|
421 | + $this->formatStatus($status) |
|
422 | 422 | . ': ' |
423 | 423 | . $count; |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
427 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | * |
437 | 437 | * @return string HTML |
438 | 438 | */ |
439 | - private function formatStatus( string $status ): string { |
|
440 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
439 | + private function formatStatus(string $status): string { |
|
440 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
441 | 441 | $statusIcons = [ |
442 | 442 | CheckResult::STATUS_SUGGESTION => [ |
443 | 443 | 'icon' => 'suggestion-constraint-violation', |
@@ -454,25 +454,25 @@ discard block |
||
454 | 454 | ], |
455 | 455 | ]; |
456 | 456 | |
457 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
458 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
459 | - $iconHtml = $iconWidget->toString() . ' '; |
|
457 | + if (array_key_exists($status, $statusIcons)) { |
|
458 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
459 | + $iconHtml = $iconWidget->toString().' '; |
|
460 | 460 | } else { |
461 | 461 | $iconHtml = ''; |
462 | 462 | } |
463 | 463 | |
464 | - $labelWidget = new LabelWidget( [ |
|
465 | - 'label' => $this->msg( $messageName )->text(), |
|
466 | - ] ); |
|
464 | + $labelWidget = new LabelWidget([ |
|
465 | + 'label' => $this->msg($messageName)->text(), |
|
466 | + ]); |
|
467 | 467 | $labelHtml = $labelWidget->toString(); |
468 | 468 | |
469 | 469 | $formattedStatus = |
470 | 470 | 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 . $labelHtml |
|
475 | + $iconHtml.$labelHtml |
|
476 | 476 | ); |
477 | 477 | |
478 | 478 | return $formattedStatus; |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | return Html::rawElement( |
496 | 496 | 'a', |
497 | 497 | [ |
498 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
498 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
499 | 499 | 'target' => '_blank', |
500 | 500 | ], |
501 | 501 | $text |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | EntityId $entityId, |
510 | 510 | NumericPropertyId $propertyId |
511 | 511 | ): string { |
512 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
513 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
512 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
513 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
514 | 514 | |
515 | 515 | return $entityUrl; |
516 | 516 | } |