Completed
Push — master ( c165cf...afc26a )
by
unknown
39s queued 14s
created
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +86 added lines, -86 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
 		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
 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,56 +157,56 @@  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
 		}
@@ -214,18 +214,18 @@  discard block
 block discarded – undo
214 214
 		$this->dataFactory->increment(
215 215
 			'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck'
216 216
 		);
217
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
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.
src/ConstraintCheck/Helper/FormatCheckerHelper.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@
 block discarded – undo
21 21
 	 * @return false|int (from the preg_match documentation) returns 1 if the pattern
22 22
 	 * matches given subject, 0 if it does not, or FALSE if an error occurred.
23 23
 	 */
24
-	public static function runRegexCheck( string $regex, string $text ) {
25
-		$pattern = '(^(?:' . $regex . ')$)u';
24
+	public static function runRegexCheck(string $regex, string $text) {
25
+		$pattern = '(^(?:'.$regex.')$)u';
26 26
 
27 27
 		// `preg_match` emits an E_WARNING when the pattern is not valid regex.
28 28
 		// Silence this warning to avoid throwing a ShellboxError.
29 29
 		// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
30
-		return @preg_match( $pattern, $text );
30
+		return @preg_match($pattern, $text);
31 31
 	}
32 32
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/TypeCheckerHelper.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -81,26 +81,26 @@  discard block
 block discarded – undo
81 81
 	 * @return bool
82 82
 	 * @throws OverflowException if $entitiesChecked exceeds the configured limit
83 83
 	 */
84
-	private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) {
85
-		$maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' );
84
+	private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) {
85
+		$maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities');
86 86
 		if ( ++$entitiesChecked > $maxEntities ) {
87
-			throw new OverflowException( 'Too many entities to check' );
87
+			throw new OverflowException('Too many entities to check');
88 88
 		}
89 89
 
90
-		$item = $this->entityLookup->getEntity( $comparativeClass );
91
-		if ( !( $item instanceof StatementListProvider ) ) {
90
+		$item = $this->entityLookup->getEntity($comparativeClass);
91
+		if (!($item instanceof StatementListProvider)) {
92 92
 			return false; // lookup failed, probably because item doesn't exist
93 93
 		}
94 94
 
95
-		$subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
95
+		$subclassId = $this->config->get('WBQualityConstraintsSubclassOfId');
96 96
 		$statements = $item->getStatements()
97
-			->getByPropertyId( new NumericPropertyId( $subclassId ) )
97
+			->getByPropertyId(new NumericPropertyId($subclassId))
98 98
 			->getBestStatements();
99 99
 		/** @var Statement $statement */
100
-		foreach ( $statements as $statement ) {
100
+		foreach ($statements as $statement) {
101 101
 			$mainSnak = $statement->getMainSnak();
102 102
 
103
-			if ( !$this->hasCorrectType( $mainSnak ) ) {
103
+			if (!$this->hasCorrectType($mainSnak)) {
104 104
 				continue;
105 105
 			}
106 106
 			/** @var PropertyValueSnak $mainSnak */
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
 			'@phan-var EntityIdValue $dataValue';
111 111
 			$comparativeClass = $dataValue->getEntityId();
112 112
 
113
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
113
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
114 114
 				return true;
115 115
 			}
116 116
 
117
-			if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) {
117
+			if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) {
118 118
 				return true;
119 119
 			}
120 120
 		}
@@ -135,40 +135,40 @@  discard block
 block discarded – undo
135 135
 	 * @return CachedBool
136 136
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
137 137
 	 */
138
-	public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) {
139
-		$timing = $this->statsFactory->getTiming( 'isSubclassOf_duration_seconds' )
140
-			->setLabel( 'result', 'success' )
141
-			->setLabel( 'TypeCheckerImplementation', 'php' )
142
-			->copyToStatsdAt( 'wikibase.quality.constraints.type.php.success.timing' );
138
+	public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) {
139
+		$timing = $this->statsFactory->getTiming('isSubclassOf_duration_seconds')
140
+			->setLabel('result', 'success')
141
+			->setLabel('TypeCheckerImplementation', 'php')
142
+			->copyToStatsdAt('wikibase.quality.constraints.type.php.success.timing');
143 143
 		$timing->start();
144 144
 
145 145
 		try {
146 146
 			$entitiesChecked = 0;
147
-			$isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked );
147
+			$isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked);
148 148
 			$timing->stop();
149 149
 
150 150
 			// not really a timing, but works like one (we want percentiles etc.)
151 151
 			// TODO: probably a good candidate for T348796
152
-			$this->statsFactory->getTiming( 'isSubclassOf_entities_total' )
153
-				->setLabel( 'TypeCheckerImplementation', 'php' )
154
-				->setLabel( 'result', 'success' )
155
-				->copyToStatsdAt( 'wikibase.quality.constraints.type.php.success.entities' )
156
-				->observe( $entitiesChecked );
157
-
158
-			return new CachedBool( $isSubclass, Metadata::blank() );
159
-		} catch ( OverflowException $e ) {
160
-			$timing->setLabel( 'result', 'overflow' )
161
-				->copyToStatsdAt( 'wikibase.quality.constraints.type.php.overflow.timing' )
152
+			$this->statsFactory->getTiming('isSubclassOf_entities_total')
153
+				->setLabel('TypeCheckerImplementation', 'php')
154
+				->setLabel('result', 'success')
155
+				->copyToStatsdAt('wikibase.quality.constraints.type.php.success.entities')
156
+				->observe($entitiesChecked);
157
+
158
+			return new CachedBool($isSubclass, Metadata::blank());
159
+		} catch (OverflowException $e) {
160
+			$timing->setLabel('result', 'overflow')
161
+				->copyToStatsdAt('wikibase.quality.constraints.type.php.overflow.timing')
162 162
 				->stop();
163 163
 
164
-			if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) {
165
-				$this->statsFactory->getCounter( 'sparql_typeFallback_total' )
166
-					->copyToStatsdAt( 'wikibase.quality.constraints.sparql.typeFallback' )
164
+			if (!($this->sparqlHelper instanceof DummySparqlHelper)) {
165
+				$this->statsFactory->getCounter('sparql_typeFallback_total')
166
+					->copyToStatsdAt('wikibase.quality.constraints.sparql.typeFallback')
167 167
 					->increment();
168 168
 
169
-				$timing->setLabel( 'TypeCheckerImplementation', 'sparql' )
170
-					->setLabel( 'result', 'success' )
171
-					->copyToStatsdAt( 'wikibase.quality.constraints.type.sparql.success.timing' )
169
+				$timing->setLabel('TypeCheckerImplementation', 'sparql')
170
+					->setLabel('result', 'success')
171
+					->copyToStatsdAt('wikibase.quality.constraints.type.sparql.success.timing')
172 172
 					->start();
173 173
 
174 174
 				$hasType = $this->sparqlHelper->hasType(
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 
181 181
 				return $hasType;
182 182
 			} else {
183
-				return new CachedBool( false, Metadata::blank() );
183
+				return new CachedBool(false, Metadata::blank());
184 184
 			}
185 185
 		}
186 186
 	}
@@ -198,13 +198,13 @@  discard block
 block discarded – undo
198 198
 	 * @return CachedBool
199 199
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
200 200
 	 */
