Completed
Push — master ( 44b7ae...052c87 )
by
unknown
05:42 queued 01:07
created
src/Api/CachingResultsBuilder.php 1 patch
Spacing   +65 added lines, -66 removed lines patch added patch discarded remove patch
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	) {
143 143
 		$results = [];
144 144
 		$metadatas = [];
145
-		if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) {
145
+		if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) {
146 146
 			$storedEntityIds = [];
147
-			foreach ( $entityIds as $entityId ) {
148
-				$storedResults = $this->getStoredResults( $entityId );
149
-				if ( $storedResults !== null ) {
147
+			foreach ($entityIds as $entityId) {
148
+				$storedResults = $this->getStoredResults($entityId);
149
+				if ($storedResults !== null) {
150 150
 					$this->dataFactory->increment(
151 151
 						'wikibase.quality.constraints.cache.entity.hit'
152 152
 					);
@@ -155,20 +155,20 @@  discard block
 block discarded – undo
155 155
 					$storedEntityIds[] = $entityId;
156 156
 				}
157 157
 			}
158
-			$entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) );
158
+			$entityIds = array_values(array_diff($entityIds, $storedEntityIds));
159 159
 		}
160
-		if ( $entityIds !== [] || $claimIds !== [] ) {
160
+		if ($entityIds !== [] || $claimIds !== []) {
161 161
 			$this->dataFactory->updateCount(
162 162
 				'wikibase.quality.constraints.cache.entity.miss',
163
-				count( $entityIds )
163
+				count($entityIds)
164 164
 			);
165
-			$response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses );
165
+			$response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses);
166 166
 			$results += $response->getArray();
167 167
 			$metadatas[] = $response->getMetadata();
168 168
 		}
169 169
 		return new CachedCheckConstraintsResponse(
170 170
 			$results,
171
-			Metadata::merge( $metadatas )
171
+			Metadata::merge($metadatas)
172 172
 		);
173 173
 	}
174 174
 
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
 		array $constraintIds = null,
198 198
 		array $statuses
