@@ -151,30 +151,30 @@ discard block |
||
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 | - if ( $entityIds !== [] ) { |
|
169 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
167 | + if ($entityIds !== [] || $claimIds !== []) { |
|
168 | + if ($entityIds !== []) { |
|
169 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
170 | 170 | } |
171 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
171 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
172 | 172 | $results += $response->getArray(); |
173 | 173 | $metadatas[] = $response->getMetadata(); |
174 | 174 | } |
175 | 175 | return new CachedCheckConstraintsResponse( |
176 | 176 | $results, |
177 | - Metadata::merge( $metadatas ) |
|
177 | + Metadata::merge($metadatas) |
|
178 | 178 | ); |
179 | 179 | } |
180 | 180 | |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | array $constraintIds = null, |
204 | 204 | array $statuses |
205 | 205 | ) { |
206 | - if ( $claimIds !== [] ) { |
|
206 | + if ($claimIds !== []) { |
|
207 | 207 | return false; |
208 | 208 | } |
209 | - if ( $constraintIds !== null ) { |
|
209 | + if ($constraintIds !== null) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | - if ( $statuses != $this->cachedStatuses ) { |
|
212 | + if ($statuses != $this->cachedStatuses) { |
|
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | return true; |
@@ -228,17 +228,17 @@ discard block |
||
228 | 228 | array $constraintIds = null, |
229 | 229 | array $statuses |
230 | 230 | ) { |
231 | - $results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
231 | + $results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
232 | 232 | |
233 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
234 | - foreach ( $entityIds as $entityId ) { |
|
233 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
234 | + foreach ($entityIds as $entityId) { |
|
235 | 235 | $latestRevisionIds = $this->getLatestRevisionIds( |
236 | 236 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
237 | 237 | ); |
238 | - if ( $latestRevisionIds === null ) { |
|
238 | + if ($latestRevisionIds === null) { |
|
239 | 239 | continue; |
240 | 240 | } |
241 | - if ( !array_key_exists( $entityId->getSerialization(), $results->getArray() ) ) { |
|
241 | + if (!array_key_exists($entityId->getSerialization(), $results->getArray())) { |
|
242 | 242 | // T189842 – don’t store buggy results; TODO: fix that task properly |
243 | 243 | continue; |
244 | 244 | } |
@@ -247,10 +247,10 @@ discard block |
||
247 | 247 | 'latestRevisionIds' => $latestRevisionIds, |
248 | 248 | ]; |
249 | 249 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
250 | - if ( $futureTime !== null ) { |
|
250 | + if ($futureTime !== null) { |
|
251 | 251 | $value['futureTime'] = $futureTime->getArrayValue(); |
252 | 252 | } |
253 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
253 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -282,10 +282,10 @@ discard block |
||
282 | 282 | array $constraintIds = null, |
283 | 283 | array $statuses |
284 | 284 | ) { |
285 | - if ( $constraintIds !== null ) { |
|
285 | + if ($constraintIds !== null) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | - if ( $statuses != $this->cachedStatuses ) { |
|
288 | + if ($statuses != $this->cachedStatuses) { |
|
289 | 289 | return false; |
290 | 290 | } |
291 | 291 | return true; |
@@ -298,45 +298,44 @@ discard block |
||
298 | 298 | public function getStoredResults( |
299 | 299 | EntityId $entityId |
300 | 300 | ) { |
301 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
302 | - $now = call_user_func( $this->microtime, true ); |
|
301 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
302 | + $now = call_user_func($this->microtime, true); |
|
303 | 303 | |
304 | - if ( $value === false ) { |
|
304 | + if ($value === false) { |
|
305 | 305 | return null; |
306 | 306 | } |
307 | 307 | |
308 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
308 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
309 | 309 | |
310 | 310 | $dependedEntityIds = array_map( |
311 | - [ $this->entityIdParser, "parse" ], |
|
312 | - array_keys( $value['latestRevisionIds'] ) |
|
311 | + [$this->entityIdParser, "parse"], |
|
312 | + array_keys($value['latestRevisionIds']) |
|
313 | 313 | ); |
314 | 314 | |
315 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
315 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
316 | 316 | return null; |
317 | 317 | } |
318 | 318 | |
319 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
320 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
321 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
319 | + if (array_key_exists('futureTime', $value)) { |
|
320 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
321 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
322 | 322 | return null; |
323 | 323 | } |
324 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
324 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
325 | 325 | } else { |
326 | 326 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
327 | 327 | } |
328 | 328 | |
329 | 329 | $cachingMetadata = $ageInSeconds > 0 ? |
330 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
331 | - CachingMetadata::fresh(); |
|
330 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
332 | 331 | |
333 | - if ( is_array( $value['results'] ) ) { |
|
334 | - array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata ); |
|
332 | + if (is_array($value['results'])) { |
|
333 | + array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata); |
|
335 | 334 | } |
336 | 335 | |
337 | 336 | return new CachedCheckConstraintsResponse( |
338 | - [ $entityId->getSerialization() => $value['results'] ], |
|
339 | - $this->mergeStoredMetadata( $cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata ) |
|
337 | + [$entityId->getSerialization() => $value['results']], |
|
338 | + $this->mergeStoredMetadata($cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata) |
|
340 | 339 | ); |
341 | 340 | } |
342 | 341 | |
@@ -351,19 +350,19 @@ discard block |
||
351 | 350 | array $dependedEntityIds, |
352 | 351 | DependencyMetadata $futureTimeDependencyMetadata = null |
353 | 352 | ) { |
354 | - return Metadata::merge( [ |
|
355 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
356 | - Metadata::ofDependencyMetadata( array_reduce( |
|
353 | + return Metadata::merge([ |
|
354 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
355 | + Metadata::ofDependencyMetadata(array_reduce( |
|
357 | 356 | $dependedEntityIds, |
358 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
359 | - return DependencyMetadata::merge( [ |
|
357 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
358 | + return DependencyMetadata::merge([ |
|
360 | 359 | $metadata, |
361 | - DependencyMetadata::ofEntityId( $entityId ) |
|
362 | - ] ); |
|
360 | + DependencyMetadata::ofEntityId($entityId) |
|
361 | + ]); |
|
363 | 362 | }, |
364 | 363 | $futureTimeDependencyMetadata |
365 | - ) ) |
|
366 | - ] ); |
|
364 | + )) |
|
365 | + ]); |
|
367 | 366 | } |
368 | 367 | |
369 | 368 | /** |
@@ -371,14 +370,14 @@ discard block |
||
371 | 370 | * @return int[]|null array from entity ID serializations to revision ID, |
372 | 371 | * or null to indicate that not all revision IDs could be loaded |
373 | 372 | */ |
374 | - private function getLatestRevisionIds( array $entityIds ) { |
|
375 | - if ( $entityIds === [] ) { |
|
373 | + private function getLatestRevisionIds(array $entityIds) { |
|
374 | + if ($entityIds === []) { |
|
376 | 375 | $this->loggingHelper->logEmptyDependencyMetadata(); |
377 | 376 | return []; |
378 | 377 | } |
379 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
378 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
380 | 379 | // one of those entities will probably be edited soon, so might as well skip caching |
381 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
380 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
382 | 381 | return null; |
383 | 382 | } |
384 | 383 | |
@@ -386,7 +385,7 @@ discard block |
||
386 | 385 | $entityIds, |
387 | 386 | EntityRevisionLookup::LATEST_FROM_REPLICA |
388 | 387 | ); |
389 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
388 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
390 | 389 | return null; |
391 | 390 | } |
392 | 391 | return $latestRevisionIds; |
@@ -396,31 +395,31 @@ discard block |
||
396 | 395 | * @param array $array |
397 | 396 | * @return bool |
398 | 397 | */ |
399 | - private function hasFalseElements( array $array ) { |
|
400 | - return in_array( false, $array, true ); |
|
398 | + private function hasFalseElements(array $array) { |
|
399 | + return in_array(false, $array, true); |
|
401 | 400 | } |
402 | 401 | |
403 | - public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) { |
|
404 | - if ( $key === 'cached' ) { |
|
405 | - $element = CachingMetadata::merge( [ |
|
402 | + public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) { |
|
403 | + if ($key === 'cached') { |
|
404 | + $element = CachingMetadata::merge([ |
|
406 | 405 | $cachingMetadata, |
407 | - CachingMetadata::ofArray( $element ), |
|
408 | - ] )->toArray(); |
|
406 | + CachingMetadata::ofArray($element), |
|
407 | + ])->toArray(); |
|
409 | 408 | } |
410 | 409 | if ( |
411 | - is_array( $element ) && |
|
412 | - array_key_exists( 'constraint', $element ) && |
|
413 | - in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true ) |
|
410 | + is_array($element) && |
|
411 | + array_key_exists('constraint', $element) && |
|
412 | + in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true) |
|
414 | 413 | ) { |
415 | - $element['cached'] = CachingMetadata::merge( [ |
|
414 | + $element['cached'] = CachingMetadata::merge([ |
|
416 | 415 | $cachingMetadata, |
417 | 416 | CachingMetadata::ofArray( |
418 | - array_key_exists( 'cached', $element ) ? $element['cached'] : null |
|
417 | + array_key_exists('cached', $element) ? $element['cached'] : null |
|
419 | 418 | ), |
420 | - ] )->toArray(); |
|
419 | + ])->toArray(); |
|
421 | 420 | } |
422 | - if ( is_array( $element ) ) { |
|
423 | - array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata ); |
|
421 | + if (is_array($element)) { |
|
422 | + array_walk($element, [$this, __FUNCTION__], $cachingMetadata); |
|
424 | 423 | } |
425 | 424 | } |
426 | 425 | |
@@ -429,7 +428,7 @@ discard block |
||
429 | 428 | * |
430 | 429 | * @param callable $microtime |
431 | 430 | */ |
432 | - public function setMicrotimeFunction( callable $microtime ) { |
|
431 | + public function setMicrotimeFunction(callable $microtime) { |
|
433 | 432 | $this->microtime = $microtime; |
434 | 433 | } |
435 | 434 |