201
-	public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) {
201
+	public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) {
202 202
 		$metadatas = [];
203 203
 
204
-		foreach ( $this->getBestStatementsByPropertyIds( $statements, $relationIds ) as $statement ) {
204
+		foreach ($this->getBestStatementsByPropertyIds($statements, $relationIds) as $statement) {
205 205
 			$mainSnak = $statement->getMainSnak();
206 206
 
207
-			if ( !$this->hasCorrectType( $mainSnak ) ) {
207
+			if (!$this->hasCorrectType($mainSnak)) {
208 208
 				continue;
209 209
 			}
210 210
 			/** @var PropertyValueSnak $mainSnak */
@@ -214,24 +214,24 @@  discard block
 block discarded – undo
214 214
 			'@phan-var EntityIdValue $dataValue';
215 215
 			$comparativeClass = $dataValue->getEntityId();
216 216
 
217
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
217
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
218 218
 				// discard $metadatas, we know this is fresh
219
-				return new CachedBool( true, Metadata::blank() );
219
+				return new CachedBool(true, Metadata::blank());
220 220
 			}
221 221
 
222
-			$result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck );
222
+			$result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck);
223 223
 			$metadatas[] = $result->getMetadata();
224
-			if ( $result->getBool() ) {
224
+			if ($result->getBool()) {
225 225
 				return new CachedBool(
226 226
 					true,
227
-					Metadata::merge( $metadatas )
227
+					Metadata::merge($metadatas)
228 228
 				);
229 229
 			}
230 230
 		}
231 231
 
232 232
 		return new CachedBool(
233 233
 			false,
234
-			Metadata::merge( $metadatas )
234
+			Metadata::merge($metadatas)
235 235
 		);
236 236
 	}
237 237
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 * @return bool
241 241
 	 * @phan-assert PropertyValueSnak $mainSnak
242 242
 	 */