199 199
 	) {
200
-		if ( $claimIds !== [] ) {
200
+		if ($claimIds !== []) {
201 201
 			return false;
202 202
 		}
203
-		if ( $constraintIds !== null ) {
203
+		if ($constraintIds !== null) {
204 204
 			return false;
205 205
 		}
206
-		if ( $statuses != $this->cachedStatuses ) {
206
+		if ($statuses != $this->cachedStatuses) {
207 207
 			return false;
208 208
 		}
209 209
 		return true;
@@ -222,14 +222,14 @@  discard block
 block discarded – undo
222 222
 		array $constraintIds = null,
223 223
 		array $statuses
224 224
 	) {
225
-		$results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds, $statuses );
225
+		$results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds, $statuses);
226 226
 
227
-		if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) {
228
-			foreach ( $entityIds as $entityId ) {
227
+		if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) {
228
+			foreach ($entityIds as $entityId) {
229 229
 				$latestRevisionIds = $this->getLatestRevisionIds(
230 230
 					$results->getMetadata()->getDependencyMetadata()->getEntityIds()
231 231
 				);
232
-				if ( $latestRevisionIds === null ) {
232
+				if ($latestRevisionIds === null) {
233 233
 					continue;
234 234
 				}
235 235
 				$value = [
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 					'latestRevisionIds' => $latestRevisionIds,
238 238
 				];
239 239
 				$futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime();
240
-				if ( $futureTime !== null ) {
240
+				if ($futureTime !== null) {
241 241
 					$value['futureTime'] = $futureTime->getArrayValue();
242 242
 				}
243
-				$this->cache->set( $entityId, $value, $this->ttlInSeconds );
243
+				$this->cache->set($entityId, $value, $this->ttlInSeconds);
244 244
 			}
245 245
 		}
246 246
 
@@ -272,10 +272,10 @@  discard block
 block discarded – undo
272 272
 		array $constraintIds = null,
273 273
 		array $statuses
274 274
 	) {
275
-		if ( $constraintIds !== null ) {
275
+		if ($constraintIds !== null) {
276 276
 			return false;
277 277
 		}
278
-		if ( $statuses != $this->cachedStatuses ) {
278
+		if ($statuses != $this->cachedStatuses) {
279 279
 			return false;
280 280
 		}
281 281
 		return true;
@@ -288,45 +288,44 @@  discard block
 block discarded – undo
288 288
 	public function getStoredResults(
289 289
 		EntityId $entityId
290 290
 	) {
291
-		$value = $this->cache->get( $entityId, $curTTL, [], $asOf );
292
-		$now = call_user_func( $this->microtime, true );
291
+		$value = $this->cache->get($entityId, $curTTL, [], $asOf);
292
+		$now = call_user_func($this->microtime, true);
293 293
 
294
-		if ( $value === false ) {
294
+		if ($value === false) {
295 295
 			return null;
296 296
 		}
297 297
 
298
-		$ageInSeconds = (int)ceil( $now - $asOf );
298
+		$ageInSeconds = (int) ceil($now - $asOf);
299 299
 
300 300
 		$dependedEntityIds = array_map(
301
-			[ $this->entityIdParser, "parse" ],
302
-			array_keys( $value['latestRevisionIds'] )
301
+			[$this->entityIdParser, "parse"],
302
+			array_keys($value['latestRevisionIds'])
303 303
 		);
304 304
 
305
-		if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) {
305
+		if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) {
306 306
 			return null;
307 307
 		}
308 308
 
309
-		if ( array_key_exists( 'futureTime', $value ) ) {
310
-			$futureTime = TimeValue::newFromArray( $value['futureTime'] );
311
-			if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) {
309
+		if (array_key_exists('futureTime', $value)) {
310
+			$futureTime = TimeValue::newFromArray($value['futureTime']);
311
+			if (!$this->timeValueComparer->isFutureTime($futureTime)) {
312 312
 				return null;
313 313
 			}
314
-			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime );
314
+			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime);
315 315
 		} else {
316 316
 			$futureTimeDependencyMetadata = DependencyMetadata::blank();
317 317
 		}
318 318
 
319 319
 		$cachingMetadata = $ageInSeconds > 0 ?
320
-			CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) :
321
-			CachingMetadata::fresh();
320
+			CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh();
322 321
 
323
-		if ( is_array( $value['results'] ) ) {
324
-			array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata );
322
+		if (is_array($value['results'])) {
323
+			array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata);
325 324
 		}
326 325
 
327 326
 		return new CachedCheckConstraintsResponse(
328
-			[ $entityId->getSerialization() => $value['results'] ],
329
-			$this->mergeStoredMetadata( $cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata )
327
+			[$entityId->getSerialization() => $value['results']],
328
+			$this->mergeStoredMetadata($cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata)
330 329
 		);
331 330
 	}
332 331
 
@@ -341,19 +340,19 @@  discard block
 block discarded – undo
341 340
 		array $dependedEntityIds,
342 341
 		DependencyMetadata $futureTimeDependencyMetadata = null
343 342
 	) {
344
-		return Metadata::merge( [
345
-			Metadata::ofCachingMetadata( $cachingMetadata ),
346
-			Metadata::ofDependencyMetadata( array_reduce(
343
+		return Metadata::merge([
344
+			Metadata::ofCachingMetadata($cachingMetadata),
345
+			Metadata::ofDependencyMetadata(array_reduce(
347 346
 				$dependedEntityIds,
348
-				function( DependencyMetadata $metadata, EntityId $entityId ) {
349
-					return DependencyMetadata::merge( [
347
+				function(DependencyMetadata $metadata, EntityId $entityId) {
348
+					return DependencyMetadata::merge([
350 349
 						$metadata,
351
-						DependencyMetadata::ofEntityId( $entityId )
352
-					] );
350
+						DependencyMetadata::ofEntityId($entityId)
351
+					]);
353 352
 				},
354 353
 				$futureTimeDependencyMetadata
355
-			) )
356
-		] );
354
+			))
355
+		]);
357 356
 	}
358 357
 
359 358
 	/**
@@ -361,8 +360,8 @@  discard block
 block discarded – undo
361 360
 	 * @return int[]|null array from entity ID serializations to revision ID,
362 361
 	 * or null to indicate that not all revision IDs could be loaded
363 362
 	 */
364
-	private function getLatestRevisionIds( array $entityIds ) {
365
-		if ( $entityIds === [] ) {
363
+	private function getLatestRevisionIds(array $entityIds) {
364
+		if ($entityIds === []) {
366 365
 			return [];
367 366
 		}
368 367
 
@@ -370,11 +369,11 @@  discard block
 block discarded – undo
370 369
 			$entityIds,
371 370
 			EntityRevisionLookup::LATEST_FROM_REPLICA
372 371
 		);
373
-		if ( $this->hasFalseElements( $revisionInformations ) ) {
372
+		if ($this->hasFalseElements($revisionInformations)) {
374 373
 			return null;
375 374
 		}
376 375
 		$latestRevisionIds = [];
377
-		foreach ( $revisionInformations as $serialization => $revisionInformation ) {
376
+		foreach ($revisionInformations as $serialization => $revisionInformation) {
378 377
 			$latestRevisionIds[$serialization] = $revisionInformation->page_latest;
379 378
 		}
380 379
 		return $latestRevisionIds;
@@ -384,31 +383,31 @@  discard block
 block discarded – undo
384 383
 	 * @param array $array
385 384
 	 * @return bool
386 385
 	 */
387
-	private function hasFalseElements( array $array ) {
388
-		return in_array( false, $array, true );
386
+	private function hasFalseElements(array $array) {
387
+		return in_array(false, $array, true);
389 388
 	}
390 389
 
391
-	public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) {
392
-		if ( $key === 'cached' ) {
393
-			$element = CachingMetadata::merge( [
390
+	public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) {
391
+		if ($key === 'cached') {
392
+			$element = CachingMetadata::merge([
394 393
 				$cachingMetadata,
395
-				CachingMetadata::ofArray( $element ),
396
-			] )->toArray();
394
+				CachingMetadata::ofArray($element),
395
+			])->toArray();
397 396
 		}
398 397
 		if (
399
-			is_array( $element ) &&
400
-			array_key_exists( 'constraint', $element ) &&
401
-			in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true )
398
+			is_array($element) &&
399
+			array_key_exists('constraint', $element) &&
400
+			in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true)
402 401
 		) {
403
-			$element['cached'] = CachingMetadata::merge( [
402
+			$element['cached'] = CachingMetadata::merge([
404 403
 				$cachingMetadata,
405 404
 				CachingMetadata::ofArray(
406
-					array_key_exists( 'cached', $element ) ? $element['cached'] : null
405
+					array_key_exists('cached', $element) ? $element['cached'] : null
407 406
 				),
408
-			] )->toArray();
407
+			])->toArray();
409 408
 		}
410
-		if ( is_array( $element ) ) {
411
-			array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata );
409
+		if (is_array($element)) {
410
+			array_walk($element, [$this, __FUNCTION__], $cachingMetadata);
412 411
 		}
413 412
 	}
414 413
 
@@ -417,7 +416,7 @@  discard block
 block discarded – undo
417 416
 	 *
418 417
 	 * @param callable $microtime
419 418
 	 */
420
-	public function setMicrotimeFunction( callable $microtime ) {
419
+	public function setMicrotimeFunction(callable $microtime) {
421 420
 		$this->microtime = $microtime;
422 421
 	}
423 422
 
Please login to merge, or discard this patch.