Completed
Push — master ( f44503...1def0f )
by
unknown
06:52
created
src/Api/CheckConstraints.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -79,19 +79,19 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @return self
81 81
 	 */
82
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
82
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
83 83
 		$repo = WikibaseRepo::getDefaultInstance();
84 84
 
85 85
 		$language = $repo->getUserLanguage();
86 86
 		$formatterOptions = new FormatterOptions();
87
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
87
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
88 88
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
89
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
89
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
90 90
 
91 91
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
92
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language );
92
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language);
93 93
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
94
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language );
94
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language);
95 95
 		$config = MediaWikiServices::getInstance()->getMainConfig();
96 96
 		$dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory();
97 97
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 			$prefix,
114 114
 			$repo->getEntityIdParser(),
115 115
 			$repo->getStatementGuidValidator(),
116
-			$repo->getApiHelperFactory( RequestContext::getMain() ),
116
+			$repo->getApiHelperFactory(RequestContext::getMain()),
117 117
 			$resultsSource,
118 118
 			$checkResultsRenderer,
119 119
 			$dataFactory
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 		CheckResultsRenderer $checkResultsRenderer,
143 143
 		IBufferingStatsdDataFactory $dataFactory
144 144
 	) {
145
-		parent::__construct( $main, $name, $prefix );
145
+		parent::__construct($main, $name, $prefix);
146 146
 		$this->entityIdParser = $entityIdParser;
147 147
 		$this->statementGuidValidator = $statementGuidValidator;
148
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
149
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
148
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
149
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
150 150
 		$this->resultsSource = $resultsSource;
151 151
 		$this->checkResultsRenderer = $checkResultsRenderer;
152 152
 		$this->dataFactory = $dataFactory;
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
 
163 163
 		$params = $this->extractRequestParams();
164 164
 
165
-		$this->validateParameters( $params );
166
-		$entityIds = $this->parseEntityIds( $params );
167
-		$claimIds = $this->parseClaimIds( $params );
165
+		$this->validateParameters($params);
166
+		$entityIds = $this->parseEntityIds($params);
167
+		$claimIds = $this->parseClaimIds($params);
168 168
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
169 169
 		$statuses = $params[self::PARAM_STATUS];
170 170
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 				)
181 181
 			)->getArray()
182 182
 		);
183
-		$this->resultBuilder->markSuccess( 1 );
183
+		$this->resultBuilder->markSuccess(1);
184 184
 	}
185 185
 
186 186
 	/**
@@ -188,24 +188,24 @@  discard block
 block discarded – undo
188 188
 	 *
189 189
 	 * @return EntityId[]
190 190
 	 */
