Completed
Push — master ( 5f2272...5a9251 )
by
unknown
10:04 queued 07:17
created
src/Api/CachingResultsBuilder.php 1 patch
Spacing   +69 added lines, -70 removed lines patch added patch discarded remove patch
@@ -151,30 +151,30 @@  discard block
 block discarded – undo
151 151
 	) {
152 152
 		$results = [];
153 153
 		$metadatas = [];
154
-		if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) {
154
+		if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) {
155 155
 			$storedEntityIds = [];
156
-			foreach ( $entityIds as $entityId ) {
157
-				$storedResults = $this->getStoredResults( $entityId );
158
-				if ( $storedResults !== null ) {
159
-					$this->loggingHelper->logCheckConstraintsCacheHit( $entityId );
156
+			foreach ($entityIds as $entityId) {
157
+				$storedResults = $this->getStoredResults($entityId);
158
+				if ($storedResults !== null) {
159
+					$this->loggingHelper->logCheckConstraintsCacheHit($entityId);
160 160
 					$results += $storedResults->getArray();
161 161
 					$metadatas[] = $storedResults->getMetadata();
162 162
 					$storedEntityIds[] = $entityId;
163 163
 				}
164 164
 			}
165
-			$entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) );
165
+			$entityIds = array_values(array_diff($entityIds, $storedEntityIds));
166 166
 		}
167
-		if ( $entityIds !== [] || $claimIds !== [] ) {
168
-			if ( $entityIds !== [] ) {
169
-				$this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds );
167
+		if ($entityIds !== [] || $claimIds !== []) {
168
+			if ($entityIds !== []) {
169
+				$this->loggingHelper->logCheckConstraintsCacheMisses($entityIds);
170 170
 			}
171
-			$response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses );
171
+			$response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses);
172 172
 			$results += $response->getArray();
173 173
 			$metadatas[] = $response->getMetadata();
174 174
 		}
175 175
 		return new CachedCheckConstraintsResponse(
176 176
 			$results,
177
-			Metadata::merge( $metadatas )
177
+			Metadata::merge($metadatas)
178 178
 		);
179 179
 	}
180 180
 
@@ -203,13 +203,13 @@  discard block
 block discarded – undo
203 203
 		array $constraintIds = null,
204 204
 		array $statuses