243
-	private function hasCorrectType( Snak $mainSnak ) {
243
+	private function hasCorrectType(Snak $mainSnak) {
244 244
 		return $mainSnak instanceof PropertyValueSnak
245 245
 			&& $mainSnak->getDataValue()->getType() === 'wikibase-entityid';
246 246
 	}
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
 	) {
258 258
 		$statementArrays = [];
259 259
 
260
-		foreach ( $propertyIdSerializations as $propertyIdSerialization ) {
261
-			$propertyId = new NumericPropertyId( $propertyIdSerialization );
260
+		foreach ($propertyIdSerializations as $propertyIdSerialization) {
261
+			$propertyId = new NumericPropertyId($propertyIdSerialization);
262 262
 			$statementArrays[] = $statements
263
-				->getByPropertyId( $propertyId )
263
+				->getByPropertyId($propertyId)
264 264
 				->getBestStatements()
265 265
 				->toArray();
266 266
 		}
267 267
 
268
-		return array_merge( ...$statementArrays );
268
+		return array_merge(...$statementArrays);
269 269
 	}
270 270
 
271 271
 	/**
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 		$relation
286 286
 	) {
287 287
 		$classes = array_map(
288
-			static function ( $itemIdSerialization ) {
289
-				return new ItemId( $itemIdSerialization );
288
+			static function($itemIdSerialization) {
289
+				return new ItemId($itemIdSerialization);
290 290
 			},
291 291
 			$classes
292 292
 		);
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
 		// wbqc-violation-message-valueType-instance
299 299
 		// wbqc-violation-message-valueType-subclass
300 300
 		// wbqc-violation-message-valueType-instanceOrSubclass
301
-		return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) )
302
-			->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY )
303
-			->withEntityId( $entityId, Role::SUBJECT )
304
-			->withEntityIdList( $classes, Role::OBJECT );
301
+		return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation))
302
+			->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY)
303
+			->withEntityId($entityId, Role::SUBJECT)
304
+			->withEntityIdList($classes, Role::OBJECT);
305 305
 	}
306 306
 
307 307
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/MultilingualTextViolationMessageRenderer.php 1 patch
Spacing   +21 added lines, -21 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\ConstraintCheck\Message;
6 6
 
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 		'wbqc-violation-message-format-clarification' => 'wbqc-violation-message-format',
29 29
 	];
30 30
 
31
-	public function render( ViolationMessage $violationMessage ): string {
32
-		if ( !array_key_exists( $violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS ) ) {
33
-			return parent::render( $violationMessage );
31
+	public function render(ViolationMessage $violationMessage): string {
32
+		if (!array_key_exists($violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS)) {
33
+			return parent::render($violationMessage);
34 34
 		}
35 35
 
36 36
 		$arguments = $violationMessage->getArguments();
37
-		$multilingualTextArgument = array_pop( $arguments );
37
+		$multilingualTextArgument = array_pop($arguments);
38 38
 		$multilingualTextParams = $this->renderMultilingualText(
39 39
 			// @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue
40 40
 			$multilingualTextArgument['value'],
@@ -42,22 +42,22 @@  discard block
 block discarded – undo
42 42
 			$multilingualTextArgument['role']
43 43
 		);
44 44
 
45
-		$paramsLists = [ [] ];
46
-		foreach ( $arguments as $argument ) {
47
-			$paramsLists[] = $this->renderArgument( $argument );
45
+		$paramsLists = [[]];
46
+		foreach ($arguments as $argument) {
47
+			$paramsLists[] = $this->renderArgument($argument);
48 48
 		}
49
-		$regularParams = array_merge( ...$paramsLists );
49
+		$regularParams = array_merge(...$paramsLists);
50 50
 
51
-		if ( $multilingualTextParams === null ) {
51
+		if ($multilingualTextParams === null) {
52 52
 			return $this->messageLocalizer
53
-				->msg( self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()] )
54
-				->params( $regularParams )
53
+				->msg(self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()])
54
+				->params($regularParams)
55 55
 				->escaped();
56 56
 		} else {
57 57
 			return $this->messageLocalizer
58
-				->msg( $violationMessage->getMessageKey() )
59
-				->params( $regularParams )
60
-				->params( $multilingualTextParams )
58
+				->msg($violationMessage->getMessageKey())
59
+				->params($regularParams)
60
+				->params($multilingualTextParams)
61 61
 				->escaped();
62 62
 		}
63 63
 	}
@@ -68,14 +68,14 @@  discard block
 block discarded – undo
68 68
 	 * @return MessageParam[]|null list of parameters as accepted by Message::params(),
69 69
 	 * or null if the text is not available in the user’s language
70 70
 	 */
71
-	protected function renderMultilingualText( MultilingualTextValue $text, ?string $role ): ?array {
71
+	protected function renderMultilingualText(MultilingualTextValue $text, ?string $role): ?array {
72 72
 		$texts = $text->getTexts();
73
-		foreach ( $this->languageFallbackChain->getFetchLanguageCodes() as $languageCode ) {
74
-			if ( array_key_exists( $languageCode, $texts ) ) {
75
-				return [ Message::rawParam( $this->addRole(
76
-					htmlspecialchars( $texts[$languageCode]->getText() ),
73
+		foreach ($this->languageFallbackChain->getFetchLanguageCodes() as $languageCode) {
74
+			if (array_key_exists($languageCode, $texts)) {
75
+				return [Message::rawParam($this->addRole(
76
+					htmlspecialchars($texts[$languageCode]->getText()),
77 77
 					$role
78
-				) ) ];
78
+				))];
79 79
 			}
80 80
 		}
81 81
 
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.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\ConstraintCheck\Message;
6 6
 
@@ -67,17 +67,17 @@  discard block
 block discarded – undo
67 67
 		$this->maxListLength = $maxListLength;
68 68
 	}
69 69
 
70
-	public function render( ViolationMessage $violationMessage ): string {
70
+	public function render(ViolationMessage $violationMessage): string {
71 71
 		$messageKey = $violationMessage->getMessageKey();
72
-		$paramsLists = [ [] ];
73
-		foreach ( $violationMessage->getArguments() as $argument ) {
74
-			$params = $this->renderArgument( $argument );
72
+		$paramsLists = [[]];
73
+		foreach ($violationMessage->getArguments() as $argument) {
74
+			$params = $this->renderArgument($argument);
75 75
 			$paramsLists[] = $params;
76 76
 		}
77
-		$allParams = array_merge( ...$paramsLists );
77
+		$allParams = array_merge(...$paramsLists);
78 78
 		return $this->messageLocalizer
79
-			->msg( $messageKey )
80
-			->params( $allParams )
79
+			->msg($messageKey)
80
+			->params($allParams)
81 81
 			->escaped();
82 82
 	}
83 83
 
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
 	 * @param string|null $role one of the Role::* constants
87 87
 	 * @return string HTML
88 88
 	 */
89
-	protected function addRole( string $value, ?string $role ): string {
90
-		if ( $role === null ) {
89
+	protected function addRole(string $value, ?string $role): string {
90
+		if ($role === null) {
91 91
 			return $value;
92 92
 		}
93 93
 
94
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
95
-			$value .
94
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
95
+			$value.
96 96
 			'</span>';
97 97
 	}
98 98
 
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 	 * @param string $key message key
101 101
 	 * @return string HTML
102 102
 	 */
103
-	protected function msgEscaped( string $key ): string {
104
-		return $this->messageLocalizer->msg( $key )->escaped();
103
+	protected function msgEscaped(string $key): string {
104
+		return $this->messageLocalizer->msg($key)->escaped();
105 105
 	}
106 106
 
107 107
 	/**
108 108
 	 * @param array $argument
109 109
 	 * @return MessageParam[] params (for Message::params)
110 110
 	 */
111
-	protected function renderArgument( array $argument ): array {
111
+	protected function renderArgument(array $argument): array {
112 112
 		$methods = [
113 113
 			ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId',
114 114
 			ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList',
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		$value = $argument['value'];
130 130
 		$role = $argument['role'];
131 131
 
132
-		if ( array_key_exists( $type, $methods ) ) {
132
+		if (array_key_exists($type, $methods)) {
133 133
 			$method = $methods[$type];
134
-			$params = $this->$method( $value, $role );
134
+			$params = $this->$method($value, $role);
135 135
 		} else {
136 136
 			throw new InvalidArgumentException(
137
-				'Unknown ViolationMessage argument type ' . $type . '!'
137
+				'Unknown ViolationMessage argument type '.$type.'!'
138 138
 			);
139 139
 		}
140 140
 
@@ -148,36 +148,36 @@  discard block
 block discarded – undo
148 148
 	 * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ])
149 149
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
150 150
 	 */
151
-	private function renderList( array $list, ?string $role, callable $render ): array {
152
-		if ( $list === [] ) {
151
+	private function renderList(array $list, ?string $role, callable $render): array {
152
+		if ($list === []) {
153 153
 			return [
154
-				Message::numParam( 0 ),
155
-				Message::rawParam( '<ul></ul>' ),
154
+				Message::numParam(0),
155
+				Message::rawParam('<ul></ul>'),
156 156
 			];
157 157
 		}
158 158
 
159
-		if ( count( $list ) > $this->maxListLength ) {
160
-			$list = array_slice( $list, 0, $this->maxListLength );
159
+		if (count($list) > $this->maxListLength) {
160
+			$list = array_slice($list, 0, $this->maxListLength);
161 161
 			$truncated = true;
162 162
 		}
163 163
 
164 164
 		$renderedParamsLists = array_map(
165 165
 			$render,
166 166
 			$list,
167
-			array_fill( 0, count( $list ), $role )
167
+			array_fill(0, count($list), $role)
168 168
 		);
169
-		$renderedParams = array_column( $renderedParamsLists, 0 );
170
-		$renderedElements = array_map( static fn ( MessageParam $msg ) => $msg->getValue(), $renderedParams );
171
-		if ( isset( $truncated ) ) {
172
-			$renderedElements[] = $this->msgEscaped( 'ellipsis' );
169
+		$renderedParams = array_column($renderedParamsLists, 0);
170
+		$renderedElements = array_map(static fn (MessageParam $msg) => $msg->getValue(), $renderedParams);
171
+		if (isset($truncated)) {
172
+			$renderedElements[] = $this->msgEscaped('ellipsis');
173 173
 		}
174 174
 
175 175
 		return array_merge(
176 176
 			[
177
-				Message::numParam( count( $list ) ),
177
+				Message::numParam(count($list)),
178 178
 				Message::rawParam(
179
-					'<ul><li>' .
180
-					implode( '</li><li>', $renderedElements ) .
179
+					'<ul><li>'.
180
+					implode('</li><li>', $renderedElements).
181 181
 					'</li></ul>'
182 182
 				),
183 183
 			],
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
 	 * @param string|null $role one of the Role::* constants
191 191
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
192 192
 	 */
193
-	private function renderEntityId( EntityId $entityId, ?string $role ): array {
194
-		return [ Message::rawParam( $this->addRole(
195
-			$this->entityIdFormatter->formatEntityId( $entityId ),
193
+	private function renderEntityId(EntityId $entityId, ?string $role): array {
194
+		return [Message::rawParam($this->addRole(
195
+			$this->entityIdFormatter->formatEntityId($entityId),
196 196
 			$role
197
-		) ) ];
197
+		))];
198 198
 	}
199 199
 
200 200
 	/**
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 	 * @param string|null $role one of the Role::* constants
203 203
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
204 204
 	 */
205
-	private function renderEntityIdList( array $entityIdList, ?string $role ): array {
206
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
205
+	private function renderEntityIdList(array $entityIdList, ?string $role): array {
206
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
207 207
 	}
208 208
 
209 209
 	/**
@@ -211,24 +211,24 @@  discard block
 block discarded – undo
211 211
 	 * @param string|null $role one of the Role::* constants
212 212
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
213 213
 	 */
214
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, ?string $role ): array {
215
-		switch ( true ) {
214
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, ?string $role): array {
215
+		switch (true) {
216 216
 			case $value->isValue():
217
-				return $this->renderEntityId( $value->getItemId(), $role );
217
+				return $this->renderEntityId($value->getItemId(), $role);
218 218
 			case $value->isSomeValue():
219
-				return [ Message::rawParam( $this->addRole(
220
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
221
-						$this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) .
219
+				return [Message::rawParam($this->addRole(
220
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
221
+						$this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue').
222 222
 						'</span>',
223 223
 					$role
224
-				) ) ];
224
+				))];
225 225
 			case $value->isNoValue():
226
-				return [ Message::rawParam( $this->addRole(
227
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
228
-					$this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) .
226
+				return [Message::rawParam($this->addRole(
227
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
228
+					$this->msgEscaped('wikibase-snakview-snaktypeselector-novalue').
229 229
 						'</span>',
230 230
 					$role
231
-				) ) ];
231
+				))];
232 232
 			default:
233 233
 				// @codeCoverageIgnoreStart
234 234
 				throw new LogicException(
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
 	 * @param string|null $role one of the Role::* constants
244 244
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
245 245
 	 */
246
-	private function renderItemIdSnakValueList( array $valueList, ?string $role ): array {
247
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
246
+	private function renderItemIdSnakValueList(array $valueList, ?string $role): array {
247
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
248 248
 	}
249 249
 
250 250
 	/**
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
 	 * @param string|null $role one of the Role::* constants
253 253
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
254 254
 	 */
255
-	private function renderDataValue( DataValue $dataValue, ?string $role ): array {
256
-		return [ Message::rawParam( $this->addRole(
257
-			$this->dataValueFormatter->format( $dataValue ),
255
+	private function renderDataValue(DataValue $dataValue, ?string $role): array {
256
+		return [Message::rawParam($this->addRole(
257
+			$this->dataValueFormatter->format($dataValue),
258 258
 			$role
259
-		) ) ];
259
+		))];
260 260
 	}
261 261
 
262 262
 	/**
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	 * @param string|null $role one of the Role::* constants
265 265
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
266 266
 	 */
267
-	private function renderDataValueType( string $dataValueType, ?string $role ): array {
267
+	private function renderDataValueType(string $dataValueType, ?string $role): array {
268 268
 		$messageKeys = [
269 269
 			'string' => 'datatypes-type-string',
270 270
 			'monolingualtext' => 'datatypes-type-monolingualtext',
@@ -273,15 +273,15 @@  discard block
 block discarded – undo
273 273
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
274 274
 		];
275 275
 
276
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
277
-			return [ Message::rawParam( $this->addRole(
278
-				$this->msgEscaped( $messageKeys[$dataValueType] ),
276
+		if (array_key_exists($dataValueType, $messageKeys)) {
277
+			return [Message::rawParam($this->addRole(
278
+				$this->msgEscaped($messageKeys[$dataValueType]),
279 279
 				$role
280
-			) ) ];
280
+			))];
281 281
 		} else {
282 282
 			// @codeCoverageIgnoreStart
283 283
 			throw new LogicException(
284
-				'Unknown data value type ' . $dataValueType
284
+				'Unknown data value type '.$dataValueType
285 285
 			);
286 286
 			// @codeCoverageIgnoreEnd
287 287
 		}
@@ -292,11 +292,11 @@  discard block
 block discarded – undo
292 292
 	 * @param string|null $role one of the Role::* constants
293 293
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
294 294
 	 */
295
-	private function renderInlineCode( string $code, ?string $role ): array {
296
-		return [ Message::rawParam( $this->addRole(
297
-			'<code>' . htmlspecialchars( $code ) . '</code>',
295
+	private function renderInlineCode(string $code, ?string $role): array {
296
+		return [Message::rawParam($this->addRole(
297
+			'<code>'.htmlspecialchars($code).'</code>',
298 298
 			$role
299
-		) ) ];
299
+		))];
300 300
 	}
301 301
 
302 302
 	/**
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 	 * @param string|null $role one of the Role::* constants
305 305
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
306 306
 	 */
307
-	private function renderConstraintScope( string $scope, ?string $role ): array {
308
-		switch ( $scope ) {
307
+	private function renderConstraintScope(string $scope, ?string $role): array {
308
+		switch ($scope) {
309 309
 			case Context::TYPE_STATEMENT:
310 310
 				$itemId = $this->config->get(
311 311
 					'WBQualityConstraintsConstraintCheckedOnMainValueId'
@@ -325,10 +325,10 @@  discard block
 block discarded – undo
325 325
 				// callers should never let this happen, but if it does happen,
326 326
 				// showing “unknown value” seems reasonable
327 327
 				// @codeCoverageIgnoreStart
328
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
328
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
329 329
 				// @codeCoverageIgnoreEnd
330 330
 		}
331
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
331
+		return $this->renderEntityId(new ItemId($itemId), $role);
332 332
 	}
333 333
 
334 334
 	/**
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
 	 * @param string|null $role one of the Role::* constants
337 337
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
338 338
 	 */
339
-	private function renderConstraintScopeList( array $scopeList, ?string $role ): array {
340
-		return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] );
339
+	private function renderConstraintScopeList(array $scopeList, ?string $role): array {
340
+		return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']);
341 341
 	}
342 342
 
343 343
 	/**
@@ -345,25 +345,25 @@  discard block
 block discarded – undo
345 345
 	 * @param string|null $role one of the Role::* constants
346 346
 	 * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
347 347
 	 */
348
-	private function renderPropertyScope( string $scope, ?string $role ): array {
349
-		switch ( $scope ) {
348
+	private function renderPropertyScope(string $scope, ?string $role): array {
349
+		switch ($scope) {
350 350
 			case Context::TYPE_STATEMENT:
351
-				$itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' );
351
+				$itemId = $this->config->get('WBQualityConstraintsAsMainValueId');
352 352
 				break;
353 353
 			case Context::TYPE_QUALIFIER:
354
-				$itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' );
354
+				$itemId = $this->config->get('WBQualityConstraintsAsQualifiersId');
355 355
 				break;
356 356
 			case Context::TYPE_REFERENCE:
357
-				$itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' );
357
+				$itemId = $this->config->get('WBQualityConstraintsAsReferencesId');
358 358
 				break;
359 359
 			default:
360 360
 				// callers should never let this happen, but if it does happen,
361 361
 				// showing “unknown value” seems reasonable
362 362
 				// @codeCoverageIgnoreStart
363
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
363
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
364 364
 				// @codeCoverageIgnoreEnd
365 365
 		}
366
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
366
+		return $this->renderEntityId(new ItemId($itemId), $role);
367 367
 	}
368 368
 
369 369
 	/**
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 	 * @param string|null $role one of the Role::* constants
372 372
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
373 373
 	 */
374
-	private function renderPropertyScopeList( array $scopeList, ?string $role ): array {
375
-		return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] );
374
+	private function renderPropertyScopeList(array $scopeList, ?string $role): array {
375
+		return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']);
376 376
 	}
377 377
 
378 378
 	/**
@@ -380,14 +380,14 @@  discard block
 block discarded – undo
380 380
 	 * @param string|null $role one of the Role::* constants
381 381
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
382 382
 	 */
383
-	private function renderLanguage( string $languageCode, ?string $role ): array {
383
+	private function renderLanguage(string $languageCode, ?string $role): array {
384 384
 		return [
385 385
 			// ::renderList (through ::renderLanguageList) requires 'raw' parameter
386 386
 			// so we effectively build Message::plaintextParam here
387
-			Message::rawParam( htmlspecialchars(
388
-				$this->languageNameUtils->getLanguageName( $languageCode, $this->userLanguageCode )
389
-			) ),
390
-			Message::plaintextParam( $languageCode ),
387
+			Message::rawParam(htmlspecialchars(
388
+				$this->languageNameUtils->getLanguageName($languageCode, $this->userLanguageCode)
389
+			)),
390
+			Message::plaintextParam($languageCode),
391 391
 		];
392 392
 	}
393 393
 
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
 	 * @param string|null $role one of the Role::* constants
397 397
 	 * @return MessageParam[] list of parameters as accepted by Message::params()
398 398
 	 */
399
-	private function renderLanguageList( array $languageCodes, ?string $role ): array {
400
-		return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] );
399
+	private function renderLanguageList(array $languageCodes, ?string $role): array {
400
+		return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']);
401 401
 	}
402 402
 
403 403
 }
Please login to merge, or discard this patch.
maintenance/ImportConstraintStatements.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@  discard block
 block discarded – undo
10 10
 use WikibaseQuality\ConstraintReport\Job\UpdateConstraintsTableJob;
11 11
 
12 12
 // @codeCoverageIgnoreStart
13
-$basePath = getenv( "MW_INSTALL_PATH" ) !== false
14
-	? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../..";
13
+$basePath = getenv("MW_INSTALL_PATH") !== false
14
+	? getenv("MW_INSTALL_PATH") : __DIR__."/../../..";
15 15
 
16
-require_once $basePath . "/maintenance/Maintenance.php";
16
+require_once $basePath."/maintenance/Maintenance.php";
17 17
 // @codeCoverageIgnoreEnd
18 18
 
19 19
 /**
@@ -42,56 +42,56 @@  discard block
 block discarded – undo
42 42
 
43 43
 	public function __construct() {
44 44
 		parent::__construct();
45
-		$this->newUpdateConstraintsTableJob = static function ( $propertyIdSerialization ) {
45
+		$this->newUpdateConstraintsTableJob = static function($propertyIdSerialization) {
46 46
 			return UpdateConstraintsTableJob::newFromGlobalState(
47 47
 				Title::newMainPage(),
48
-				[ 'propertyId' => $propertyIdSerialization ]
48
+				['propertyId' => $propertyIdSerialization]
49 49
 			);
50 50
 		};
51 51
 
52
-		$this->addDescription( 'Imports property constraints from statements on properties' );
53
-		$this->requireExtension( 'WikibaseQualityConstraints' );
54
-		$this->setBatchSize( 10 );
52
+		$this->addDescription('Imports property constraints from statements on properties');
53
+		$this->requireExtension('WikibaseQualityConstraints');
54
+		$this->setBatchSize(10);
55 55
 
56 56
 		// Wikibase classes are not yet loaded, so setup services in a callback run in execute
57 57
 		// that can be overridden in tests.
58
-		$this->setupServices = function () {
58
+		$this->setupServices = function() {
59 59
 			$services = MediaWikiServices::getInstance();
60
-			$this->propertyInfoLookup = WikibaseRepo::getStore( $services )->getPropertyInfoLookup();
60
+			$this->propertyInfoLookup = WikibaseRepo::getStore($services)->getPropertyInfoLookup();
61 61
 		};
62 62
 	}
63 63
 
64 64
 	public function execute() {
65
-		( $this->setupServices )();
66
-		if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) {
67
-			$this->error( 'Constraint statements are not enabled. Aborting.' );
65
+		($this->setupServices)();
66
+		if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) {
67
+			$this->error('Constraint statements are not enabled. Aborting.');
68 68
 			return;
69 69
 		}
70 70
 
71 71
 		$propertyInfos = $this->propertyInfoLookup->getAllPropertyInfo();
72
-		$propertyIds = array_keys( $propertyInfos );
72
+		$propertyIds = array_keys($propertyInfos);
73 73
 
74
-		foreach ( array_chunk( $propertyIds, $this->getBatchSize() ) as $propertyIdsChunk ) {
75
-			foreach ( $propertyIdsChunk as $propertyIdSerialization ) {
76
-				$this->output( sprintf(
74
+		foreach (array_chunk($propertyIds, $this->getBatchSize()) as $propertyIdsChunk) {
75
+			foreach ($propertyIdsChunk as $propertyIdSerialization) {
76
+				$this->output(sprintf(
77 77
 					'Importing constraint statements for % 6s... ',
78 78
 					$propertyIdSerialization ),
79 79
 					$propertyIdSerialization
80 80
 				);
81
-				$startTime = microtime( true );
82
-				$job = ( $this->newUpdateConstraintsTableJob )( $propertyIdSerialization );
81
+				$startTime = microtime(true);
82
+				$job = ($this->newUpdateConstraintsTableJob)($propertyIdSerialization);
83 83
 				$job->run();
84
-				$endTime = microtime( true );
85
-				$millis = ( $endTime - $startTime ) * 1000;
86
-				$this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization );
84
+				$endTime = microtime(true);
85
+				$millis = ($endTime - $startTime) * 1000;
86
+				$this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization);
87 87
 			}
88 88
 
89
-			$this->output( 'Waiting for replication... ', 'waitForReplication' );
90
-			$startTime = microtime( true );
89
+			$this->output('Waiting for replication... ', 'waitForReplication');
90
+			$startTime = microtime(true);
91 91
 			$this->waitForReplication();
92
-			$endTime = microtime( true );
93
-			$millis = ( $endTime - $startTime ) * 1000;
94
-			$this->output( sprintf( 'done in % 6.2f ms.', $millis ), 'waitForReplication' );
92
+			$endTime = microtime(true);
93
+			$millis = ($endTime - $startTime) * 1000;
94
+			$this->output(sprintf('done in % 6.2f ms.', $millis), 'waitForReplication');
95 95
 		}
96 96
 	}
97 97
 
Please login to merge, or discard this patch.
src/Api/CachingResultsSource.php 1 patch
Spacing   +77 added lines, -78 removed lines patch added patch discarded remove patch
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 	) {
144 144
 		$results = [];
145 145
 		$metadatas = [];
146
-		if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) {
146
+		if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) {
147 147
 			$storedEntityIds = [];
148
-			foreach ( $entityIds as $entityId ) {
149
-				$storedResults = $this->getStoredResults( $entityId );
150
-				if ( $storedResults !== null ) {
151
-					$this->loggingHelper->logCheckConstraintsCacheHit( $entityId );
152
-					foreach ( $storedResults->getArray() as $checkResult ) {
153
-						if ( $this->statusSelected( $statuses, $checkResult ) ) {
148
+			foreach ($entityIds as $entityId) {
149
+				$storedResults = $this->getStoredResults($entityId);
150
+				if ($storedResults !== null) {
151
+					$this->loggingHelper->logCheckConstraintsCacheHit($entityId);
152
+					foreach ($storedResults->getArray() as $checkResult) {
153
+						if ($this->statusSelected($statuses, $checkResult)) {
154 154
 							$results[] = $checkResult;
155 155
 						}
156 156
 					}
@@ -158,19 +158,19 @@  discard block
 block discarded – undo
158 158
 					$storedEntityIds[] = $entityId;
159 159
 				}
160 160
 			}
161
-			$entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) );
161
+			$entityIds = array_values(array_diff($entityIds, $storedEntityIds));
162 162
 		}
163
-		if ( $entityIds !== [] || $claimIds !== [] ) {
164
-			if ( $entityIds !== [] ) {
165
-				$this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds );
163
+		if ($entityIds !== [] || $claimIds !== []) {
164
+			if ($entityIds !== []) {
165
+				$this->loggingHelper->logCheckConstraintsCacheMisses($entityIds);
166 166
 			}
167
-			$response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses );
168
-			$results = array_merge( $results, $response->getArray() );
167
+			$response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses);
168
+			$results = array_merge($results, $response->getArray());
169 169
 			$metadatas[] = $response->getMetadata();
170 170
 		}
171 171
 		return new CachedCheckResults(
172 172
 			$results,
173
-			Metadata::merge( $metadatas )
173
+			Metadata::merge($metadatas)
174 174
 		);
175 175
 	}
176 176
 
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
 		?array $constraintIds,
194 194
 		array $statuses
195 195
 	) {
196
-		if ( $claimIds !== [] ) {
196
+		if ($claimIds !== []) {
197 197
 			return false;
198 198
 		}
199
-		if ( $constraintIds !== null ) {
199
+		if ($constraintIds !== null) {
200 200
 			return false;
201 201
 		}
202
-		if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) {
202
+		if (array_diff($statuses, self::CACHED_STATUSES) !== []) {
203 203
 			return false;
204 204
 		}
205 205
 		return true;
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 	 * @param CheckResult $result
215 215
 	 * @return bool
216 216
 	 */
217
-	private function statusSelected( array $statuses, CheckResult $result ) {
218
-		return in_array( $result->getStatus(), $statuses, true ) ||
217
+	private function statusSelected(array $statuses, CheckResult $result) {
218
+		return in_array($result->getStatus(), $statuses, true) ||
219 219
 			$result instanceof NullResult;
220 220
 	}
221 221
 
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
 		?array $constraintIds,
233 233
 		array $statuses
234 234
 	) {
235
-		$results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses );
235
+		$results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses);
236 236
 
237
-		if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) {
238
-			foreach ( $entityIds as $entityId ) {
239
-				$this->storeResults( $entityId, $results );
237
+		if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) {
238
+			foreach ($entityIds as $entityId) {
239
+				$this->storeResults($entityId, $results);
240 240
 			}
241 241
 		}
242 242
 
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
 		?array $constraintIds,
268 268
 		array $statuses
269 269
 	) {
270
-		if ( $constraintIds !== null ) {
270
+		if ($constraintIds !== null) {
271 271
 			return false;
272 272
 		}
273
-		if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) {
273
+		if (array_diff(self::CACHED_STATUSES, $statuses) !== []) {
274 274
 			return false;
275 275
 		}
276 276
 		return true;
@@ -284,21 +284,21 @@  discard block
 block discarded – undo
284 284
 	 * May include check results for other entity IDs as well,
285 285
 	 * or check results with statuses that we’re not interested in caching.
286 286
 	 */
287
-	private function storeResults( EntityId $entityId, CachedCheckResults $results ) {
287
+	private function storeResults(EntityId $entityId, CachedCheckResults $results) {
288 288
 		$latestRevisionIds = $this->getLatestRevisionIds(
289 289
 			$results->getMetadata()->getDependencyMetadata()->getEntityIds()
290 290
 		);
291
-		if ( $latestRevisionIds === null ) {
291
+		if ($latestRevisionIds === null) {
292 292
 			return;
293 293
 		}
294 294
 
295 295
 		$resultSerializations = [];
296
-		foreach ( $results->getArray() as $checkResult ) {
297
-			if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) {
296
+		foreach ($results->getArray() as $checkResult) {
297
+			if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) {
298 298
 				continue;
299 299
 			}
300
-			if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) {
301
-				$resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult );
300
+			if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) {
301
+				$resultSerializations[] = $this->checkResultSerializer->serialize($checkResult);
302 302
 			}
303 303
 		}
304 304
 
@@ -307,11 +307,11 @@  discard block
 block discarded – undo
307 307
 			'latestRevisionIds' => $latestRevisionIds,
308 308
 		];
309 309
 		$futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime();
310
-		if ( $futureTime !== null ) {
310
+		if ($futureTime !== null) {
311 311
 			$value['futureTime'] = $futureTime->getArrayValue();
312 312
 		}
313 313
 
314
-		$this->cache->set( $entityId, $value, $this->ttlInSeconds );
314
+		$this->cache->set($entityId, $value, $this->ttlInSeconds);
315 315
 	}
316 316
 
317 317
 	/**
@@ -326,33 +326,32 @@  discard block
 block discarded – undo
326 326
 		$forRevision = 0
327 327
 	) {
328 328
 		$cacheInfo = WANObjectCache::PASS_BY_REF;
329
-		$value = $this->cache->get( $entityId, $curTTL, [], $cacheInfo );
330
-		$now = ( $this->microtime )( true );
329
+		$value = $this->cache->get($entityId, $curTTL, [], $cacheInfo);
330
+		$now = ($this->microtime)(true);
331 331
 
332
-		$dependencyMetadata = $this->checkDependencyMetadata( $value,
333
-			[ $entityId->getSerialization() => $forRevision ] );
334
-		if ( $dependencyMetadata === null ) {
332
+		$dependencyMetadata = $this->checkDependencyMetadata($value,
333
+			[$entityId->getSerialization() => $forRevision]);
334
+		if ($dependencyMetadata === null) {
335 335
 			return null;
336 336
 		}
337 337
 
338 338
 		// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
339 339
 		$asOf = $cacheInfo[WANObjectCache::KEY_AS_OF];
340
-		$ageInSeconds = (int)ceil( $now - $asOf );
340
+		$ageInSeconds = (int) ceil($now - $asOf);
341 341
 		$cachingMetadata = $ageInSeconds > 0 ?
342
-			CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) :
343
-			CachingMetadata::fresh();
342
+			CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh();
344 343
 
345 344
 		$results = [];
346
-		foreach ( $value['results'] as $resultSerialization ) {
347
-			$results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata );
345
+		foreach ($value['results'] as $resultSerialization) {
346
+			$results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata);
348 347
 		}
349 348
 
350 349
 		return new CachedCheckResults(
351 350
 			$results,
352
-			Metadata::merge( [
353
-				Metadata::ofCachingMetadata( $cachingMetadata ),
354
-				Metadata::ofDependencyMetadata( $dependencyMetadata ),
355
-			] )
351
+			Metadata::merge([
352
+				Metadata::ofCachingMetadata($cachingMetadata),
353
+				Metadata::ofDependencyMetadata($dependencyMetadata),
354
+			])
356 355
 		);
357 356
 	}
358 357
 
@@ -368,43 +367,43 @@  discard block
 block discarded – undo
368 367
 	 * @return DependencyMetadata|null the dependency metadata,
369 368
 	 * or null if $value should no longer be used
370 369
 	 */
371
-	private function checkDependencyMetadata( $value, $paramRevs ) {
372
-		if ( $value === false ) {
370
+	private function checkDependencyMetadata($value, $paramRevs) {
371
+		if ($value === false) {
373 372
 			return null;
374 373
 		}
375 374
 
376
-		if ( array_key_exists( 'futureTime', $value ) ) {
377
-			$futureTime = TimeValue::newFromArray( $value['futureTime'] );
378
-			if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) {
375
+		if (array_key_exists('futureTime', $value)) {
376
+			$futureTime = TimeValue::newFromArray($value['futureTime']);
377
+			if (!$this->timeValueComparer->isFutureTime($futureTime)) {
379 378
 				return null;
380 379
 			}
381
-			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime );
380
+			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime);
382 381
 		} else {
383 382
 			$futureTimeDependencyMetadata = DependencyMetadata::blank();
384 383
 		}
385 384
 
386
-		foreach ( $paramRevs as $id => $revision ) {
387
-			if ( $revision > 0 ) {
388
-				$value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX );
385
+		foreach ($paramRevs as $id => $revision) {
386
+			if ($revision > 0) {
387
+				$value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX);
389 388
 			}
390 389
 		}
391 390
 
392 391
 		$dependedEntityIds = array_map(
393
-			[ $this->entityIdParser, "parse" ],
394
-			array_keys( $value['latestRevisionIds'] )
392
+			[$this->entityIdParser, "parse"],
393
+			array_keys($value['latestRevisionIds'])
395 394
 		);
396 395
 
397
-		if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) {
396
+		if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) {
398 397
 			return null;
399 398
 		}
400 399
 
401 400
 		return array_reduce(
402 401
 			$dependedEntityIds,
403
-			static function ( DependencyMetadata $metadata, EntityId $entityId ) {
404
-				return DependencyMetadata::merge( [
402
+			static function(DependencyMetadata $metadata, EntityId $entityId) {
403
+				return DependencyMetadata::merge([
405 404
 					$metadata,
406
-					DependencyMetadata::ofEntityId( $entityId ),
407
-				] );
405
+					DependencyMetadata::ofEntityId($entityId),
406
+				]);
408 407
 			},
409 408
 			$futureTimeDependencyMetadata
410 409
 		);
@@ -424,13 +423,13 @@  discard block
 block discarded – undo
424 423
 		array $resultSerialization,
425 424
 		CachingMetadata $cachingMetadata
426 425
 	) {
427
-		$result = $this->checkResultDeserializer->deserialize( $resultSerialization );
428
-		if ( $this->isPossiblyStaleResult( $result ) ) {
426
+		$result = $this->checkResultDeserializer->deserialize($resultSerialization);
427
+		if ($this->isPossiblyStaleResult($result)) {
429 428
 			$result->withMetadata(
430
-				Metadata::merge( [
429
+				Metadata::merge([
431 430
 					$result->getMetadata(),
432
-					Metadata::ofCachingMetadata( $cachingMetadata ),
433
-				] )
431
+					Metadata::ofCachingMetadata($cachingMetadata),
432
+				])
434 433
 			);
435 434
 		}
436 435
 		return $result;
@@ -440,8 +439,8 @@  discard block
 block discarded – undo
440 439
 	 * @param CheckResult $result
441 440
 	 * @return bool
442 441
 	 */
443
-	private function isPossiblyStaleResult( CheckResult $result ) {
444
-		if ( $result instanceof NullResult ) {
442
+	private function isPossiblyStaleResult(CheckResult $result) {
443
+		if ($result instanceof NullResult) {
445 444
 			return false;
446 445
 		}
447 446
 
@@ -456,14 +455,14 @@  discard block
 block discarded – undo
456 455
 	 * @return int[]|null array from entity ID serializations to revision ID,
457 456
 	 * or null to indicate that not all revision IDs could be loaded
458 457
 	 */
459
-	private function getLatestRevisionIds( array $entityIds ) {
460
-		if ( $entityIds === [] ) {
458
+	private function getLatestRevisionIds(array $entityIds) {
459
+		if ($entityIds === []) {
461 460
 			$this->loggingHelper->logEmptyDependencyMetadata();
462 461
 			return [];
463 462
 		}
464
-		if ( count( $entityIds ) > $this->maxRevisionIds ) {
463
+		if (count($entityIds) > $this->maxRevisionIds) {
465 464
 			// one of those entities will probably be edited soon, so might as well skip caching
466
-			$this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds );
465
+			$this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds);
467 466
 			return null;
468 467
 		}
469 468
 
@@ -471,7 +470,7 @@  discard block
 block discarded – undo
471 470
 			$entityIds,
472 471
 			LookupConstants::LATEST_FROM_REPLICA
473 472
 		);
474
-		if ( $this->hasFalseElements( $latestRevisionIds ) ) {
473
+		if ($this->hasFalseElements($latestRevisionIds)) {
475 474
 			return null;
476 475
 		}
477 476
 		return $latestRevisionIds;
@@ -481,8 +480,8 @@  discard block
 block discarded – undo
481 480
 	 * @param array $array
482 481
 	 * @return bool
483 482
 	 */
484
-	private function hasFalseElements( array $array ) {
485
-		return in_array( false, $array, true );
483
+	private function hasFalseElements(array $array) {
484
+		return in_array(false, $array, true);
486 485
 	}
487 486
 
488 487
 	/**
@@ -490,7 +489,7 @@  discard block
 block discarded – undo
490 489
 	 *
491 490
 	 * @param callable $microtime
492 491
 	 */
493
-	public function setMicrotimeFunction( callable $microtime ) {
492
+	public function setMicrotimeFunction(callable $microtime) {
494 493
 		$this->microtime = $microtime;
495 494
 	}
496 495
 
Please login to merge, or discard this patch.
src/Api/CheckConstraintsRdf.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		EntityIdLookup $entityIdLookup,
50 50
 		RdfVocabulary $rdfVocabulary
51 51
 	) {
52
-		parent::__construct( $page, $context );
52
+		parent::__construct($page, $context);
53 53
 		$this->resultsSource = $resultsSource;
54 54
 		$this->entityIdLookup = $entityIdLookup;
55 55
 		$this->rdfVocabulary = $rdfVocabulary;
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 	 * @param string $guid
109 109
 	 * @return string
110 110
 	 */
111
-	private function cleanupGuid( $guid ) {
112
-		return preg_replace( '/[^\w-]/', '-', $guid );
111
+	private function cleanupGuid($guid) {
112
+		return preg_replace('/[^\w-]/', '-', $guid);
113 113
 	}
114 114
 
115 115
 	/**
@@ -121,63 +121,63 @@  discard block
 block discarded – undo
121 121
 		$response = $this->getRequest()->response();
122 122
 		$this->getOutput()->disable();
123 123
 
124
-		if ( !$this->resultsSource instanceof CachingResultsSource ) {
124
+		if (!$this->resultsSource instanceof CachingResultsSource) {
125 125
 			// TODO: make configurable whether only cached results are returned
126
-			$response->statusHeader( 501 ); // Not Implemented
126
+			$response->statusHeader(501); // Not Implemented
127 127
 			return null;
128 128
 		}
129 129
 
130
-		$entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() );
131
-		if ( $entityId === null ) {
132
-			$response->statusHeader( 404 ); // Not Found
130
+		$entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle());
131
+		if ($entityId === null) {
132
+			$response->statusHeader(404); // Not Found
133 133
 			return null;
134 134
 		}
135
-		$revId = $this->getRequest()->getInt( 'revision' );
135
+		$revId = $this->getRequest()->getInt('revision');
136 136
 
137
-		$results = $this->resultsSource->getStoredResults( $entityId, $revId );
138
-		if ( $results === null ) {
139
-			$response->statusHeader( 204 ); // No Content
137
+		$results = $this->resultsSource->getStoredResults($entityId, $revId);
138
+		if ($results === null) {
139
+			$response->statusHeader(204); // No Content
140 140
 			return null;
141 141
 		}
142 142
 
143 143
 		$format = 'ttl'; // TODO: make format an option
144 144
 
145 145
 		$writerFactory = new RdfWriterFactory();
146
-		$formatName = $writerFactory->getFormatName( $format );
147
-		$contentType = $writerFactory->getMimeTypes( $formatName )[0];
146
+		$formatName = $writerFactory->getFormatName($format);
147
+		$contentType = $writerFactory->getMimeTypes($formatName)[0];
148 148
 
149
-		$propertyRepo = $this->rdfVocabulary->getEntityRepositoryName( new NumericPropertyId( 'P1' ) );
149
+		$propertyRepo = $this->rdfVocabulary->getEntityRepositoryName(new NumericPropertyId('P1'));
150 150
 		$wds = $this->rdfVocabulary->statementNamespaceNames[$propertyRepo][RdfVocabulary::NS_STATEMENT];
151 151
 
152
-		$writer = $writerFactory->getWriter( $formatName );
153
-		foreach ( [ $wds, RdfVocabulary::NS_ONTOLOGY ] as $ns ) {
154
-			$writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) );
152
+		$writer = $writerFactory->getWriter($formatName);
153
+		foreach ([$wds, RdfVocabulary::NS_ONTOLOGY] as $ns) {
154
+			$writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns));
155 155
 		}
156 156
 		$writer->start();
157 157
 		$writtenAny = false;
158 158
 
159
-		foreach ( $results->getArray() as $checkResult ) {
160
-			if ( $checkResult instanceof NullResult ) {
159
+		foreach ($results->getArray() as $checkResult) {
160
+			if ($checkResult instanceof NullResult) {
161 161
 				continue;
162 162
 			}
163
-			if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) {
163
+			if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) {
164 164
 				continue;
165 165
 			}
166 166
 			$writtenAny = true;
167
-			$writer->about( $wds,
168
-				$this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) )
169
-				->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' )
170
-				->is( $wds,
171
-					$this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) );
167
+			$writer->about($wds,
168
+				$this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid()))
169
+				->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint')
170
+				->is($wds,
171
+					$this->cleanupGuid($checkResult->getConstraint()->getConstraintId()));
172 172
 		}
173 173
 		$writer->finish();
174
-		if ( $writtenAny ) {
175
-			$response->header( "Content-Type: $contentType; charset=UTF-8" );
174
+		if ($writtenAny) {
175
+			$response->header("Content-Type: $contentType; charset=UTF-8");
176 176
 			echo $writer->drain();
177 177
 		} else {
178 178
 			// Do not output RDF if we haven't written any actual statements. Output 204 instead
179 179
 			$writer->drain();
180
-			$response->statusHeader( 204 ); // No Content
180
+			$response->statusHeader(204); // No Content
181 181
 		}
182 182
 		return null;
183 183
 	}
Please login to merge, or discard this patch.
maintenance/ImportConstraintEntities.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
 use Wikibase\Repo\WikibaseRepo;
19 19
 
20 20
 // @codeCoverageIgnoreStart
21
-$basePath = getenv( "MW_INSTALL_PATH" ) !== false
22
-	? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../..";
21
+$basePath = getenv("MW_INSTALL_PATH") !== false
22
+	? getenv("MW_INSTALL_PATH") : __DIR__."/../../..";
23 23
 
24
-require_once $basePath . "/maintenance/Maintenance.php";
24
+require_once $basePath."/maintenance/Maintenance.php";
25 25
 // @codeCoverageIgnoreEnd
26 26
 
27 27
 /**
@@ -60,20 +60,20 @@  discard block
 block discarded – undo
60 60
 		parent::__construct();
61 61
 
62 62
 		$this->addDescription(
63
-			'Import entities needed for constraint checks ' .
63
+			'Import entities needed for constraint checks '.
64 64
 			'from Wikidata into the local repository.'
65 65
 		);
66 66
 		$this->addOption(
67 67
 			'config-format',
68
-			'The format in which the resulting configuration will be omitted: ' .
69
-			'"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' .
68
+			'The format in which the resulting configuration will be omitted: '.
69
+			'"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '.
70 70
 			'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.'
71 71
 		);
72 72
 		$this->addOption(
73 73
 			'dry-run',
74 74
 			'Don’t actually import entities, just print which ones would be imported.'
75 75
 		);
76
-		$this->requireExtension( 'WikibaseQualityConstraints' );
76
+		$this->requireExtension('WikibaseQualityConstraints');
77 77
 	}
78 78
 
79 79
 	/**
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
 	 */
82 82
 	private function setupServices() {
83 83
 		$services = MediaWikiServices::getInstance();
84
-		$this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer( $services );
85
-		$this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer( $services );
86
-		$this->entityStore = WikibaseRepo::getEntityStore( $services );
84
+		$this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer($services);
85
+		$this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer($services);
86
+		$this->entityStore = WikibaseRepo::getEntityStore($services);
87 87
 		$this->httpRequestFactory = $services->getHttpRequestFactory();
88
-		if ( !$this->getOption( 'dry-run', false ) ) {
89
-			$this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' );
88
+		if (!$this->getOption('dry-run', false)) {
89
+			$this->user = User::newSystemUser('WikibaseQualityConstraints importer');
90 90
 		}
91 91
 	}
92 92
 
@@ -95,21 +95,21 @@  discard block
 block discarded – undo
95 95
 
96 96
 		$configUpdates = [];
97 97
 
98
-		$extensionJsonFile = __DIR__ . '/../extension.json';
99
-		$extensionJsonText = file_get_contents( $extensionJsonFile );
100
-		$extensionJson = json_decode( $extensionJsonText, /* assoc = */ true );
98
+		$extensionJsonFile = __DIR__.'/../extension.json';
99
+		$extensionJsonText = file_get_contents($extensionJsonFile);
100
+		$extensionJson = json_decode($extensionJsonText, /* assoc = */ true);
101 101
 		// @phan-suppress-next-line PhanTypeArraySuspiciousNullable
102
-		$wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() );
102
+		$wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig());
103 103
 
104
-		foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) {
105
-			$localEntityId = $this->importEntityFromWikidata( $wikidataEntityId );
104
+		foreach ($wikidataEntityIds as $key => $wikidataEntityId) {
105
+			$localEntityId = $this->importEntityFromWikidata($wikidataEntityId);
106 106
 			$configUpdates[$key] = [
107 107
 				'wikidata' => $wikidataEntityId,
108 108
 				'local' => $localEntityId,
109 109
 			];
110 110
 		}
111 111
 
112
-		$this->outputConfigUpdates( $configUpdates );
112
+		$this->outputConfigUpdates($configUpdates);
113 113
 	}
114 114
 
115 115
 	/**
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
 	 * @param Config $wikiConfig
118 118
 	 * @return string[]
119 119
 	 */
120
-	private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) {
120
+	private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) {
121 121
 		$wikidataEntityIds = [];
122 122
 
123
-		foreach ( $extensionJsonConfig as $key => $value ) {
124
-			if ( !preg_match( '/Id$/', $key ) ) {
123
+		foreach ($extensionJsonConfig as $key => $value) {
124
+			if (!preg_match('/Id$/', $key)) {
125 125
 				continue;
126 126
 			}
127 127
 
128 128
 			$wikidataEntityId = $value['value'];
129
-			$localEntityId = $wikiConfig->get( $key );
129
+			$localEntityId = $wikiConfig->get($key);
130 130
 
131
-			if ( $localEntityId === $wikidataEntityId ) {
131
+			if ($localEntityId === $wikidataEntityId) {
132 132
 				$wikidataEntityIds[$key] = $wikidataEntityId;
133 133
 			}
134 134
 		}
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 	 * @param string $wikidataEntityId
141 141
 	 * @return string local entity ID
142 142
 	 */
143
-	private function importEntityFromWikidata( $wikidataEntityId ) {
143
+	private function importEntityFromWikidata($wikidataEntityId) {
144 144
 		$wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json";
145
-		$wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ );
146
-		return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson );
145
+		$wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__);
146
+		return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson);
147 147
 	}
148 148
 
149 149
 	/**
@@ -151,24 +151,24 @@  discard block
 block discarded – undo
151 151
 	 * @param string $wikidataEntitiesJson
152 152
 	 * @return string local entity ID
153 153
 	 */
154
-	private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) {
154
+	private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) {
155 155
 		// @phan-suppress-next-line PhanTypeArraySuspiciousNullable
156
-		$wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId];
157
-		$wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray );
156
+		$wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId];
157
+		$wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray);
158 158
 
159
-		$wikidataEntity->setId( null );
159
+		$wikidataEntity->setId(null);
160 160
 
161
-		if ( $wikidataEntity instanceof StatementListProvider ) {
161
+		if ($wikidataEntity instanceof StatementListProvider) {
162 162
 			$wikidataEntity->getStatements()->clear();
163 163
 		}
164 164
 
165
-		if ( $wikidataEntity instanceof Item ) {
166
-			$wikidataEntity->setSiteLinkList( new SiteLinkList() );
165
+		if ($wikidataEntity instanceof Item) {
166
+			$wikidataEntity->setSiteLinkList(new SiteLinkList());
167 167
 		}
168 168
 
169
-		if ( $this->getOption( 'dry-run', false ) ) {
170
-			$wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) );
171
-			$this->output( $wikidataEntityJson . "\n" );
169
+		if ($this->getOption('dry-run', false)) {
170
+			$wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity));
171
+			$this->output($wikidataEntityJson."\n");
172 172
 			return "-$wikidataEntityId";
173 173
 		}
174 174
 
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
 			)->getEntity();
182 182
 
183 183
 			return $localEntity->getId()->getSerialization();
184
-		} catch ( StorageException $storageException ) {
185
-			return $this->storageExceptionToEntityId( $storageException );
184
+		} catch (StorageException $storageException) {
185
+			return $this->storageExceptionToEntityId($storageException);
186 186
 		}
187 187
 	}
188 188
 
189
-	private function storageExceptionToEntityId( StorageException $storageException ): string {
189
+	private function storageExceptionToEntityId(StorageException $storageException): string {
190 190
 		$message = $storageException->getMessage();
191 191
 		// example messages:
192 192
 		// * Item [[Item:Q475|Q475]] already has label "as references"
@@ -196,25 +196,25 @@  discard block
 block discarded – undo
196 196
 		// * Property [[Property:P694|P694]] already has label "instance of"
197 197
 		//   associated with language code en.
198 198
 		$pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/';
199
-		if ( preg_match( $pattern, $message, $matches ) ) {
199
+		if (preg_match($pattern, $message, $matches)) {
200 200
 			return $matches[1];
201 201
 		} else {
202 202
 			throw $storageException;
203 203
 		}
204 204
 	}
205 205
 
206
-	private function outputConfigUpdates( array $configUpdates ) {
207
-		$configFormat = $this->getOption( 'config-format', 'globals' );
208
-		switch ( $configFormat ) {
206
+	private function outputConfigUpdates(array $configUpdates) {
207
+		$configFormat = $this->getOption('config-format', 'globals');
208
+		switch ($configFormat) {
209 209
 			case 'globals':
210
-				$this->outputConfigUpdatesGlobals( $configUpdates );
210
+				$this->outputConfigUpdatesGlobals($configUpdates);
211 211
 				break;
212 212
 			case 'wgConf':
213
-				$this->outputConfigUpdatesWgConf( $configUpdates );
213
+				$this->outputConfigUpdatesWgConf($configUpdates);
214 214
 				break;
215 215
 			default:
216
-				$this->error( "Invalid config format \"$configFormat\", using \"globals\"" );
217
-				$this->outputConfigUpdatesGlobals( $configUpdates );
216
+				$this->error("Invalid config format \"$configFormat\", using \"globals\"");
217
+				$this->outputConfigUpdatesGlobals($configUpdates);
218 218
 				break;
219 219
 		}
220 220
 	}
@@ -222,22 +222,22 @@  discard block
 block discarded – undo
222 222
 	/**
223 223
 	 * @param array[] $configUpdates
224 224
 	 */
225
-	private function outputConfigUpdatesGlobals( array $configUpdates ) {
226
-		foreach ( $configUpdates as $key => $value ) {
227
-			$localValueCode = var_export( $value['local'], true );
228
-			$this->output( "\$wg$key = $localValueCode;\n" );
225
+	private function outputConfigUpdatesGlobals(array $configUpdates) {
226
+		foreach ($configUpdates as $key => $value) {
227
+			$localValueCode = var_export($value['local'], true);
228
+			$this->output("\$wg$key = $localValueCode;\n");
229 229
 		}
230 230
 	}
231 231
 
232 232
 	/**
233 233
 	 * @param array[] $configUpdates
234 234
 	 */
235
-	private function outputConfigUpdatesWgConf( array $configUpdates ) {
236
-		$wikiIdCode = var_export( WikiMap::getCurrentWikiId(), true );
237
-		foreach ( $configUpdates as $key => $value ) {
238
-			$keyCode = var_export( "wg$key", true );
239
-			$wikidataValueCode = var_export( $value['wikidata'], true );
240
-			$localValueCode = var_export( $value['local'], true );
235
+	private function outputConfigUpdatesWgConf(array $configUpdates) {
236
+		$wikiIdCode = var_export(WikiMap::getCurrentWikiId(), true);
237
+		foreach ($configUpdates as $key => $value) {
238
+			$keyCode = var_export("wg$key", true);
239
+			$wikidataValueCode = var_export($value['wikidata'], true);
240
+			$localValueCode = var_export($value['local'], true);
241 241
 			$block = <<< EOF
242 242
 $keyCode => [
243 243
 	'default' => $wikidataValueCode,
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 
247 247
 
248 248
 EOF;
249
-			$this->output( $block );
249
+			$this->output($block);
250 250
 		}
251 251
 	}
252 252
 
Please login to merge, or discard this patch.