191
-	private function parseEntityIds( array $params ) {
191
+	private function parseEntityIds(array $params) {
192 192
 		$ids = $params[self::PARAM_ID];
193 193
 
194
-		if ( $ids === null ) {
194
+		if ($ids === null) {
195 195
 			return [];
196
-		} elseif ( $ids === [] ) {
196
+		} elseif ($ids === []) {
197 197
 			$this->errorReporter->dieError(
198
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
198
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
199 199
 		}
200 200
 
201
-		return array_map( function ( $id ) {
201
+		return array_map(function($id) {
202 202
 			try {
203
-				return $this->entityIdParser->parse( $id );
204
-			} catch ( EntityIdParsingException $e ) {
203
+				return $this->entityIdParser->parse($id);
204
+			} catch (EntityIdParsingException $e) {
205 205
 				$this->errorReporter->dieError(
206
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
206
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
207 207
 			}
208
-		}, $ids );
208
+		}, $ids);
209 209
 	}
210 210
 
211 211
 	/**
@@ -213,35 +213,35 @@  discard block
 block discarded – undo
213 213
 	 *
214 214
 	 * @return string[]
215 215
 	 */
216
-	private function parseClaimIds( array $params ) {
216
+	private function parseClaimIds(array $params) {
217 217
 		$ids = $params[self::PARAM_CLAIM_ID];
218 218
 
219
-		if ( $ids === null ) {
219
+		if ($ids === null) {
220 220
 			return [];
221
-		} elseif ( $ids === [] ) {
221
+		} elseif ($ids === []) {
222 222
 			$this->errorReporter->dieError(
223
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
223
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
224 224
 		}
225 225
 
226
-		foreach ( $ids as $id ) {
227
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
226
+		foreach ($ids as $id) {
227
+			if (!$this->statementGuidValidator->validate($id)) {
228 228
 				$this->errorReporter->dieError(
229
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
229
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
230 230
 			}
231 231
 		}
232 232
 
233 233
 		return $ids;
234 234
 	}
235 235
 
236
-	private function validateParameters( array $params ) {
237
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
238
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
236
+	private function validateParameters(array $params) {
237
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
238
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
239 239
 		) {
240 240
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
241 241
 			$this->errorReporter->dieError(
242 242
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
243 243
 		}
244
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
244
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
245 245
 			$paramId = self::PARAM_ID;
246 246
 			$paramClaimId = self::PARAM_CLAIM_ID;
247 247
 			$this->errorReporter->dieError(
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 				],
283 283
 				ApiBase::PARAM_ISMULTI => true,
284 284
 				ApiBase::PARAM_ALL => true,
285
-				ApiBase::PARAM_DFLT => implode( '|', CachingResultsSource::CACHED_STATUSES ),
285
+				ApiBase::PARAM_DFLT => implode('|', CachingResultsSource::CACHED_STATUSES),
286 286
 				ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
287 287
 			],
288 288
 		];
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
 	/**
@@ -325,31 +325,30 @@  discard block
 block discarded – undo
325 325
 		EntityId $entityId,
326 326
 		$forRevision = 0
327 327
 	) {
328
-		$value = $this->cache->get( $entityId, $curTTL, [], $asOf );
329
-		$now = call_user_func( $this->microtime, true );
328
+		$value = $this->cache->get($entityId, $curTTL, [], $asOf);
329
+		$now = call_user_func($this->microtime, true);
330 330
 
331
-		$dependencyMetadata = $this->checkDependencyMetadata( $value,
332
-			[ $entityId->getSerialization() => $forRevision ] );
333
-		if ( $dependencyMetadata === null ) {
331
+		$dependencyMetadata = $this->checkDependencyMetadata($value,
332
+			[$entityId->getSerialization() => $forRevision]);
333
+		if ($dependencyMetadata === null) {
334 334
 			return null;
335 335
 		}
336 336
 
337
-		$ageInSeconds = (int)ceil( $now - $asOf );
337
+		$ageInSeconds = (int) ceil($now - $asOf);
338 338
 		$cachingMetadata = $ageInSeconds > 0 ?
339
-			CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) :
340
-			CachingMetadata::fresh();
339
+			CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh();
341 340
 
342 341
 		$results = [];
343
-		foreach ( $value['results'] as $resultSerialization ) {
344
-			$results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata );
342
+		foreach ($value['results'] as $resultSerialization) {
343
+			$results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata);
345 344
 		}
346 345
 
347 346
 		return new CachedCheckResults(
348 347
 			$results,
349
-			Metadata::merge( [
350
-				Metadata::ofCachingMetadata( $cachingMetadata ),
351
-				Metadata::ofDependencyMetadata( $dependencyMetadata ),
352
-			] )
348
+			Metadata::merge([
349
+				Metadata::ofCachingMetadata($cachingMetadata),
350
+				Metadata::ofDependencyMetadata($dependencyMetadata),
351
+			])
353 352
 		);
354 353
 	}
355 354
 
@@ -365,43 +364,43 @@  discard block
 block discarded – undo
365 364
 	 * @return DependencyMetadata|null the dependency metadata,
366 365
 	 * or null if $value should no longer be used
367 366
 	 */
368
-	private function checkDependencyMetadata( $value, $paramRevs ) {
369
-		if ( $value === false ) {
367
+	private function checkDependencyMetadata($value, $paramRevs) {
368
+		if ($value === false) {
370 369
 			return null;
371 370
 		}
372 371
 
373
-		if ( array_key_exists( 'futureTime', $value ) ) {
374
-			$futureTime = TimeValue::newFromArray( $value['futureTime'] );
375
-			if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) {
372
+		if (array_key_exists('futureTime', $value)) {
373
+			$futureTime = TimeValue::newFromArray($value['futureTime']);
374
+			if (!$this->timeValueComparer->isFutureTime($futureTime)) {
376 375
 				return null;
377 376
 			}
378
-			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime );
377
+			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime);
379 378
 		} else {
380 379
 			$futureTimeDependencyMetadata = DependencyMetadata::blank();
381 380
 		}
382 381
 
383
-		foreach ( $paramRevs as $id => $revision ) {
384
-			if ( $revision > 0 ) {
385
-				$value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX );
382
+		foreach ($paramRevs as $id => $revision) {
383
+			if ($revision > 0) {
384
+				$value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX);
386 385
 			}
387 386
 		}
388 387
 
389 388
 		$dependedEntityIds = array_map(
390
-			[ $this->entityIdParser, "parse" ],
391
-			array_keys( $value['latestRevisionIds'] )
389
+			[$this->entityIdParser, "parse"],
390
+			array_keys($value['latestRevisionIds'])
392 391
 		);
393 392
 
394
-		if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) {
393
+		if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) {
395 394
 			return null;
396 395
 		}
397 396
 
398 397
 		return array_reduce(
399 398
 			$dependedEntityIds,
400
-			function( DependencyMetadata $metadata, EntityId $entityId ) {
401
-				return DependencyMetadata::merge( [
399
+			function(DependencyMetadata $metadata, EntityId $entityId) {
400
+				return DependencyMetadata::merge([
402 401
 					$metadata,
403
-					DependencyMetadata::ofEntityId( $entityId )
404
-				] );
402
+					DependencyMetadata::ofEntityId($entityId)
403
+				]);
405 404
 			},
406 405
 			$futureTimeDependencyMetadata
407 406
 		);
@@ -421,13 +420,13 @@  discard block
 block discarded – undo
421 420
 		array $resultSerialization,
422 421
 		CachingMetadata $cachingMetadata
423 422
 	) {
424
-		$result = $this->checkResultDeserializer->deserialize( $resultSerialization );
425
-		if ( $this->isPossiblyStaleResult( $result ) ) {
423
+		$result = $this->checkResultDeserializer->deserialize($resultSerialization);
424
+		if ($this->isPossiblyStaleResult($result)) {
426 425
 			$result->withMetadata(
427
-				Metadata::merge( [
426
+				Metadata::merge([
428 427
 					$result->getMetadata(),
429
-					Metadata::ofCachingMetadata( $cachingMetadata ),
430
-				] )
428
+					Metadata::ofCachingMetadata($cachingMetadata),
429
+				])
431 430
 			);
432 431
 		}
433 432
 		return $result;
@@ -437,8 +436,8 @@  discard block
 block discarded – undo
437 436
 	 * @param CheckResult $result
438 437
 	 * @return bool
439 438
 	 */
440
-	private function isPossiblyStaleResult( CheckResult $result ) {
441
-		if ( $result instanceof NullResult ) {
439
+	private function isPossiblyStaleResult(CheckResult $result) {
440
+		if ($result instanceof NullResult) {
442 441
 			return false;
443 442
 		}
444 443
 
@@ -453,14 +452,14 @@  discard block
 block discarded – undo
453 452
 	 * @return int[]|null array from entity ID serializations to revision ID,
454 453
 	 * or null to indicate that not all revision IDs could be loaded
455 454
 	 */
456
-	private function getLatestRevisionIds( array $entityIds ) {
457
-		if ( $entityIds === [] ) {
455
+	private function getLatestRevisionIds(array $entityIds) {
456
+		if ($entityIds === []) {
458 457
 			$this->loggingHelper->logEmptyDependencyMetadata();
459 458
 			return [];
460 459
 		}
461
-		if ( count( $entityIds ) > $this->maxRevisionIds ) {
460
+		if (count($entityIds) > $this->maxRevisionIds) {
462 461
 			// one of those entities will probably be edited soon, so might as well skip caching
463
-			$this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds );
462
+			$this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds);
464 463
 			return null;
465 464
 		}
466 465
 
@@ -468,7 +467,7 @@  discard block
 block discarded – undo
468 467
 			$entityIds,
469 468
 			EntityRevisionLookup::LATEST_FROM_REPLICA
470 469
 		);
471
-		if ( $this->hasFalseElements( $latestRevisionIds ) ) {
470
+		if ($this->hasFalseElements($latestRevisionIds)) {
472 471
 			return null;
473 472
 		}
474 473
 		return $latestRevisionIds;
@@ -478,8 +477,8 @@  discard block
 block discarded – undo
478 477
 	 * @param array $array
479 478
 	 * @return bool
480 479
 	 */
481
-	private function hasFalseElements( array $array ) {
482
-		return in_array( false, $array, true );
480
+	private function hasFalseElements(array $array) {
481
+		return in_array(false, $array, true);
483 482
 	}
484 483
 
485 484
 	/**
@@ -487,7 +486,7 @@  discard block
 block discarded – undo
487 486
 	 *
488 487
 	 * @param callable $microtime
489 488
 	 */
490
-	public function setMicrotimeFunction( callable $microtime ) {
489
+	public function setMicrotimeFunction(callable $microtime) {
491 490
 		$this->microtime = $microtime;
492 491
 	}
493 492
 
Please login to merge, or discard this patch.
maintenance/ImportConstraintEntities.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 use Wikibase\Repo\WikibaseRepo;
16 16
 
17 17
 // @codeCoverageIgnoreStart
18
-$basePath = getenv( "MW_INSTALL_PATH" ) !== false
19
-	? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../..";
18
+$basePath = getenv("MW_INSTALL_PATH") !== false
19
+	? getenv("MW_INSTALL_PATH") : __DIR__."/../../..";
20 20
 
21
-require_once $basePath . "/maintenance/Maintenance.php";
21
+require_once $basePath."/maintenance/Maintenance.php";
22 22
 // @codeCoverageIgnoreEnd
23 23
 
24 24
 /**
@@ -52,20 +52,20 @@  discard block
 block discarded – undo
52 52
 		parent::__construct();
53 53
 
54 54
 		$this->addDescription(
55
-			'Import entities needed for constraint checks ' .
55
+			'Import entities needed for constraint checks '.
56 56
 			'from Wikidata into the local repository.'
57 57
 		);
58 58
 		$this->addOption(
59 59
 			'config-format',
60
-			'The format in which the resulting configuration will be omitted: ' .
61
-			'"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' .
60
+			'The format in which the resulting configuration will be omitted: '.
61
+			'"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '.
62 62
 			'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.'
63 63
 		);
64 64
 		$this->addOption(
65 65
 			'dry-run',
66 66
 			'Don’t actually import entities, just print which ones would be imported.'
67 67
 		);
68
-		$this->requireExtension( 'WikibaseQualityConstraints' );
68
+		$this->requireExtension('WikibaseQualityConstraints');
69 69
 	}
70 70
 
71 71
 	/**
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 		$this->entitySerializer = $repo->getAllTypesEntitySerializer();
77 77
 		$this->entityDeserializer = $repo->getInternalFormatEntityDeserializer();
78 78
 		$this->entityStore = $repo->getEntityStore();
79
-		if ( !$this->getOption( 'dry-run', false ) ) {
80
-			$this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' );
79
+		if (!$this->getOption('dry-run', false)) {
80
+			$this->user = User::newSystemUser('WikibaseQualityConstraints importer');
81 81
 		}
82 82
 	}
83 83
 
@@ -86,21 +86,21 @@  discard block
 block discarded – undo
86 86
 
87 87
 		$configUpdates = [];
88 88
 
89
-		$extensionJsonFile = __DIR__ . '/../extension.json';
90
-		$extensionJsonText = file_get_contents( $extensionJsonFile );
91
-		$extensionJson = json_decode( $extensionJsonText, /* assoc = */ true );
89
+		$extensionJsonFile = __DIR__.'/../extension.json';
90
+		$extensionJsonText = file_get_contents($extensionJsonFile);
91
+		$extensionJson = json_decode($extensionJsonText, /* assoc = */ true);
92 92
 		// @phan-suppress-next-line PhanTypeArraySuspiciousNullable
93
-		$wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() );
93
+		$wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig());
94 94
 
95
-		foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) {
96
-			$localEntityId = $this->importEntityFromWikidata( $wikidataEntityId );
95
+		foreach ($wikidataEntityIds as $key => $wikidataEntityId) {
96
+			$localEntityId = $this->importEntityFromWikidata($wikidataEntityId);
97 97
 			$configUpdates[$key] = [
98 98
 				'wikidata' => $wikidataEntityId,
99 99
 				'local' => $localEntityId,
100 100
 			];
101 101
 		}
102 102
 
103
-		$this->outputConfigUpdates( $configUpdates );
103
+		$this->outputConfigUpdates($configUpdates);
104 104
 	}
105 105
 
106 106
 	/**
@@ -108,18 +108,18 @@  discard block
 block discarded – undo
108 108
 	 * @param Config $wikiConfig
109 109
 	 * @return string[]
110 110
 	 */
111
-	private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) {
111
+	private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) {
112 112
 		$wikidataEntityIds = [];
113 113
 
114
-		foreach ( $extensionJsonConfig as $key => $value ) {
115
-			if ( !preg_match( '/Id$/', $key ) ) {
114
+		foreach ($extensionJsonConfig as $key => $value) {
115
+			if (!preg_match('/Id$/', $key)) {
116 116
 				continue;
117 117
 			}
118 118
 
119 119
 			$wikidataEntityId = $value['value'];
120
-			$localEntityId = $wikiConfig->get( $key );
120
+			$localEntityId = $wikiConfig->get($key);
121 121
 
122
-			if ( $localEntityId === $wikidataEntityId ) {
122
+			if ($localEntityId === $wikidataEntityId) {
123 123
 				$wikidataEntityIds[$key] = $wikidataEntityId;
124 124
 			}
125 125
 		}
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
 	 * @param string $wikidataEntityId
132 132
 	 * @return string local entity ID
133 133
 	 */
134
-	private function importEntityFromWikidata( $wikidataEntityId ) {
134
+	private function importEntityFromWikidata($wikidataEntityId) {
135 135
 		$wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json";
136
-		$wikidataEntitiesJson = file_get_contents( $wikidataEntityUrl );
137
-		return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson );
136
+		$wikidataEntitiesJson = file_get_contents($wikidataEntityUrl);
137
+		return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson);
138 138
 	}
139 139
 
140 140
 	/**
@@ -142,24 +142,24 @@  discard block
 block discarded – undo
142 142
 	 * @param string $wikidataEntitiesJson
143 143
 	 * @return string local entity ID
144 144
 	 */
145
-	private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) {
145
+	private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) {
146 146
 		// @phan-suppress-next-line PhanTypeArraySuspiciousNullable
147
-		$wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId];
148
-		$wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray );
147
+		$wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId];
148
+		$wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray);
149 149
 
150
-		$wikidataEntity->setId( null );
150
+		$wikidataEntity->setId(null);
151 151
 
152
-		if ( $wikidataEntity instanceof StatementListProvider ) {
152
+		if ($wikidataEntity instanceof StatementListProvider) {
153 153
 			$wikidataEntity->getStatements()->clear();
154 154
 		}
155 155
 
156
-		if ( $wikidataEntity instanceof Item ) {
157
-			$wikidataEntity->setSiteLinkList( new SiteLinkList() );
156
+		if ($wikidataEntity instanceof Item) {
157
+			$wikidataEntity->setSiteLinkList(new SiteLinkList());
158 158
 		}
159 159
 
160
-		if ( $this->getOption( 'dry-run', false ) ) {
161
-			$wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) );
162
-			$this->output( $wikidataEntityJson . "\n" );
160
+		if ($this->getOption('dry-run', false)) {
161
+			$wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity));
162
+			$this->output($wikidataEntityJson."\n");
163 163
 			return "-$wikidataEntityId";
164 164
 		}
165 165
 
@@ -172,12 +172,12 @@  discard block
 block discarded – undo
172 172
 			)->getEntity();
173 173
 
174 174
 			return $localEntity->getId()->getSerialization();
175
-		} catch ( StorageException $storageException ) {
176
-			return $this->storageExceptionToEntityId( $storageException );
175
+		} catch (StorageException $storageException) {
176
+			return $this->storageExceptionToEntityId($storageException);
177 177
 		}
178 178
 	}
179 179
 
180
-	private function storageExceptionToEntityId( StorageException $storageException ) {
180
+	private function storageExceptionToEntityId(StorageException $storageException) {
181 181
 		$message = $storageException->getMessage();
182 182
 		// example messages:
183 183
 		// * Item [[Item:Q475|Q475]] already has label "as references"
@@ -187,25 +187,25 @@  discard block
 block discarded – undo
187 187
 		// * Property [[Property:P694|P694]] already has label "instance of"
188 188
 		//   associated with language code en.
189 189
 		$pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/';
190
-		if ( preg_match( $pattern, $message, $matches ) ) {
190
+		if (preg_match($pattern, $message, $matches)) {
191 191
 			return $matches[1];
192 192
 		} else {
193 193
 			throw $storageException;
194 194
 		}
195 195
 	}
196 196
 
197
-	private function outputConfigUpdates( array $configUpdates ) {
198
-		$configFormat = $this->getOption( 'config-format', 'globals' );
199
-		switch ( $configFormat ) {
197
+	private function outputConfigUpdates(array $configUpdates) {
198
+		$configFormat = $this->getOption('config-format', 'globals');
199
+		switch ($configFormat) {
200 200
 			case 'globals':
201
-				$this->outputConfigUpdatesGlobals( $configUpdates );
201
+				$this->outputConfigUpdatesGlobals($configUpdates);
202 202
 				break;
203 203
 			case 'wgConf':
204
-				$this->outputConfigUpdatesWgConf( $configUpdates );
204
+				$this->outputConfigUpdatesWgConf($configUpdates);
205 205
 				break;
206 206
 			default:
207
-				$this->error( "Invalid config format \"$configFormat\", using \"globals\"" );
208
-				$this->outputConfigUpdatesGlobals( $configUpdates );
207
+				$this->error("Invalid config format \"$configFormat\", using \"globals\"");
208
+				$this->outputConfigUpdatesGlobals($configUpdates);
209 209
 				break;
210 210
 		}
211 211
 	}
@@ -213,22 +213,22 @@  discard block
 block discarded – undo
213 213
 	/**
214 214
 	 * @param array[] $configUpdates
215 215
 	 */
216
-	private function outputConfigUpdatesGlobals( array $configUpdates ) {
217
-		foreach ( $configUpdates as $key => $value ) {
218
-			$localValueCode = var_export( $value['local'], true );
219
-			$this->output( "\$wg$key = $localValueCode;\n" );
216
+	private function outputConfigUpdatesGlobals(array $configUpdates) {
217
+		foreach ($configUpdates as $key => $value) {
218
+			$localValueCode = var_export($value['local'], true);
219
+			$this->output("\$wg$key = $localValueCode;\n");
220 220
 		}
221 221
 	}
222 222
 
223 223
 	/**
224 224
 	 * @param array[] $configUpdates
225 225
 	 */
226
-	private function outputConfigUpdatesWgConf( array $configUpdates ) {
227
-		foreach ( $configUpdates as $key => $value ) {
228
-			$keyCode = var_export( "wg$key", true );
229
-			$wikidataValueCode = var_export( $value['wikidata'], true );
230
-			$localValueCode = var_export( $value['local'], true );
231
-			$wikiIdCode = var_export( wfWikiID(), true );
226
+	private function outputConfigUpdatesWgConf(array $configUpdates) {
227
+		foreach ($configUpdates as $key => $value) {
228
+			$keyCode = var_export("wg$key", true);
229
+			$wikidataValueCode = var_export($value['wikidata'], true);
230
+			$localValueCode = var_export($value['local'], true);
231
+			$wikiIdCode = var_export(wfWikiID(), true);
232 232
 			$block = <<< EOF
233 233
 $keyCode => [
234 234
 	'default' => $wikidataValueCode,
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 
238 238
 
239 239
 EOF;
240
-			$this->output( $block );
240
+			$this->output($block);
241 241
 		}
242 242
 	}
243 243
 
Please login to merge, or discard this patch.
src/ConstraintCheck/ItemIdSnakValue.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * @param ItemId $itemId
45 45
 	 * @return self
46 46
 	 */
47
-	public static function fromItemId( ItemId $itemId ) {
47
+	public static function fromItemId(ItemId $itemId) {
48 48
 		$ret = new self;
49 49
 		$ret->itemId = $itemId;
50 50
 		return $ret;
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	 * @throws InvalidArgumentException
81 81
 	 * @return self
82 82
 	 */
83
-	public static function fromSnak( Snak $snak ) {
84
-		switch ( true ) {
83
+	public static function fromSnak(Snak $snak) {
84
+		switch (true) {
85 85
 			case $snak instanceof PropertyValueSnak:
86 86
 				$dataValue = $snak->getDataValue();
87
-				if ( $dataValue instanceof EntityIdValue ) {
87
+				if ($dataValue instanceof EntityIdValue) {
88 88
 					$itemId = $dataValue->getEntityId();
89
-					if ( $itemId instanceof ItemId ) {
90
-						return self::fromItemId( $itemId );
89
+					if ($itemId instanceof ItemId) {
90
+						return self::fromItemId($itemId);
91 91
 					}
92 92
 				}
93 93
 				break;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 				return self::noValue();
98 98
 		}
99 99
 
100
-		throw new InvalidArgumentException( 'Snak must contain item ID value or be a somevalue / novalue snak' );
100
+		throw new InvalidArgumentException('Snak must contain item ID value or be a somevalue / novalue snak');
101 101
 	}
102 102
 
103 103
 	/**
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @return ItemId
136 136
 	 */
137 137
 	public function getItemId() {
138
-		if ( !$this->isValue() ) {
139
-			throw new DomainException( 'This value does not contain an item ID.' );
138
+		if (!$this->isValue()) {
139
+			throw new DomainException('This value does not contain an item ID.');
140 140
 		}
141 141
 		return $this->itemId;
142 142
 	}
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
 	 * @param Snak $snak
149 149
 	 * @return bool
150 150
 	 */
151
-	public function matchesSnak( Snak $snak ) {
152
-		switch ( true ) {
151
+	public function matchesSnak(Snak $snak) {
152
+		switch (true) {
153 153
 			case $snak instanceof PropertyValueSnak:
154 154
 				$dataValue = $snak->getDataValue();
155 155
 				return $this->isValue() &&
156 156
 					$dataValue instanceof EntityIdValue &&
157 157
 					$dataValue->getEntityId() instanceof ItemId &&
158
-					$dataValue->getEntityId()->equals( $this->getItemId() );
158
+					$dataValue->getEntityId()->equals($this->getItemId());
159 159
 			case $snak instanceof PropertySomeValueSnak:
160 160
 				return $this->isSomeValue();
161 161
 			case $snak instanceof PropertyNoValueSnak:
Please login to merge, or discard this patch.