Completed
Push — master ( 264e6e...825067 )
by
unknown
23s
created
src/WikibaseQualityConstraintsHooks.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,52 +20,52 @@
 block discarded – undo
20 20
 {
21 21
 
22 22
 	/** @inheritDoc */
23
-	public function onArticlePurge( $wikiPage ) {
23
+	public function onArticlePurge($wikiPage) {
24 24
 		$entityContentFactory = WikibaseRepo::getEntityContentFactory();
25
-		if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) {
25
+		if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) {
26 26
 			$entityIdLookup = WikibaseRepo::getEntityIdLookup();
27
-			$entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() );
28
-			if ( $entityId !== null ) {
27
+			$entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle());
28
+			if ($entityId !== null) {
29 29
 				$resultsCache = ResultsCache::getDefaultInstance();
30
-				$resultsCache->delete( $entityId );
30
+				$resultsCache->delete($entityId);
31 31
 			}
32 32
 		}
33 33
 	}
34 34
 
35 35
 	/** @inheritDoc */
36
-	public function onBeforePageDisplay( $out, $skin ): void {
36
+	public function onBeforePageDisplay($out, $skin): void {
37 37
 		$lookup = WikibaseRepo::getEntityNamespaceLookup();
38 38
 		$title = $out->getTitle();
39
-		if ( $title === null ) {
39
+		if ($title === null) {
40 40
 			return;
41 41
 		}
42 42
 
43
-		if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) {
43
+		if (!$lookup->isNamespaceWithEntities($title->getNamespace())) {
44 44
 			return;
45 45
 		}
46
-		if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) {
46
+		if (empty($out->getJsConfigVars()['wbIsEditView'])) {
47 47
 			return;
48 48
 		}
49 49
 
50 50
 		$services = MediaWikiServices::getInstance();
51 51
 		$config = $services->getMainConfig();
52 52
 
53
-		$isMobileView = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) &&
54
-			$services->getService( 'MobileFrontend.Context' )->shouldDisplayMobileView();
55
-		if ( $isMobileView ) {
53
+		$isMobileView = ExtensionRegistry::getInstance()->isLoaded('MobileFrontend') &&
54
+			$services->getService('MobileFrontend.Context')->shouldDisplayMobileView();
55
+		if ($isMobileView) {
56 56
 			return;
57 57
 		}
58 58
 
59
-		$out->addModules( 'wikibase.quality.constraints.suggestions' );
59
+		$out->addModules('wikibase.quality.constraints.suggestions');
60 60
 
61 61
 		$user = $out->getUser();
62 62
 		if (
63
-			$user->isAllowed( 'wbqc-check-constraints' ) && (
64
-				$config->get( 'WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers' ) ||
63
+			$user->isAllowed('wbqc-check-constraints') && (
64
+				$config->get('WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers') ||
65 65
 				$user->isRegistered()
66 66
 			)
67 67
 		) {
68
-			$out->addModules( 'wikibase.quality.constraints.gadget' );
68
+			$out->addModules('wikibase.quality.constraints.gadget');
69 69
 		}
70 70
 	}
71 71
 
Please login to merge, or discard this patch.
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', 'wbqc-check-constraints-uncached' );
94
+		parent::__construct('ConstraintReport', 'wbqc-check-constraints-uncached');
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,73 +157,73 @@  discard block
 block discarded – undo
157 157
 	 * @throws EntityIdParsingException
158 158
 	 * @throws UnexpectedValueException
159 159
 	 */
160
-	public function execute( $subPage ) {
161
-		parent::execute( $subPage );
160
+	public function execute($subPage) {
161
+		parent::execute($subPage);
162 162
 
163 163
 		$out = $this->getOutput();
164 164
 
165
-		$postRequest = $this->getContext()->getRequest()->getVal( 'entityid' );
166
-		if ( $postRequest ) {
165
+		$postRequest = $this->getContext()->getRequest()->getVal('entityid');
166
+		if ($postRequest) {
167 167
 			try {
168
-				$entityId = $this->entityIdParser->parse( $postRequest );
169
-				$out->redirect( $this->getPageTitle( $entityId->getSerialization() )->getLocalURL() );
168
+				$entityId = $this->entityIdParser->parse($postRequest);
169
+				$out->redirect($this->getPageTitle($entityId->getSerialization())->getLocalURL());
170 170
 				return;
171
-			} catch ( EntityIdParsingException ) {
171
+			} catch (EntityIdParsingException) {
172 172
 				// fall through, error is shown later
173 173
 			}
174 174
 		}
175 175
 
176 176
 		$out->enableOOUI();
177
-		$out->addModules( $this->getModules() );
177
+		$out->addModules($this->getModules());
178 178
 
179 179
 		$this->setHeaders();
180 180
 
181
-		$out->addHTML( $this->getExplanationText() );
181
+		$out->addHTML($this->getExplanationText());
182 182
 		$this->buildEntityIdForm();
183 183
 
184
-		if ( $postRequest ) {
184
+		if ($postRequest) {
185 185
 			// must be an invalid entity ID (otherwise we would have redirected and returned above)
186 186
 			$out->addHTML(
187
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
187
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
188 188
 			);
189 189
 			return;
190 190
 		}
191 191
 
192
-		if ( !$subPage ) {
192
+		if (!$subPage) {
193 193
 			return;
194 194
 		}
195 195
 
196 196
 		try {
197
-			$entityId = $this->entityIdParser->parse( $subPage );
198
-		} catch ( EntityIdParsingException ) {
197
+			$entityId = $this->entityIdParser->parse($subPage);
198
+		} catch (EntityIdParsingException) {
199 199
 			$out->addHTML(
200
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
200
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
201 201
 			);
202 202
 			return;
203 203
 		}
204 204
 
205
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
205
+		if (!$this->entityLookup->hasEntity($entityId)) {
206 206
 			$out->addHTML(
207
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
207
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
208 208
 			);
209 209
 			return;
210 210
 		}
211 211
 
212
-		$this->statsFactory->getCounter( 'special_constraint_report_execute_check_total' )
212
+		$this->statsFactory->getCounter('special_constraint_report_execute_check_total')
213 213
 			->increment();
214
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
214
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
215 215
 
216
-		if ( !$results ) {
217
-			$out->addHTML( $this->buildResultHeader( $entityId ) .
218
-				$this->buildNotice( 'wbqc-constraintreport-empty-result' )
216
+		if (!$results) {
217
+			$out->addHTML($this->buildResultHeader($entityId).
218
+				$this->buildNotice('wbqc-constraintreport-empty-result')
219 219
 			);
220 220
 			return;
221 221
 		}
222 222
 
223 223
 		$out->addHTML(
224
-			$this->buildResultHeader( $entityId )
225
-			. $this->buildSummary( $results )
226
-			. $this->buildResultTable( $entityId, $results )
224
+			$this->buildResultHeader($entityId)
225
+			. $this->buildSummary($results)
226
+			. $this->buildResultTable($entityId, $results)
227 227
 		);
228 228
 	}
229 229
 
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
 				'name' => 'entityid',
239 239
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
240 240
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
241
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->text(),
241
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->text(),
242 242
 				'required' => true,
243 243
 			],
244 244
 		];
245
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(),
245
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(),
246 246
 			'wbqc-constraintreport-form'
247 247
 		);
248
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->text() );
249
-		$htmlForm->setSubmitCallback( static fn () => false );
248
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->text());
249
+		$htmlForm->setSubmitCallback(static fn () => false);
250 250
 		$htmlForm->show();
251 251
 	}
252 252
 
@@ -260,16 +260,16 @@  discard block
 block discarded – undo
260 260
 	 *
261 261
 	 * @return string HTML
262 262
 	 */
263
-	private function buildNotice( string $messageKey, bool $error = false ): string {
264
-		$cssClasses = [ 'wbqc-constraintreport-notice' ];
265
-		if ( $error ) {
263
+	private function buildNotice(string $messageKey, bool $error = false): string {
264
+		$cssClasses = ['wbqc-constraintreport-notice'];
265
+		if ($error) {
266 266
 			$cssClasses[] = ' wbqc-constraintreport-notice-error';
267 267
 		}
268 268
 
269 269
 		return Html::element(
270 270
 			'p',
271
-			[ 'class' => $cssClasses ],
272
-			$this->msg( $messageKey )->text()
271
+			['class' => $cssClasses],
272
+			$this->msg($messageKey)->text()
273 273
 		);
274 274
 	}
275 275
 
@@ -279,16 +279,16 @@  discard block
 block discarded – undo
279 279
 	private function getExplanationText(): string {
280 280
 		return Html::rawElement(
281 281
 			'div',
282
-			[ 'class' => 'wbqc-explanation' ],
282
+			['class' => 'wbqc-explanation'],
283 283
 			Html::element(
284 284
 				'p',
285 285
 				[],
286
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->text()
286
+				$this->msg('wbqc-constraintreport-explanation-part-one')->text()
287 287
 			)
288 288
 			. Html::element(
289 289
 				'p',
290 290
 				[],
291
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->text()
291
+				$this->msg('wbqc-constraintreport-explanation-part-two')->text()
292 292
 			)
293 293
 		);
294 294
 	}
@@ -299,31 +299,31 @@  discard block
 block discarded – undo
299 299
 	 *
300 300
 	 * @return string HTML
301 301
 	 */
302
-	private function buildResultTable( EntityId $entityId, array $results ): string {
302
+	private function buildResultTable(EntityId $entityId, array $results): string {
303 303
 		// Set table headers
304 304
 		$table = new HtmlTableBuilder(
305 305
 			[
306 306
 				new HtmlTableHeaderBuilder(
307
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->text(),
307
+					$this->msg('wbqc-constraintreport-result-table-header-status')->text(),
308 308
 					true
309 309
 				),
310 310
 				new HtmlTableHeaderBuilder(
311
-					$this->msg( 'wbqc-constraintreport-result-table-header-property' )->text(),
311
+					$this->msg('wbqc-constraintreport-result-table-header-property')->text(),
312 312
 					true
313 313
 				),
314 314
 				new HtmlTableHeaderBuilder(
315
-					$this->msg( 'wbqc-constraintreport-result-table-header-message' )->text(),
315
+					$this->msg('wbqc-constraintreport-result-table-header-message')->text(),
316 316
 					true
317 317
 				),
318 318
 				new HtmlTableHeaderBuilder(
319
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->text(),
319
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->text(),
320 320
 					true
321 321
 				),
322 322
 			]
323 323
 		);
324 324
 
325
-		foreach ( $results as $result ) {
326
-			$this->appendToResultTable( $table, $entityId, $result );
325
+		foreach ($results as $result) {
326
+			$this->appendToResultTable($table, $entityId, $result);
327 327
 		}
328 328
 
329 329
 		return $table->toHtml();
@@ -335,35 +335,35 @@  discard block
 block discarded – undo
335 335
 		CheckResult $result
336 336
 	): void {
337 337
 		$message = $result->getMessage();
338
-		if ( !$message ) {
338
+		if (!$message) {
339 339
 			// no row for this result
340 340
 			return;
341 341
 		}
342 342
 
343 343
 		// Status column
344
-		$statusColumn = $this->formatStatus( $result->getStatus() );
344
+		$statusColumn = $this->formatStatus($result->getStatus());
345 345
 
346 346
 		// Property column
347
-		$propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() );
347
+		$propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId());
348 348
 		$propertyColumn = $this->getClaimLink(
349 349
 			$entityId,
350 350
 			$propertyId,
351
-			$this->entityIdLabelFormatter->formatEntityId( $propertyId )
351
+			$this->entityIdLabelFormatter->formatEntityId($propertyId)
352 352
 		);
353 353
 
354 354
 		// Message column
355
-		$messageColumn = $this->violationMessageRenderer->render( $message );
355
+		$messageColumn = $this->violationMessageRenderer->render($message);
356 356
 
357 357
 		// Constraint column
358 358
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
359 359
 		try {
360
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
361
-		} catch ( InvalidArgumentException ) {
362
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
360
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
361
+		} catch (InvalidArgumentException) {
362
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
363 363
 		}
364 364
 		$constraintColumn = $this->getClaimLink(
365 365
 			$propertyId,
366
-			new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
366
+			new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
367 367
 			$constraintTypeLabel
368 368
 		);
369 369
 
@@ -371,16 +371,16 @@  discard block
 block discarded – undo
371 371
 		$table->appendRow(
372 372
 			[
373 373
 				new HtmlTableCellBuilder(
374
-					new HtmlArmor( $statusColumn )
374
+					new HtmlArmor($statusColumn)
375 375
 				),
376 376
 				new HtmlTableCellBuilder(
377
-					new HtmlArmor( $propertyColumn )
377
+					new HtmlArmor($propertyColumn)
378 378
 				),
379 379
 				new HtmlTableCellBuilder(
380
-					new HtmlArmor( $messageColumn )
380
+					new HtmlArmor($messageColumn)
381 381
 				),
382 382
 				new HtmlTableCellBuilder(
383
-					new HtmlArmor( $constraintColumn )
383
+					new HtmlArmor($constraintColumn)
384 384
 				),
385 385
 			]
386 386
 		);
@@ -393,15 +393,15 @@  discard block
 block discarded – undo
393 393
 	 *
394 394
 	 * @return string HTML
395 395
 	 */
396
-	protected function buildResultHeader( EntityId $entityId ): string {
396
+	protected function buildResultHeader(EntityId $entityId): string {
397 397
 		return Html::rawElement(
398 398
 			'h3',
399 399
 			[],
400
-			$this->msg( 'wbqc-constraintreport-result-headline' )->escaped() .
401
-				$this->msg( 'word-separator' )->escaped() .
402
-				$this->entityIdLinkFormatter->formatEntityId( $entityId ) .
403
-				$this->msg( 'word-separator' )->escaped() .
404
-				$this->msg( 'parentheses', $entityId->getSerialization() )->escaped()
400
+			$this->msg('wbqc-constraintreport-result-headline')->escaped().
401
+				$this->msg('word-separator')->escaped().
402
+				$this->entityIdLinkFormatter->formatEntityId($entityId).
403
+				$this->msg('word-separator')->escaped().
404
+				$this->msg('parentheses', $entityId->getSerialization())->escaped()
405 405
 		);
406 406
 	}
407 407
 
@@ -412,23 +412,23 @@  discard block
 block discarded – undo
412 412
 	 *
413 413
 	 * @return string HTML
414 414
 	 */
415
-	protected function buildSummary( array $results ): string {
415
+	protected function buildSummary(array $results): string {
416 416
 		$statuses = [];
417
-		foreach ( $results as $result ) {
418
-			$status = strtolower( $result->getStatus() );
417
+		foreach ($results as $result) {
418
+			$status = strtolower($result->getStatus());
419 419
 			$statuses[$status] ??= 0;
420 420
 			$statuses[$status]++;
421 421
 		}
422 422
 
423 423
 		$statusElements = [];
424
-		foreach ( $statuses as $status => $count ) {
425
-			$statusElements[] = $this->formatStatus( $status ) .
426
-				$this->msg( 'colon-separator' )->escaped() .
427
-				htmlspecialchars( $this->getLanguage()->formatNum( $count ) );
424
+		foreach ($statuses as $status => $count) {
425
+			$statusElements[] = $this->formatStatus($status).
426
+				$this->msg('colon-separator')->escaped().
427
+				htmlspecialchars($this->getLanguage()->formatNum($count));
428 428
 		}
429 429
 
430
-		return Html::rawElement( 'p', [],
431
-			implode( $this->msg( 'comma-separator' )->escaped(), $statusElements )
430
+		return Html::rawElement('p', [],
431
+			implode($this->msg('comma-separator')->escaped(), $statusElements)
432 432
 		);
433 433
 	}
434 434
 
@@ -441,8 +441,8 @@  discard block
 block discarded – undo
441 441
 	 *
442 442
 	 * @return string HTML
443 443
 	 */
444
-	private function formatStatus( string $status ): string {
445
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
444
+	private function formatStatus(string $status): string {
445
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
446 446
 		$statusIcons = [
447 447
 			CheckResult::STATUS_SUGGESTION => [
448 448
 				'icon' => 'suggestion-constraint-violation',
@@ -459,21 +459,21 @@  discard block
 block discarded – undo
459 459
 			],
460 460
 		];
461 461
 
462
-		if ( array_key_exists( $status, $statusIcons ) ) {
463
-			$iconHtml = new IconWidget( $statusIcons[$status] ) .
464
-				$this->msg( 'word-separator' )->escaped();
462
+		if (array_key_exists($status, $statusIcons)) {
463
+			$iconHtml = new IconWidget($statusIcons[$status]).
464
+				$this->msg('word-separator')->escaped();
465 465
 		} else {
466 466
 			$iconHtml = '';
467 467
 		}
468 468
 
469
-		$labelWidget = new LabelWidget( [ 'label' => $this->msg( $messageName )->text() ] );
469
+		$labelWidget = new LabelWidget(['label' => $this->msg($messageName)->text()]);
470 470
 
471 471
 		return Html::rawElement(
472 472
 			'span',
473 473
 			[
474
-				'class' => 'wbqc-status wbqc-status-' . $status,
474
+				'class' => 'wbqc-status wbqc-status-'.$status,
475 475
 			],
476
-			$iconHtml . $labelWidget
476
+			$iconHtml.$labelWidget
477 477
 		);
478 478
 	}
479 479
 
@@ -491,10 +491,10 @@  discard block
 block discarded – undo
491 491
 		NumericPropertyId $propertyId,
492 492
 		string $text
493 493
 	): string {
494
-		$title = clone $this->entityTitleLookup->getTitleForId( $entityId );
495
-		$title->setFragment( $propertyId->getSerialization() );
494
+		$title = clone $this->entityTitleLookup->getTitleForId($entityId);
495
+		$title->setFragment($propertyId->getSerialization());
496 496
 
497
-		return Html::rawElement( 'a',
497
+		return Html::rawElement('a',
498 498
 			[
499 499
 				'href' => $title->getLinkURL(),
500 500
 				'target' => '_blank',
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +32 added lines, -32 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\Api;
6 6
 
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
 		CheckResultsRendererFactory $checkResultsRendererFactory,
85 85
 		StatsFactory $statsFactory
86 86
 	) {
87
-		parent::__construct( $main, $name );
87
+		parent::__construct($main, $name);
88 88
 		$this->entityIdParser = $entityIdParser;
89 89
 		$this->statementGuidValidator = $statementGuidValidator;
90
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
91
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
90
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
91
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
92 92
 		$this->resultsSource = $resultsSource;
93 93
 		$this->checkResultsRendererFactory = $checkResultsRendererFactory;
94 94
 		$this->statsFactory = $statsFactory;
@@ -98,21 +98,21 @@  discard block
 block discarded – undo
98 98
 	 * Evaluates the parameters, runs the requested constraint check, and sets up the result
99 99
 	 */
100 100
 	public function execute() {
101
-		$this->statsFactory->getCounter( 'check_constraints_execute_total' )
101
+		$this->statsFactory->getCounter('check_constraints_execute_total')
102 102
 			->increment();
103 103
 
104
-		$this->checkUserRightsAny( 'wbqc-check-constraints' );
104
+		$this->checkUserRightsAny('wbqc-check-constraints');
105 105
 
106 106
 		$params = $this->extractRequestParams();
107 107
 
108
-		$this->validateParameters( $params );
109
-		$entityIds = $this->parseEntityIds( $params );
110
-		$claimIds = $this->parseClaimIds( $params );
108
+		$this->validateParameters($params);
109
+		$entityIds = $this->parseEntityIds($params);
110
+		$claimIds = $this->parseClaimIds($params);
111 111
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
112 112
 		$statuses = $params[self::PARAM_STATUS];
113 113
 
114 114
 		$checkResultsRenderer = $this->checkResultsRendererFactory
115
-			->getCheckResultsRenderer( $this->getLanguage(), $this );
115
+			->getCheckResultsRenderer($this->getLanguage(), $this);
116 116
 
117 117
 		$this->getResult()->addValue(
118 118
 			null,
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 				)
127 127
 			)->getArray()
128 128
 		);
129
-		$this->resultBuilder->markSuccess( 1 );
129
+		$this->resultBuilder->markSuccess(1);
130 130
 	}
131 131
 
132 132
 	/**
@@ -134,24 +134,24 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @return EntityId[]
136 136
 	 */
137
-	private function parseEntityIds( array $params ): array {
137
+	private function parseEntityIds(array $params): array {
138 138
 		$ids = $params[self::PARAM_ID];
139 139
 
140
-		if ( $ids === null ) {
140
+		if ($ids === null) {
141 141
 			return [];
142
-		} elseif ( $ids === [] ) {
142
+		} elseif ($ids === []) {
143 143
 			$this->errorReporter->dieError(
144
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
144
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
145 145
 		}
146 146
 
147
-		return array_map( function ( $id ) {
147
+		return array_map(function($id) {
148 148
 			try {
149
-				return $this->entityIdParser->parse( $id );
150
-			} catch ( EntityIdParsingException ) {
149
+				return $this->entityIdParser->parse($id);
150
+			} catch (EntityIdParsingException) {
151 151
 				$this->errorReporter->dieError(
152
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
152
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
153 153
 			}
154
-		}, $ids );
154
+		}, $ids);
155 155
 	}
156 156
 
157 157
 	/**
@@ -159,35 +159,35 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @return string[]
161 161
 	 */
162
-	private function parseClaimIds( array $params ): array {
162
+	private function parseClaimIds(array $params): array {
163 163
 		$ids = $params[self::PARAM_CLAIM_ID];
164 164
 
165
-		if ( $ids === null ) {
165
+		if ($ids === null) {
166 166
 			return [];
167
-		} elseif ( $ids === [] ) {
167
+		} elseif ($ids === []) {
168 168
 			$this->errorReporter->dieError(
169
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
169
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
170 170
 		}
171 171
 
172
-		foreach ( $ids as $id ) {
173
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
172
+		foreach ($ids as $id) {
173
+			if (!$this->statementGuidValidator->validate($id)) {
174 174
 				$this->errorReporter->dieError(
175
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
175
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
176 176
 			}
177 177
 		}
178 178
 
179 179
 		return $ids;
180 180
 	}
181 181
 
182
-	private function validateParameters( array $params ): void {
183
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
184
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
182
+	private function validateParameters(array $params): void {
183
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
184
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
185 185
 		) {
186 186
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
187 187
 			$this->errorReporter->dieError(
188 188
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
189 189
 		}
190
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
190
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
191 191
 			$paramId = self::PARAM_ID;
192 192
 			$paramClaimId = self::PARAM_CLAIM_ID;
193 193
 			$this->errorReporter->dieError(
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 				],
229 229
 				ParamValidator::PARAM_ISMULTI => true,
230 230
 				ParamValidator::PARAM_ALL => true,
231
-				ParamValidator::PARAM_DEFAULT => implode( '|', CachingResultsSource::CACHED_STATUSES ),
231
+				ParamValidator::PARAM_DEFAULT => implode('|', CachingResultsSource::CACHED_STATUSES),
232 232
 				ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
233 233
 			],
234 234
 		];
Please login to merge, or discard this patch.
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +50 added lines, -50 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\Api;
6 6
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 			$delegatingConstraintChecker,
66 66
 			$violationMessageRendererFactory,
67 67
 			$statementGuidParser,
68
-			$statsFactory->withComponent( 'WikibaseQualityConstraints' )
68
+			$statsFactory->withComponent('WikibaseQualityConstraints')
69 69
 		);
70 70
 	}
71 71
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 		StatementGuidParser $statementGuidParser,
80 80
 		StatsFactory $statsFactory
81 81
 	) {
82
-		parent::__construct( $main, $name );
82
+		parent::__construct($main, $name);
83 83
 
84
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
84
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
85 85
 		$this->languageFallbackChainFactory = $languageFallbackChainFactory;
86 86
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
87 87
 		$this->violationMessageRendererFactory = $violationMessageRendererFactory;
@@ -90,47 +90,47 @@  discard block
 block discarded – undo
90 90
 	}
91 91
 
92 92
 	public function execute() {
93
-		$this->statsFactory->getCounter( 'check_constraint_parameters_execute_total' )
93
+		$this->statsFactory->getCounter('check_constraint_parameters_execute_total')
94 94
 			->increment();
95 95
 
96
-		$this->checkUserRightsAny( 'wbqc-check-constraints' );
96
+		$this->checkUserRightsAny('wbqc-check-constraints');
97 97
 
98 98
 		$params = $this->extractRequestParams();
99 99
 		$result = $this->getResult();
100 100
 
101
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
102
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
101
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
102
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
103 103
 
104
-		$this->checkPropertyIds( $propertyIds, $result );
105
-		$this->checkConstraintIds( $constraintIds, $result );
104
+		$this->checkPropertyIds($propertyIds, $result);
105
+		$this->checkConstraintIds($constraintIds, $result);
106 106
 
107
-		$result->addValue( null, 'success', 1 );
107
+		$result->addValue(null, 'success', 1);
108 108
 	}
109 109
 
110 110
 	/**
111 111
 	 * @param array|null $propertyIdSerializations
112 112
 	 * @return NumericPropertyId[]
113 113
 	 */
114
-	private function parsePropertyIds( ?array $propertyIdSerializations ): array {
115
-		if ( $propertyIdSerializations === null ) {
114
+	private function parsePropertyIds(?array $propertyIdSerializations): array {
115
+		if ($propertyIdSerializations === null) {
116 116
 			return [];
117
-		} elseif ( $propertyIdSerializations === [] ) {
117
+		} elseif ($propertyIdSerializations === []) {
118 118
 			$this->apiErrorReporter->dieError(
119
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
119
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
120 120
 				'no-data'
121 121
 			);
122 122
 		}
123 123
 
124 124
 		return array_map(
125
-			function ( $propertyIdSerialization ) {
125
+			function($propertyIdSerialization) {
126 126
 				try {
127
-					return new NumericPropertyId( $propertyIdSerialization );
128
-				} catch ( InvalidArgumentException ) {
127
+					return new NumericPropertyId($propertyIdSerialization);
128
+				} catch (InvalidArgumentException) {
129 129
 					$this->apiErrorReporter->dieError(
130 130
 						"Invalid id: $propertyIdSerialization",
131 131
 						'invalid-property-id',
132 132
 						0, // default argument
133
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
133
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
134 134
 					);
135 135
 				}
136 136
 			},
@@ -142,35 +142,35 @@  discard block
 block discarded – undo
142 142
 	 * @param array|null $constraintIds
143 143
 	 * @return string[]
144 144
 	 */
145
-	private function parseConstraintIds( ?array $constraintIds ): array {
146
-		if ( $constraintIds === null ) {
145
+	private function parseConstraintIds(?array $constraintIds): array {
146
+		if ($constraintIds === null) {
147 147
 			return [];
148
-		} elseif ( $constraintIds === [] ) {
148
+		} elseif ($constraintIds === []) {
149 149
 			$this->apiErrorReporter->dieError(
150
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
150
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
151 151
 				'no-data'
152 152
 			);
153 153
 		}
154 154
 
155 155
 		return array_map(
156
-			function ( $constraintId ) {
156
+			function($constraintId) {
157 157
 				try {
158
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
159
-					if ( !$propertyId instanceof NumericPropertyId ) {
158
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
159
+					if (!$propertyId instanceof NumericPropertyId) {
160 160
 						$this->apiErrorReporter->dieError(
161 161
 							"Invalid property ID: {$propertyId->getSerialization()}",
162 162
 							'invalid-property-id',
163 163
 							0, // default argument
164
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
164
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
165 165
 						);
166 166
 					}
167 167
 					return $constraintId;
168
-				} catch ( StatementGuidParsingException ) {
168
+				} catch (StatementGuidParsingException) {
169 169
 					$this->apiErrorReporter->dieError(
170 170
 						"Invalid statement GUID: $constraintId",
171 171
 						'invalid-guid',
172 172
 						0, // default argument
173
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
173
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
174 174
 					);
175 175
 				}
176 176
 			},
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
 	 * @param NumericPropertyId[] $propertyIds
183 183
 	 * @param ApiResult $result
184 184
 	 */
185
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ): void {
186
-		foreach ( $propertyIds as $propertyId ) {
187
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
185
+	private function checkPropertyIds(array $propertyIds, ApiResult $result): void {
186
+		foreach ($propertyIds as $propertyId) {
187
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
188 188
 			$allConstraintExceptions = $this->delegatingConstraintChecker
189
-				->checkConstraintParametersOnPropertyId( $propertyId );
190
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
189
+				->checkConstraintParametersOnPropertyId($propertyId);
190
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
191 191
 				$this->addConstraintParameterExceptionsToResult(
192 192
 					$constraintId,
193 193
 					$constraintParameterExceptions,
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 	 * @param string[] $constraintIds
202 202
 	 * @param ApiResult $result
203 203
 	 */
204
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ): void {
205
-		foreach ( $constraintIds as $constraintId ) {
206
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
204
+	private function checkConstraintIds(array $constraintIds, ApiResult $result): void {
205
+		foreach ($constraintIds as $constraintId) {
206
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
207 207
 				// already checked as part of checkPropertyIds()
208 208
 				continue;
209 209
 			}
210 210
 			$constraintParameterExceptions = $this->delegatingConstraintChecker
211
-				->checkConstraintParametersOnConstraintId( $constraintId );
212
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
211
+				->checkConstraintParametersOnConstraintId($constraintId);
212
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
213 213
 		}
214 214
 	}
215 215
 
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
 	 * @param NumericPropertyId $propertyId
218 218
 	 * @return string[]
219 219
 	 */
220
-	private function getResultPathForPropertyId( NumericPropertyId $propertyId ): array {
221
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
220
+	private function getResultPathForPropertyId(NumericPropertyId $propertyId): array {
221
+		return [$this->getModuleName(), $propertyId->getSerialization()];
222 222
 	}
223 223
 
224 224
 	/**
225 225
 	 * @param string $constraintId
226 226
 	 * @return string[]
227 227
 	 */
228
-	private function getResultPathForConstraintId( string $constraintId ): array {
229
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
228
+	private function getResultPathForConstraintId(string $constraintId): array {
229
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
230 230
 		'@phan-var NumericPropertyId $propertyId';
231
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
231
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
232 232
 	}
233 233
 
234 234
 	/**
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
 		?array $constraintParameterExceptions,
244 244
 		ApiResult $result
245 245
 	): void {
246
-		$path = $this->getResultPathForConstraintId( $constraintId );
247
-		if ( $constraintParameterExceptions === null ) {
246
+		$path = $this->getResultPathForConstraintId($constraintId);
247
+		if ($constraintParameterExceptions === null) {
248 248
 			$result->addValue(
249 249
 				$path,
250 250
 				self::KEY_STATUS,
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 			$violationMessageRenderer = $this->violationMessageRendererFactory
262 262
 				->getViolationMessageRenderer(
263 263
 					$language,
264
-					$this->languageFallbackChainFactory->newFromLanguage( $language ),
264
+					$this->languageFallbackChainFactory->newFromLanguage($language),
265 265
 					$this
266 266
 				);
267 267
 			$problems = [];
268
-			foreach ( $constraintParameterExceptions as $constraintParameterException ) {
268
+			foreach ($constraintParameterExceptions as $constraintParameterException) {
269 269
 				$problems[] = [
270 270
 					self::KEY_MESSAGE_HTML => $violationMessageRenderer->render(
271 271
 						$constraintParameterException->getViolationMessage() ),
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 		return [
305 305
 			'action=wbcheckconstraintparameters&propertyid=P247'
306 306
 				=> 'apihelp-wbcheckconstraintparameters-example-propertyid-1',
307
-			'action=wbcheckconstraintparameters&' .
308
-			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' .
307
+			'action=wbcheckconstraintparameters&'.
308
+			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'.
309 309
 			'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f'
310 310
 				=> 'apihelp-wbcheckconstraintparameters-example-constraintid-2',
311 311
 		];
Please login to merge, or discard this patch.