Completed
Push — master ( 09a985...a40fd7 )
by
unknown
01:50
created
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
 			Store::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.
src/Job/UpdateConstraintsTableJob.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 
32 32
 	const BATCH_SIZE = 10;
33 33
 
34
-	public static function newFromGlobalState( Title $title, array $params ) {
35
-		Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' );
34
+	public static function newFromGlobalState(Title $title, array $params) {
35
+		Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]');
36 36
 		$repo = WikibaseRepo::getDefaultInstance();
37 37
 		return new UpdateConstraintsTableJob(
38 38
 			$title,
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 			$params['revisionId'] ?? null,
42 42
 			MediaWikiServices::getInstance()->getMainConfig(),
43 43
 			ConstraintsServices::getConstraintStore(),
44
-			$repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ),
44
+			$repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED),
45 45
 			$repo->getBaseDataModelSerializerFactory()->newSnakSerializer()
46 46
 		);
47 47
 	}
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		EntityRevisionLookup $entityRevisionLookup,
97 97
 		Serializer $snakSerializer
98 98
 	) {
99
-		parent::__construct( 'constraintsTableUpdate', $title, $params );
99
+		parent::__construct('constraintsTableUpdate', $title, $params);
100 100
 
101 101
 		$this->propertyId = $propertyId;
102 102
 		$this->revisionId = $revisionId;
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 		$this->snakSerializer = $snakSerializer;
107 107
 	}
108 108
 
109
-	public function extractParametersFromQualifiers( SnakList $qualifiers ) {
109
+	public function extractParametersFromQualifiers(SnakList $qualifiers) {
110 110
 		$parameters = [];
111
-		foreach ( $qualifiers as $qualifier ) {
111
+		foreach ($qualifiers as $qualifier) {
112 112
 			$qualifierId = $qualifier->getPropertyId()->getSerialization();
113
-			$paramSerialization = $this->snakSerializer->serialize( $qualifier );
113
+			$paramSerialization = $this->snakSerializer->serialize($qualifier);
114 114
 			$parameters[$qualifierId][] = $paramSerialization;
115 115
 		}
116 116
 		return $parameters;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		'@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue';
128 128
 		$entityId = $dataValue->getEntityId();
129 129
 		$constraintTypeQid = $entityId->getSerialization();
130
-		$parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() );
130
+		$parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers());
131 131
 		return new Constraint(
132 132
 			$constraintId,
133 133
 			$propertyId,
@@ -142,17 +142,17 @@  discard block
 block discarded – undo
142 142
 		PropertyId $propertyConstraintPropertyId
143 143
 	) {
144 144
 		$constraintsStatements = $property->getStatements()
145
-			->getByPropertyId( $propertyConstraintPropertyId )
146
-			->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] );
145
+			->getByPropertyId($propertyConstraintPropertyId)
146
+			->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]);
147 147
 		$constraints = [];
148
-		foreach ( $constraintsStatements->getIterator() as $constraintStatement ) {
149
-			$constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement );
150
-			if ( count( $constraints ) >= self::BATCH_SIZE ) {
151
-				$constraintStore->insertBatch( $constraints );
148
+		foreach ($constraintsStatements->getIterator() as $constraintStatement) {
149
+			$constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement);
150
+			if (count($constraints) >= self::BATCH_SIZE) {
151
+				$constraintStore->insertBatch($constraints);
152 152
 				$constraints = [];
153 153
 			}
154 154
 		}
155
-		$constraintStore->insertBatch( $constraints );
155
+		$constraintStore->insertBatch($constraints);
156 156
 	}
157 157
 
158 158
 	/**
@@ -163,19 +163,19 @@  discard block
 block discarded – undo
163 163
 	public function run() {
164 164
 		// TODO in the future: only touch constraints affected by the edit (requires T163465)
165 165
 
166
-		$propertyId = new PropertyId( $this->propertyId );
166
+		$propertyId = new PropertyId($this->propertyId);
167 167
 		$propertyRevision = $this->entityRevisionLookup->getEntityRevision(
168 168
 			$propertyId,
169 169
 			0, // latest
170 170
 			Store::LATEST_FROM_REPLICA
171 171
 		);
172 172
 
173
-		if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) {
174
-			JobQueueGroup::singleton()->push( $this );
173
+		if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) {
174
+			JobQueueGroup::singleton()->push($this);
175 175
 			return true;
176 176
 		}
177 177
 
178
-		$this->constraintStore->deleteForProperty( $propertyId );
178
+		$this->constraintStore->deleteForProperty($propertyId);
179 179
 
180 180
 		/** @var Property $property */
181 181
 		$property = $propertyRevision->getEntity();
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 		$this->importConstraintsForProperty(
184 184
 			$property,
185 185
 			$this->constraintStore,
186
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) )
186
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId'))
187 187
 		);
188 188
 
189 189
 		return true;
Please login to merge, or discard this patch.