205 205
 	) {
206
-		if ( $claimIds !== [] ) {
206
+		if ($claimIds !== []) {
207 207
 			return false;
208 208
 		}
209
-		if ( $constraintIds !== null ) {
209
+		if ($constraintIds !== null) {
210 210
 			return false;
211 211
 		}
212
-		if ( $statuses != $this->cachedStatuses ) {
212
+		if ($statuses != $this->cachedStatuses) {
213 213
 			return false;
214 214
 		}
215 215
 		return true;
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
 		array $constraintIds = null,
229 229
 		array $statuses
230 230
 	) {
231
-		$results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds, $statuses );
231
+		$results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds, $statuses);
232 232
 
233
-		if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) {
234
-			foreach ( $entityIds as $entityId ) {
233
+		if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) {
234
+			foreach ($entityIds as $entityId) {
235 235
 				$latestRevisionIds = $this->getLatestRevisionIds(
236 236
 					$results->getMetadata()->getDependencyMetadata()->getEntityIds()
237 237
 				);
238
-				if ( $latestRevisionIds === null ) {
238
+				if ($latestRevisionIds === null) {
239 239
 					continue;
240 240
 				}
241 241
 				$value = [
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 					'latestRevisionIds' => $latestRevisionIds,
244 244
 				];
245 245
 				$futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime();
246
-				if ( $futureTime !== null ) {
246
+				if ($futureTime !== null) {
247 247
 					$value['futureTime'] = $futureTime->getArrayValue();
248 248
 				}
249
-				$this->cache->set( $entityId, $value, $this->ttlInSeconds );
249
+				$this->cache->set($entityId, $value, $this->ttlInSeconds);
250 250
 			}
251 251
 		}
252 252
 
@@ -278,10 +278,10 @@  discard block
 block discarded – undo
278 278
 		array $constraintIds = null,
279 279
 		array $statuses
280 280
 	) {
281
-		if ( $constraintIds !== null ) {
281
+		if ($constraintIds !== null) {
282 282
 			return false;
283 283
 		}
284
-		if ( $statuses != $this->cachedStatuses ) {
284
+		if ($statuses != $this->cachedStatuses) {
285 285
 			return false;
286 286
 		}
287 287
 		return true;
@@ -294,45 +294,44 @@  discard block
 block discarded – undo
294 294
 	public function getStoredResults(
295 295
 		EntityId $entityId
296 296
 	) {
297
-		$value = $this->cache->get( $entityId, $curTTL, [], $asOf );
298
-		$now = call_user_func( $this->microtime, true );
297
+		$value = $this->cache->get($entityId, $curTTL, [], $asOf);
298
+		$now = call_user_func($this->microtime, true);
299 299
 
300
-		if ( $value === false ) {
300
+		if ($value === false) {
301 301
 			return null;
302 302
 		}
303 303
 
304
-		$ageInSeconds = (int)ceil( $now - $asOf );
304
+		$ageInSeconds = (int) ceil($now - $asOf);
305 305
 
306 306
 		$dependedEntityIds = array_map(
307
-			[ $this->entityIdParser, "parse" ],
308
-			array_keys( $value['latestRevisionIds'] )
307
+			[$this->entityIdParser, "parse"],
308
+			array_keys($value['latestRevisionIds'])
309 309
 		);
310 310
 
311
-		if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) {
311
+		if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) {
312 312
 			return null;
313 313
 		}
314 314
 
315
-		if ( array_key_exists( 'futureTime', $value ) ) {
316
-			$futureTime = TimeValue::newFromArray( $value['futureTime'] );
317
-			if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) {
315
+		if (array_key_exists('futureTime', $value)) {
316
+			$futureTime = TimeValue::newFromArray($value['futureTime']);
317
+			if (!$this->timeValueComparer->isFutureTime($futureTime)) {
318 318
 				return null;
319 319
 			}
320
-			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime );
320
+			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime);
321 321
 		} else {
322 322
 			$futureTimeDependencyMetadata = DependencyMetadata::blank();
323 323
 		}
324 324
 
325 325
 		$cachingMetadata = $ageInSeconds > 0 ?
326
-			CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) :
327
-			CachingMetadata::fresh();
326
+			CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh();
328 327
 
329
-		if ( is_array( $value['results'] ) ) {
330
-			array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata );
328
+		if (is_array($value['results'])) {
329
+			array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata);
331 330
 		}
332 331
 
333 332
 		return new CachedCheckConstraintsResponse(
334
-			[ $entityId->getSerialization() => $value['results'] ],
335
-			$this->mergeStoredMetadata( $cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata )
333
+			[$entityId->getSerialization() => $value['results']],
334
+			$this->mergeStoredMetadata($cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata)
336 335
 		);
337 336
 	}
338 337
 
@@ -347,19 +346,19 @@  discard block
 block discarded – undo
347 346
 		array $dependedEntityIds,
348 347
 		DependencyMetadata $futureTimeDependencyMetadata = null
349 348
 	) {
350
-		return Metadata::merge( [
351
-			Metadata::ofCachingMetadata( $cachingMetadata ),
352
-			Metadata::ofDependencyMetadata( array_reduce(
349
+		return Metadata::merge([
350
+			Metadata::ofCachingMetadata($cachingMetadata),
351
+			Metadata::ofDependencyMetadata(array_reduce(
353 352
 				$dependedEntityIds,
354
-				function( DependencyMetadata $metadata, EntityId $entityId ) {
355
-					return DependencyMetadata::merge( [
353
+				function(DependencyMetadata $metadata, EntityId $entityId) {
354
+					return DependencyMetadata::merge([
356 355
 						$metadata,
357
-						DependencyMetadata::ofEntityId( $entityId )
358
-					] );
356
+						DependencyMetadata::ofEntityId($entityId)
357
+					]);
359 358
 				},
360 359
 				$futureTimeDependencyMetadata
361
-			) )
362
-		] );
360
+			))
361
+		]);
363 362
 	}
364 363
 
365 364
 	/**
@@ -367,14 +366,14 @@  discard block
 block discarded – undo
367 366
 	 * @return int[]|null array from entity ID serializations to revision ID,
368 367
 	 * or null to indicate that not all revision IDs could be loaded
369 368
 	 */
370
-	private function getLatestRevisionIds( array $entityIds ) {
371
-		if ( $entityIds === [] ) {
369
+	private function getLatestRevisionIds(array $entityIds) {
370
+		if ($entityIds === []) {
372 371
 			$this->loggingHelper->logEmptyDependencyMetadata();
373 372
 			return [];
374 373
 		}
375
-		if ( count( $entityIds ) > $this->maxRevisionIds ) {
374
+		if (count($entityIds) > $this->maxRevisionIds) {
376 375
 			// one of those entities will probably be edited soon, so might as well skip caching
377
-			$this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds );
376
+			$this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds);
378 377
 			return null;
379 378
 		}
380 379
 
@@ -382,11 +381,11 @@  discard block
 block discarded – undo
382 381
 			$entityIds,
383 382
 			EntityRevisionLookup::LATEST_FROM_REPLICA
384 383
 		);
385
-		if ( $this->hasFalseElements( $revisionInformations ) ) {
384
+		if ($this->hasFalseElements($revisionInformations)) {
386 385
 			return null;
387 386
 		}
388 387
 		$latestRevisionIds = [];
389
-		foreach ( $revisionInformations as $serialization => $revisionInformation ) {
388
+		foreach ($revisionInformations as $serialization => $revisionInformation) {
390 389
 			$latestRevisionIds[$serialization] = $revisionInformation->page_latest;
391 390
 		}
392 391
 		return $latestRevisionIds;
@@ -396,31 +395,31 @@  discard block
 block discarded – undo
396 395
 	 * @param array $array
397 396
 	 * @return bool
398 397
 	 */
399
-	private function hasFalseElements( array $array ) {
400
-		return in_array( false, $array, true );
398
+	private function hasFalseElements(array $array) {
399
+		return in_array(false, $array, true);
401 400
 	}
402 401
 
403
-	public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) {
404
-		if ( $key === 'cached' ) {
405
-			$element = CachingMetadata::merge( [
402
+	public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) {
403
+		if ($key === 'cached') {
404
+			$element = CachingMetadata::merge([
406 405
 				$cachingMetadata,
407
-				CachingMetadata::ofArray( $element ),
408
-			] )->toArray();
406
+				CachingMetadata::ofArray($element),
407
+			])->toArray();
409 408
 		}
410 409
 		if (
411
-			is_array( $element ) &&
412
-			array_key_exists( 'constraint', $element ) &&
413
-			in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true )
410
+			is_array($element) &&
411
+			array_key_exists('constraint', $element) &&
412
+			in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true)
414 413
 		) {
415
-			$element['cached'] = CachingMetadata::merge( [
414
+			$element['cached'] = CachingMetadata::merge([
416 415
 				$cachingMetadata,
417 416
 				CachingMetadata::ofArray(
418
-					array_key_exists( 'cached', $element ) ? $element['cached'] : null
417
+					array_key_exists('cached', $element) ? $element['cached'] : null
419 418
 				),
420
-			] )->toArray();
419
+			])->toArray();
421 420
 		}
422
-		if ( is_array( $element ) ) {
423
-			array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata );
421
+		if (is_array($element)) {
422
+			array_walk($element, [$this, __FUNCTION__], $cachingMetadata);
424 423
 		}
425 424
 	}
426 425
 
@@ -429,7 +428,7 @@  discard block
 block discarded – undo
429 428
 	 *
430 429
 	 * @param callable $microtime
431 430
 	 */
432
-	public function setMicrotimeFunction( callable $microtime ) {
431
+	public function setMicrotimeFunction(callable $microtime) {
433 432
 		$this->microtime = $microtime;
434 433
 	}
435 434
 
Please login to merge, or discard this patch.