@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | ) { |
151 | 151 | $results = []; |
152 | 152 | $metadatas = []; |
153 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
153 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
154 | 154 | $storedEntityIds = []; |
155 | - foreach ( $entityIds as $entityId ) { |
|
156 | - $storedResults = $this->getStoredResults( $entityId ); |
|
157 | - if ( $storedResults !== null ) { |
|
158 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
159 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
160 | - if ( in_array( $checkResult->getStatus(), $statuses ) ) { |
|
155 | + foreach ($entityIds as $entityId) { |
|
156 | + $storedResults = $this->getStoredResults($entityId); |
|
157 | + if ($storedResults !== null) { |
|
158 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
159 | + foreach ($storedResults->getArray() as $checkResult) { |
|
160 | + if (in_array($checkResult->getStatus(), $statuses)) { |
|
161 | 161 | $results[] = $checkResult; |
162 | 162 | } |
163 | 163 | } |
@@ -165,19 +165,19 @@ discard block |
||
165 | 165 | $storedEntityIds[] = $entityId; |
166 | 166 | } |
167 | 167 | } |
168 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
168 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
169 | 169 | } |
170 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
171 | - if ( $entityIds !== [] ) { |
|
172 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
170 | + if ($entityIds !== [] || $claimIds !== []) { |
|
171 | + if ($entityIds !== []) { |
|
172 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
173 | 173 | } |
174 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
175 | - $results = array_merge( $results, $response->getArray() ); |
|
174 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
175 | + $results = array_merge($results, $response->getArray()); |
|
176 | 176 | $metadatas[] = $response->getMetadata(); |
177 | 177 | } |
178 | 178 | return new CachedCheckResults( |
179 | 179 | $results, |
180 | - Metadata::merge( $metadatas ) |
|
180 | + Metadata::merge($metadatas) |
|
181 | 181 | ); |
182 | 182 | } |
183 | 183 | |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | array $constraintIds = null, |
201 | 201 | array $statuses |
202 | 202 | ) { |
203 | - if ( $claimIds !== [] ) { |
|
203 | + if ($claimIds !== []) { |
|
204 | 204 | return false; |
205 | 205 | } |
206 | - if ( $constraintIds !== null ) { |
|
206 | + if ($constraintIds !== null) { |
|
207 | 207 | return false; |
208 | 208 | } |
209 | - if ( array_diff( $statuses, $this->cachedStatuses ) !== [] ) { |
|
209 | + if (array_diff($statuses, $this->cachedStatuses) !== []) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | return true; |
@@ -225,11 +225,11 @@ discard block |
||
225 | 225 | array $constraintIds = null, |
226 | 226 | array $statuses |
227 | 227 | ) { |
228 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
228 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
229 | 229 | |
230 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
231 | - foreach ( $entityIds as $entityId ) { |
|
232 | - $this->storeResults( $entityId, $results ); |
|
230 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
231 | + foreach ($entityIds as $entityId) { |
|
232 | + $this->storeResults($entityId, $results); |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | array $constraintIds = null, |
261 | 261 | array $statuses |
262 | 262 | ) { |
263 | - if ( $constraintIds !== null ) { |
|
263 | + if ($constraintIds !== null) { |
|
264 | 264 | return false; |
265 | 265 | } |
266 | - if ( array_diff( $this->cachedStatuses, $statuses ) !== [] ) { |
|
266 | + if (array_diff($this->cachedStatuses, $statuses) !== []) { |
|
267 | 267 | return false; |
268 | 268 | } |
269 | 269 | return true; |
@@ -277,23 +277,23 @@ discard block |
||
277 | 277 | * May include check results for other entity IDs as well, |
278 | 278 | * or check results with statuses that we’re not interested in caching. |
279 | 279 | */ |
280 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
280 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
281 | 281 | $latestRevisionIds = $this->getLatestRevisionIds( |
282 | 282 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
283 | 283 | ); |
284 | - if ( $latestRevisionIds === null ) { |
|
284 | + if ($latestRevisionIds === null) { |
|
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
288 | 288 | $resultSerializations = []; |
289 | - foreach ( $results->getArray() as $checkResult ) { |
|
290 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
289 | + foreach ($results->getArray() as $checkResult) { |
|
290 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
291 | 291 | continue; |
292 | 292 | } |
293 | - if ( !in_array( $checkResult->getStatus(), $this->cachedStatuses ) ) { |
|
293 | + if (!in_array($checkResult->getStatus(), $this->cachedStatuses)) { |
|
294 | 294 | continue; |
295 | 295 | } |
296 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
296 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | $value = [ |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | 'latestRevisionIds' => $latestRevisionIds, |
302 | 302 | ]; |
303 | 303 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
304 | - if ( $futureTime !== null ) { |
|
304 | + if ($futureTime !== null) { |
|
305 | 305 | $value['futureTime'] = $futureTime->getArrayValue(); |
306 | 306 | } |
307 | 307 | |
308 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
308 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -315,30 +315,29 @@ discard block |
||
315 | 315 | public function getStoredResults( |
316 | 316 | EntityId $entityId |
317 | 317 | ) { |
318 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
319 | - $now = call_user_func( $this->microtime, true ); |
|
318 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
319 | + $now = call_user_func($this->microtime, true); |
|
320 | 320 | |
321 | - $dependencyMetadata = $this->checkDependencyMetadata( $value ); |
|
322 | - if ( $dependencyMetadata === null ) { |
|
321 | + $dependencyMetadata = $this->checkDependencyMetadata($value); |
|
322 | + if ($dependencyMetadata === null) { |
|
323 | 323 | return null; |
324 | 324 | } |
325 | 325 | |
326 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
326 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
327 | 327 | $cachingMetadata = $ageInSeconds > 0 ? |
328 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
329 | - CachingMetadata::fresh(); |
|
328 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
330 | 329 | |
331 | 330 | $results = []; |
332 | - foreach ( $value['results'] as $resultSerialization ) { |
|
333 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
331 | + foreach ($value['results'] as $resultSerialization) { |
|
332 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
334 | 333 | } |
335 | 334 | |
336 | 335 | return new CachedCheckResults( |
337 | 336 | $results, |
338 | - Metadata::merge( [ |
|
339 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
340 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
341 | - ] ) |
|
337 | + Metadata::merge([ |
|
338 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
339 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
340 | + ]) |
|
342 | 341 | ); |
343 | 342 | } |
344 | 343 | |
@@ -350,37 +349,37 @@ discard block |
||
350 | 349 | * @return DependencyMetadata|null the dependency metadata, |
351 | 350 | * or null if $value should no longer be used |
352 | 351 | */ |
353 | - private function checkDependencyMetadata( $value ) { |
|
354 | - if ( $value === false ) { |
|
352 | + private function checkDependencyMetadata($value) { |
|
353 | + if ($value === false) { |
|
355 | 354 | return null; |
356 | 355 | } |
357 | 356 | |
358 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
359 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
360 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
357 | + if (array_key_exists('futureTime', $value)) { |
|
358 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
359 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
361 | 360 | return null; |
362 | 361 | } |
363 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
362 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
364 | 363 | } else { |
365 | 364 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
366 | 365 | } |
367 | 366 | |
368 | 367 | $dependedEntityIds = array_map( |
369 | - [ $this->entityIdParser, "parse" ], |
|
370 | - array_keys( $value['latestRevisionIds'] ) |
|
368 | + [$this->entityIdParser, "parse"], |
|
369 | + array_keys($value['latestRevisionIds']) |
|
371 | 370 | ); |
372 | 371 | |
373 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
372 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
374 | 373 | return null; |
375 | 374 | } |
376 | 375 | |
377 | 376 | return array_reduce( |
378 | 377 | $dependedEntityIds, |
379 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
380 | - return DependencyMetadata::merge( [ |
|
378 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
379 | + return DependencyMetadata::merge([ |
|
381 | 380 | $metadata, |
382 | - DependencyMetadata::ofEntityId( $entityId ) |
|
383 | - ] ); |
|
381 | + DependencyMetadata::ofEntityId($entityId) |
|
382 | + ]); |
|
384 | 383 | }, |
385 | 384 | $futureTimeDependencyMetadata |
386 | 385 | ); |
@@ -400,13 +399,13 @@ discard block |
||
400 | 399 | array $resultSerialization, |
401 | 400 | CachingMetadata $cachingMetadata |
402 | 401 | ) { |
403 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
404 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
402 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
403 | + if ($this->isPossiblyStaleResult($result)) { |
|
405 | 404 | $result->withMetadata( |
406 | - Metadata::merge( [ |
|
405 | + Metadata::merge([ |
|
407 | 406 | $result->getMetadata(), |
408 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
409 | - ] ) |
|
407 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
408 | + ]) |
|
410 | 409 | ); |
411 | 410 | } |
412 | 411 | return $result; |
@@ -416,7 +415,7 @@ discard block |
||
416 | 415 | * @param CheckResult $result |
417 | 416 | * @return bool |
418 | 417 | */ |
419 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
418 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
420 | 419 | return in_array( |
421 | 420 | $result->getConstraint()->getConstraintTypeItemId(), |
422 | 421 | $this->possiblyStaleConstraintTypes |
@@ -428,14 +427,14 @@ discard block |
||
428 | 427 | * @return int[]|null array from entity ID serializations to revision ID, |
429 | 428 | * or null to indicate that not all revision IDs could be loaded |
430 | 429 | */ |
431 | - private function getLatestRevisionIds( array $entityIds ) { |
|
432 | - if ( $entityIds === [] ) { |
|
430 | + private function getLatestRevisionIds(array $entityIds) { |
|
431 | + if ($entityIds === []) { |
|
433 | 432 | $this->loggingHelper->logEmptyDependencyMetadata(); |
434 | 433 | return []; |
435 | 434 | } |
436 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
435 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
437 | 436 | // one of those entities will probably be edited soon, so might as well skip caching |
438 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
437 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
439 | 438 | return null; |
440 | 439 | } |
441 | 440 | |
@@ -443,7 +442,7 @@ discard block |
||
443 | 442 | $entityIds, |
444 | 443 | EntityRevisionLookup::LATEST_FROM_REPLICA |
445 | 444 | ); |
446 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
445 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
447 | 446 | return null; |
448 | 447 | } |
449 | 448 | return $latestRevisionIds; |
@@ -453,8 +452,8 @@ discard block |
||
453 | 452 | * @param array $array |
454 | 453 | * @return bool |
455 | 454 | */ |
456 | - private function hasFalseElements( array $array ) { |
|
457 | - return in_array( false, $array, true ); |
|
455 | + private function hasFalseElements(array $array) { |
|
456 | + return in_array(false, $array, true); |
|
458 | 457 | } |
459 | 458 | |
460 | 459 | /** |
@@ -462,7 +461,7 @@ discard block |
||
462 | 461 | * |
463 | 462 | * @param callable $microtime |
464 | 463 | */ |
465 | - public function setMicrotimeFunction( callable $microtime ) { |
|
464 | + public function setMicrotimeFunction(callable $microtime) { |
|
466 | 465 | $this->microtime = $microtime; |
467 | 466 | } |
468 | 467 |