@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | CheckResult::STATUS_SUGGESTION, |
145 | 145 | CheckResult::STATUS_BAD_PARAMETERS, |
146 | 146 | ]; |
147 | - $this->cachedStatusesFlipped = array_flip( $this->cachedStatuses ); |
|
147 | + $this->cachedStatusesFlipped = array_flip($this->cachedStatuses); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | public function getResults( |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | ) { |
156 | 156 | $results = []; |
157 | 157 | $metadatas = []; |
158 | - $statusesFlipped = array_flip( $statuses ); |
|
159 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
158 | + $statusesFlipped = array_flip($statuses); |
|
159 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
160 | 160 | $storedEntityIds = []; |
161 | - foreach ( $entityIds as $entityId ) { |
|
162 | - $storedResults = $this->getStoredResults( $entityId ); |
|
163 | - if ( $storedResults !== null ) { |
|
164 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
165 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
166 | - if ( $this->statusSelected( $statusesFlipped, $checkResult ) ) { |
|
161 | + foreach ($entityIds as $entityId) { |
|
162 | + $storedResults = $this->getStoredResults($entityId); |
|
163 | + if ($storedResults !== null) { |
|
164 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
165 | + foreach ($storedResults->getArray() as $checkResult) { |
|
166 | + if ($this->statusSelected($statusesFlipped, $checkResult)) { |
|
167 | 167 | $results[] = $checkResult; |
168 | 168 | } |
169 | 169 | } |
@@ -171,19 +171,19 @@ discard block |
||
171 | 171 | $storedEntityIds[] = $entityId; |
172 | 172 | } |
173 | 173 | } |
174 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
174 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
175 | 175 | } |
176 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
177 | - if ( $entityIds !== [] ) { |
|
178 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
176 | + if ($entityIds !== [] || $claimIds !== []) { |
|
177 | + if ($entityIds !== []) { |
|
178 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
179 | 179 | } |
180 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
181 | - $results = array_merge( $results, $response->getArray() ); |
|
180 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
181 | + $results = array_merge($results, $response->getArray()); |
|
182 | 182 | $metadatas[] = $response->getMetadata(); |
183 | 183 | } |
184 | 184 | return new CachedCheckResults( |
185 | 185 | $results, |
186 | - Metadata::merge( $metadatas ) |
|
186 | + Metadata::merge($metadatas) |
|
187 | 187 | ); |
188 | 188 | } |
189 | 189 | |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | ?array $constraintIds, |
207 | 207 | array $statuses |
208 | 208 | ) { |
209 | - if ( $claimIds !== [] ) { |
|
209 | + if ($claimIds !== []) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | - if ( $constraintIds !== null ) { |
|
212 | + if ($constraintIds !== null) { |
|
213 | 213 | return false; |
214 | 214 | } |
215 | - if ( array_diff( $statuses, $this->cachedStatuses ) !== [] ) { |
|
215 | + if (array_diff($statuses, $this->cachedStatuses) !== []) { |
|
216 | 216 | return false; |
217 | 217 | } |
218 | 218 | return true; |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | * @param CheckResult $result |
228 | 228 | * @return bool |
229 | 229 | */ |
230 | - private function statusSelected( array $statusesFlipped, CheckResult $result ) { |
|
231 | - return array_key_exists( $result->getStatus(), $statusesFlipped ) || |
|
230 | + private function statusSelected(array $statusesFlipped, CheckResult $result) { |
|
231 | + return array_key_exists($result->getStatus(), $statusesFlipped) || |
|
232 | 232 | $result instanceof NullResult; |
233 | 233 | } |
234 | 234 | |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | ?array $constraintIds, |
246 | 246 | array $statuses |
247 | 247 | ) { |
248 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
248 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
249 | 249 | |
250 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
251 | - foreach ( $entityIds as $entityId ) { |
|
252 | - $this->storeResults( $entityId, $results ); |
|
250 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
251 | + foreach ($entityIds as $entityId) { |
|
252 | + $this->storeResults($entityId, $results); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | ?array $constraintIds, |
281 | 281 | array $statuses |
282 | 282 | ) { |
283 | - if ( $constraintIds !== null ) { |
|
283 | + if ($constraintIds !== null) { |
|
284 | 284 | return false; |
285 | 285 | } |
286 | - if ( array_diff( $this->cachedStatuses, $statuses ) !== [] ) { |
|
286 | + if (array_diff($this->cachedStatuses, $statuses) !== []) { |
|
287 | 287 | return false; |
288 | 288 | } |
289 | 289 | return true; |
@@ -297,21 +297,21 @@ discard block |
||
297 | 297 | * May include check results for other entity IDs as well, |
298 | 298 | * or check results with statuses that we’re not interested in caching. |
299 | 299 | */ |
300 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
300 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
301 | 301 | $latestRevisionIds = $this->getLatestRevisionIds( |
302 | 302 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
303 | 303 | ); |
304 | - if ( $latestRevisionIds === null ) { |
|
304 | + if ($latestRevisionIds === null) { |
|
305 | 305 | return; |
306 | 306 | } |
307 | 307 | |
308 | 308 | $resultSerializations = []; |
309 | - foreach ( $results->getArray() as $checkResult ) { |
|
310 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
309 | + foreach ($results->getArray() as $checkResult) { |
|
310 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
311 | 311 | continue; |
312 | 312 | } |
313 | - if ( $this->statusSelected( $this->cachedStatusesFlipped, $checkResult ) ) { |
|
314 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
313 | + if ($this->statusSelected($this->cachedStatusesFlipped, $checkResult)) { |
|
314 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
@@ -320,11 +320,11 @@ discard block |
||
320 | 320 | 'latestRevisionIds' => $latestRevisionIds, |
321 | 321 | ]; |
322 | 322 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
323 | - if ( $futureTime !== null ) { |
|
323 | + if ($futureTime !== null) { |
|
324 | 324 | $value['futureTime'] = $futureTime->getArrayValue(); |
325 | 325 | } |
326 | 326 | |
327 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
327 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -338,31 +338,30 @@ discard block |
||
338 | 338 | EntityId $entityId, |
339 | 339 | $forRevision = 0 |
340 | 340 | ) { |
341 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
342 | - $now = call_user_func( $this->microtime, true ); |
|
341 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
342 | + $now = call_user_func($this->microtime, true); |
|
343 | 343 | |
344 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
345 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
346 | - if ( $dependencyMetadata === null ) { |
|
344 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
345 | + [$entityId->getSerialization() => $forRevision]); |
|
346 | + if ($dependencyMetadata === null) { |
|
347 | 347 | return null; |
348 | 348 | } |
349 | 349 | |
350 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
350 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
351 | 351 | $cachingMetadata = $ageInSeconds > 0 ? |
352 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
353 | - CachingMetadata::fresh(); |
|
352 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
354 | 353 | |
355 | 354 | $results = []; |
356 | - foreach ( $value['results'] as $resultSerialization ) { |
|
357 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
355 | + foreach ($value['results'] as $resultSerialization) { |
|
356 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
358 | 357 | } |
359 | 358 | |
360 | 359 | return new CachedCheckResults( |
361 | 360 | $results, |
362 | - Metadata::merge( [ |
|
363 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
364 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
365 | - ] ) |
|
361 | + Metadata::merge([ |
|
362 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
363 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
364 | + ]) |
|
366 | 365 | ); |
367 | 366 | } |
368 | 367 | |
@@ -378,43 +377,43 @@ discard block |
||
378 | 377 | * @return DependencyMetadata|null the dependency metadata, |
379 | 378 | * or null if $value should no longer be used |
380 | 379 | */ |
381 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
382 | - if ( $value === false ) { |
|
380 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
381 | + if ($value === false) { |
|
383 | 382 | return null; |
384 | 383 | } |
385 | 384 | |
386 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
387 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
388 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
385 | + if (array_key_exists('futureTime', $value)) { |
|
386 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
387 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
389 | 388 | return null; |
390 | 389 | } |
391 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
390 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
392 | 391 | } else { |
393 | 392 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
394 | 393 | } |
395 | 394 | |
396 | - foreach ( $paramRevs as $id => $revision ) { |
|
397 | - if ( $revision > 0 ) { |
|
398 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
395 | + foreach ($paramRevs as $id => $revision) { |
|
396 | + if ($revision > 0) { |
|
397 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
399 | 398 | } |
400 | 399 | } |
401 | 400 | |
402 | 401 | $dependedEntityIds = array_map( |
403 | - [ $this->entityIdParser, "parse" ], |
|
404 | - array_keys( $value['latestRevisionIds'] ) |
|
402 | + [$this->entityIdParser, "parse"], |
|
403 | + array_keys($value['latestRevisionIds']) |
|
405 | 404 | ); |
406 | 405 | |
407 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
406 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
408 | 407 | return null; |
409 | 408 | } |
410 | 409 | |
411 | 410 | return array_reduce( |
412 | 411 | $dependedEntityIds, |
413 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
414 | - return DependencyMetadata::merge( [ |
|
412 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
413 | + return DependencyMetadata::merge([ |
|
415 | 414 | $metadata, |
416 | - DependencyMetadata::ofEntityId( $entityId ) |
|
417 | - ] ); |
|
415 | + DependencyMetadata::ofEntityId($entityId) |
|
416 | + ]); |
|
418 | 417 | }, |
419 | 418 | $futureTimeDependencyMetadata |
420 | 419 | ); |
@@ -434,13 +433,13 @@ discard block |
||
434 | 433 | array $resultSerialization, |
435 | 434 | CachingMetadata $cachingMetadata |
436 | 435 | ) { |
437 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
438 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
436 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
437 | + if ($this->isPossiblyStaleResult($result)) { |
|
439 | 438 | $result->withMetadata( |
440 | - Metadata::merge( [ |
|
439 | + Metadata::merge([ |
|
441 | 440 | $result->getMetadata(), |
442 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
443 | - ] ) |
|
441 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
442 | + ]) |
|
444 | 443 | ); |
445 | 444 | } |
446 | 445 | return $result; |
@@ -450,8 +449,8 @@ discard block |
||
450 | 449 | * @param CheckResult $result |
451 | 450 | * @return bool |
452 | 451 | */ |
453 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
454 | - if ( $result instanceof NullResult ) { |
|
452 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
453 | + if ($result instanceof NullResult) { |
|
455 | 454 | return false; |
456 | 455 | } |
457 | 456 | |
@@ -466,14 +465,14 @@ discard block |
||
466 | 465 | * @return int[]|null array from entity ID serializations to revision ID, |
467 | 466 | * or null to indicate that not all revision IDs could be loaded |
468 | 467 | */ |
469 | - private function getLatestRevisionIds( array $entityIds ) { |
|
470 | - if ( $entityIds === [] ) { |
|
468 | + private function getLatestRevisionIds(array $entityIds) { |
|
469 | + if ($entityIds === []) { |
|
471 | 470 | $this->loggingHelper->logEmptyDependencyMetadata(); |
472 | 471 | return []; |
473 | 472 | } |
474 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
473 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
475 | 474 | // one of those entities will probably be edited soon, so might as well skip caching |
476 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
475 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
477 | 476 | return null; |
478 | 477 | } |
479 | 478 | |
@@ -481,7 +480,7 @@ discard block |
||
481 | 480 | $entityIds, |
482 | 481 | EntityRevisionLookup::LATEST_FROM_REPLICA |
483 | 482 | ); |
484 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
483 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
485 | 484 | return null; |
486 | 485 | } |
487 | 486 | return $latestRevisionIds; |
@@ -491,8 +490,8 @@ discard block |
||
491 | 490 | * @param array $array |
492 | 491 | * @return bool |
493 | 492 | */ |
494 | - private function hasFalseElements( array $array ) { |
|
495 | - return in_array( false, $array, true ); |
|
493 | + private function hasFalseElements(array $array) { |
|
494 | + return in_array(false, $array, true); |
|
496 | 495 | } |
497 | 496 | |
498 | 497 | /** |
@@ -500,7 +499,7 @@ discard block |
||
500 | 499 | * |
501 | 500 | * @param callable $microtime |
502 | 501 | */ |
503 | - public function setMicrotimeFunction( callable $microtime ) { |
|
502 | + public function setMicrotimeFunction(callable $microtime) { |
|
504 | 503 | $this->microtime = $microtime; |
505 | 504 | } |
506 | 505 |