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