Completed
Push — master ( a35969...a87f93 )
by
unknown
07:49
created
src/Api/CachingResultsBuilder.php 1 patch
Spacing   +60 added lines, -61 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,10 +222,10 @@  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
 				$value = [
230 230
 					'results' => $results->getArray()[$entityId->getSerialization()],
231 231
 					'latestRevisionIds' => $this->getLatestRevisionIds(
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
 					),
234 234
 				];
235 235
 				$futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime();
236
-				if ( $futureTime !== null ) {
236
+				if ($futureTime !== null) {
237 237
 					$value['futureTime'] = $futureTime->getArrayValue();
238 238
 				}
239
-				$this->cache->set( $entityId, $value, $this->ttlInSeconds );
239
+				$this->cache->set($entityId, $value, $this->ttlInSeconds);
240 240
 			}
241 241
 		}
242 242
 
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 		array $constraintIds = null,
269 269
 		array $statuses
270 270
 	) {
271
-		if ( $constraintIds !== null ) {
271
+		if ($constraintIds !== null) {
272 272
 			return false;
273 273
 		}
274
-		if ( $statuses != $this->cachedStatuses ) {
274
+		if ($statuses != $this->cachedStatuses) {
275 275
 			return false;
276 276
 		}
277 277
 		return true;
@@ -284,45 +284,44 @@  discard block
 block discarded – undo
284 284
 	public function getStoredResults(
285 285
 		EntityId $entityId
286 286
 	) {
287
-		$value = $this->cache->get( $entityId, $curTTL, [], $asOf );
288
-		$now = call_user_func( $this->microtime, true );
287
+		$value = $this->cache->get($entityId, $curTTL, [], $asOf);
288
+		$now = call_user_func($this->microtime, true);
289 289
 
290
-		if ( $value === false ) {
290
+		if ($value === false) {
291 291
 			return null;
292 292
 		}
293 293
 
294
-		$ageInSeconds = (int)ceil( $now - $asOf );
294
+		$ageInSeconds = (int) ceil($now - $asOf);
295 295
 
296 296
 		$dependedEntityIds = array_map(
297
-			[ $this->entityIdParser, "parse" ],
298
-			array_keys( $value['latestRevisionIds'] )
297
+			[$this->entityIdParser, "parse"],
298
+			array_keys($value['latestRevisionIds'])
299 299
 		);
300 300
 
301
-		if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) {
301
+		if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) {
302 302
 			return null;
303 303
 		}
304 304
 
305
-		if ( array_key_exists( 'futureTime', $value ) ) {
306
-			$futureTime = TimeValue::newFromArray( $value['futureTime'] );
307
-			if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) {
305
+		if (array_key_exists('futureTime', $value)) {
306
+			$futureTime = TimeValue::newFromArray($value['futureTime']);
307
+			if (!$this->timeValueComparer->isFutureTime($futureTime)) {
308 308
 				return null;
309 309
 			}
310
-			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime );
310
+			$futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime);
311 311
 		} else {
312 312
 			$futureTimeDependencyMetadata = DependencyMetadata::blank();
313 313
 		}
314 314
 
315 315
 		$cachingMetadata = $ageInSeconds > 0 ?
316
-			CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) :
317
-			CachingMetadata::fresh();
316
+			CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh();
318 317
 
319
-		if ( is_array( $value['results'] ) ) {
320
-			array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata );
318
+		if (is_array($value['results'])) {
319
+			array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata);
321 320
 		}
322 321
 
323 322
 		return new CachedCheckConstraintsResponse(
324
-			[ $entityId->getSerialization() => $value['results'] ],
325
-			$this->mergeStoredMetadata( $cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata )
323
+			[$entityId->getSerialization() => $value['results']],
324
+			$this->mergeStoredMetadata($cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata)
326 325
 		);
327 326
 	}
328 327
 
@@ -337,58 +336,58 @@  discard block
 block discarded – undo
