@@ -106,26 +106,26 @@ discard block |
||
106 | 106 | ) { |
107 | 107 | $results = []; |
108 | 108 | $metadatas = []; |
109 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds ) ) { |
|
109 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds)) { |
|
110 | 110 | $storedEntityIds = []; |
111 | - foreach ( $entityIds as $entityId ) { |
|
112 | - $storedResults = $this->getStoredResults( $entityId ); |
|
113 | - if ( $storedResults !== null ) { |
|
111 | + foreach ($entityIds as $entityId) { |
|
112 | + $storedResults = $this->getStoredResults($entityId); |
|
113 | + if ($storedResults !== null) { |
|
114 | 114 | $results += $storedResults->getArray(); |
115 | 115 | $metadatas[] = $storedResults->getMetadata(); |
116 | 116 | $storedEntityIds[] = $entityId; |
117 | 117 | } |
118 | 118 | } |
119 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
119 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
120 | 120 | } |
121 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
122 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds ); |
|
121 | + if ($entityIds !== [] || $claimIds !== []) { |
|
122 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds); |
|
123 | 123 | $results += $response->getArray(); |
124 | 124 | $metadatas[] = $response->getMetadata(); |
125 | 125 | } |
126 | 126 | return new CachedCheckConstraintsResponse( |
127 | 127 | $results, |
128 | - Metadata::merge( $metadatas ) |
|
128 | + Metadata::merge($metadatas) |
|
129 | 129 | ); |
130 | 130 | } |
131 | 131 | |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | array $claimIds, |
159 | 159 | array $constraintIds = null |
160 | 160 | ) { |
161 | - $results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds ); |
|
161 | + $results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds); |
|
162 | 162 | |
163 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds ) ) { |
|
164 | - foreach ( $entityIds as $entityId ) { |
|
163 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds)) { |
|
164 | + foreach ($entityIds as $entityId) { |
|
165 | 165 | $value = [ |
166 | 166 | 'results' => $results->getArray()[$entityId->getSerialization()], |
167 | 167 | 'latestRevisionIds' => $this->getLatestRevisionIds( |
168 | 168 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
169 | 169 | ), |
170 | 170 | ]; |
171 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
171 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -201,45 +201,44 @@ discard block |
||
201 | 201 | public function getStoredResults( |
202 | 202 | EntityId $entityId |
203 | 203 | ) { |
204 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
205 | - $now = call_user_func( $this->microtime, true ); |
|
204 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
205 | + $now = call_user_func($this->microtime, true); |
|
206 | 206 | |
207 | - if ( $value === false ) { |
|
207 | + if ($value === false) { |
|
208 | 208 | return null; |
209 | 209 | } |
210 | 210 | |
211 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
211 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
212 | 212 | |
213 | 213 | $dependedEntityIds = array_map( |
214 | - [ $this->entityIdParser, "parse" ], |
|
215 | - array_keys( $value['latestRevisionIds'] ) |
|
214 | + [$this->entityIdParser, "parse"], |
|
215 | + array_keys($value['latestRevisionIds']) |
|
216 | 216 | ); |
217 | 217 | |
218 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
218 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
219 | 219 | return null; |
220 | 220 | } |
221 | 221 | |
222 | 222 | $cachingMetadata = $ageInSeconds > 0 ? |
223 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
224 | - CachingMetadata::fresh(); |
|
223 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
225 | 224 | |
226 | - if ( is_array( $value['results'] ) ) { |
|
227 | - array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata ); |
|
225 | + if (is_array($value['results'])) { |
|
226 | + array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata); |
|
228 | 227 | } |
229 | 228 | |
230 | 229 | return new CachedCheckConstraintsResponse( |
231 | - [ $entityId->getSerialization() => $value['results'] ], |
|
230 | + [$entityId->getSerialization() => $value['results']], |
|
232 | 231 | array_reduce( |
233 | 232 | $dependedEntityIds, |
234 | - function( Metadata $metadata, EntityId $entityId ) { |
|
235 | - return Metadata::merge( [ |
|
233 | + function(Metadata $metadata, EntityId $entityId) { |
|
234 | + return Metadata::merge([ |
|
236 | 235 | $metadata, |
237 | 236 | Metadata::ofDependencyMetadata( |
238 | - DependencyMetadata::ofEntityId( $entityId ) |
|
237 | + DependencyMetadata::ofEntityId($entityId) |
|
239 | 238 | ) |
240 | - ] ); |
|
239 | + ]); |
|
241 | 240 | }, |
242 | - Metadata::ofCachingMetadata( $cachingMetadata ) |
|
241 | + Metadata::ofCachingMetadata($cachingMetadata) |
|
243 | 242 | ) |
244 | 243 | ); |
245 | 244 | } |
@@ -248,37 +247,37 @@ discard block |
||
248 | 247 | * @param EntityId[] $entityIds |
249 | 248 | * @return int[] |
250 | 249 | */ |
251 | - private function getLatestRevisionIds( array $entityIds ) { |
|
250 | + private function getLatestRevisionIds(array $entityIds) { |
|
252 | 251 | $latestRevisionIds = []; |
253 | - foreach ( $entityIds as $entityId ) { |
|
252 | + foreach ($entityIds as $entityId) { |
|
254 | 253 | $serialization = $entityId->getSerialization(); |
255 | - $latestRevisionId = $this->entityRevisionLookup->getLatestRevisionId( $entityId ); |
|
254 | + $latestRevisionId = $this->entityRevisionLookup->getLatestRevisionId($entityId); |
|
256 | 255 | $latestRevisionIds[$serialization] = $latestRevisionId; |
257 | 256 | } |
258 | 257 | return $latestRevisionIds; |
259 | 258 | } |
260 | 259 | |
261 | - public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) { |
|
262 | - if ( $key === 'cached' ) { |
|
263 | - $element = CachingMetadata::merge( [ |
|
260 | + public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) { |
|
261 | + if ($key === 'cached') { |
|
262 | + $element = CachingMetadata::merge([ |
|
264 | 263 | $cachingMetadata, |
265 | - CachingMetadata::ofArray( $element ), |
|
266 | - ] )->toArray(); |
|
264 | + CachingMetadata::ofArray($element), |
|
265 | + ])->toArray(); |
|
267 | 266 | } |
268 | 267 | if ( |
269 | - is_array( $element ) && |
|
270 | - array_key_exists( 'constraint', $element ) && |
|
271 | - in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true ) |
|
268 | + is_array($element) && |
|
269 | + array_key_exists('constraint', $element) && |
|
270 | + in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true) |
|
272 | 271 | ) { |
273 | - $element['cached'] = CachingMetadata::merge( [ |
|
272 | + $element['cached'] = CachingMetadata::merge([ |
|
274 | 273 | $cachingMetadata, |
275 | 274 | CachingMetadata::ofArray( |
276 | - array_key_exists( 'cached', $element ) ? $element['cached'] : null |
|
275 | + array_key_exists('cached', $element) ? $element['cached'] : null |
|
277 | 276 | ), |
278 | - ] )->toArray(); |
|
277 | + ])->toArray(); |
|
279 | 278 | } |
280 | - if ( is_array( $element ) ) { |
|
281 | - array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata ); |
|
279 | + if (is_array($element)) { |
|
280 | + array_walk($element, [$this, __FUNCTION__], $cachingMetadata); |
|
282 | 281 | } |
283 | 282 | } |
284 | 283 | |
@@ -287,7 +286,7 @@ discard block |
||
287 | 286 | * |
288 | 287 | * @param callable $microtime |
289 | 288 | */ |
290 | - public function setMicrotimeFunction( callable $microtime ) { |
|
289 | + public function setMicrotimeFunction(callable $microtime) { |
|
291 | 290 | $this->microtime = $microtime; |
292 | 291 | } |
293 | 292 |