337 336
 		array $dependedEntityIds,
338 337
 		DependencyMetadata $futureTimeDependencyMetadata = null
339 338
 	) {
340
-		return Metadata::merge( [
341
-			Metadata::ofCachingMetadata( $cachingMetadata ),
342
-			Metadata::ofDependencyMetadata( array_reduce(
339
+		return Metadata::merge([
340
+			Metadata::ofCachingMetadata($cachingMetadata),
341
+			Metadata::ofDependencyMetadata(array_reduce(
343 342
 				$dependedEntityIds,
344
-				function( DependencyMetadata $metadata, EntityId $entityId ) {
345
-					return DependencyMetadata::merge( [
343
+				function(DependencyMetadata $metadata, EntityId $entityId) {
344
+					return DependencyMetadata::merge([
346 345
 						$metadata,
347
-						DependencyMetadata::ofEntityId( $entityId )
348
-					] );
346
+						DependencyMetadata::ofEntityId($entityId)
347
+					]);
349 348
 				},
350 349
 				$futureTimeDependencyMetadata
351
-			) )
352
-		] );
350
+			))
351
+		]);
353 352
 	}
354 353
 
355 354
 	/**
356 355
 	 * @param EntityId[] $entityIds
357 356
 	 * @return int[]
358 357
 	 */
359
-	private function getLatestRevisionIds( array $entityIds ) {
358
+	private function getLatestRevisionIds(array $entityIds) {
360 359
 		$revisionInformations = $this->wikiPageEntityMetaDataAccessor->loadRevisionInformation(
361 360
 			$entityIds,
362 361
 			EntityRevisionLookup::LATEST_FROM_REPLICA
363 362
 		);
364 363
 		$latestRevisionIds = [];
365
-		foreach ( $revisionInformations as $serialization => $revisionInformation ) {
364
+		foreach ($revisionInformations as $serialization => $revisionInformation) {
366 365
 			$latestRevisionIds[$serialization] = $revisionInformation->page_latest;
367 366
 		}
368 367
 		return $latestRevisionIds;
369 368
 	}
370 369
 
371
-	public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) {
372
-		if ( $key === 'cached' ) {
373
-			$element = CachingMetadata::merge( [
370
+	public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) {
371
+		if ($key === 'cached') {
372
+			$element = CachingMetadata::merge([
374 373
 				$cachingMetadata,
375
-				CachingMetadata::ofArray( $element ),
376
-			] )->toArray();
374
+				CachingMetadata::ofArray($element),
375
+			])->toArray();
377 376
 		}
378 377
 		if (
379
-			is_array( $element ) &&
380
-			array_key_exists( 'constraint', $element ) &&
381
-			in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true )
378
+			is_array($element) &&
379
+			array_key_exists('constraint', $element) &&
380
+			in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true)
382 381
 		) {
383
-			$element['cached'] = CachingMetadata::merge( [
382
+			$element['cached'] = CachingMetadata::merge([
384 383
 				$cachingMetadata,
385 384
 				CachingMetadata::ofArray(
386
-					array_key_exists( 'cached', $element ) ? $element['cached'] : null
385
+					array_key_exists('cached', $element) ? $element['cached'] : null
387 386
 				),
388
-			] )->toArray();
387
+			])->toArray();
389 388
 		}
390
-		if ( is_array( $element ) ) {
391
-			array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata );
389
+		if (is_array($element)) {
390
+			array_walk($element, [$this, __FUNCTION__], $cachingMetadata);
392 391
 		}
393 392
 	}
394 393
 
@@ -397,7 +396,7 @@  discard block
 block discarded – undo
397 396
 	 *
398 397
 	 * @param callable $microtime
399 398
 	 */
400
-	public function setMicrotimeFunction( callable $microtime ) {
399
+	public function setMicrotimeFunction(callable $microtime) {
401 400
 		$this->microtime = $microtime;
402 401
 	}
403 402
 
Please login to merge, or discard this patch.