@@ -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,14 +228,14 @@ 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 | 241 | $value = [ |
@@ -243,10 +243,10 @@ discard block |
||
243 | 243 | 'latestRevisionIds' => $latestRevisionIds, |
244 | 244 | ]; |
245 | 245 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
246 | - if ( $futureTime !== null ) { |
|
246 | + if ($futureTime !== null) { |
|
247 | 247 | $value['futureTime'] = $futureTime->getArrayValue(); |
248 | 248 | } |
249 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
249 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -278,10 +278,10 @@ discard block |
||
278 | 278 | array $constraintIds = null, |
279 | 279 | array $statuses |
280 | 280 | ) { |
281 | - if ( $constraintIds !== null ) { |
|
281 | + if ($constraintIds !== null) { |
|
282 | 282 | return false; |
283 | 283 | } |
284 | - if ( $statuses != $this->cachedStatuses ) { |
|
284 | + if ($statuses != $this->cachedStatuses) { |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | return true; |
@@ -294,45 +294,44 @@ discard block |
||
294 | 294 | public function getStoredResults( |
295 | 295 | EntityId $entityId |
296 | 296 | ) { |
297 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
298 | - $now = call_user_func( $this->microtime, true ); |
|
297 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
298 | + $now = call_user_func($this->microtime, true); |
|
299 | 299 | |
300 | - if ( $value === false ) { |
|
300 | + if ($value === false) { |
|
301 | 301 | return null; |
302 | 302 | } |
303 | 303 | |
304 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
304 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
305 | 305 | |
306 | 306 | $dependedEntityIds = array_map( |
307 | - [ $this->entityIdParser, "parse" ], |
|
308 | - array_keys( $value['latestRevisionIds'] ) |
|
307 | + [$this->entityIdParser, "parse"], |
|
308 | + array_keys($value['latestRevisionIds']) |
|
309 | 309 | ); |
310 | 310 | |
311 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
311 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
312 | 312 | return null; |
313 | 313 | } |
314 | 314 | |
315 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
316 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
317 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
315 | + if (array_key_exists('futureTime', $value)) { |
|
316 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
317 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
318 | 318 | return null; |
319 | 319 | } |
320 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
320 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
321 | 321 | } else { |
322 | 322 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
323 | 323 | } |
324 | 324 | |
325 | 325 | $cachingMetadata = $ageInSeconds > 0 ? |
326 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
327 | - CachingMetadata::fresh(); |
|
326 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
328 | 327 | |
329 | - if ( is_array( $value['results'] ) ) { |
|
330 | - array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata ); |
|
328 | + if (is_array($value['results'])) { |
|
329 | + array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata); |
|
331 | 330 | } |
332 | 331 | |
333 | 332 | return new CachedCheckConstraintsResponse( |
334 | - [ $entityId->getSerialization() => $value['results'] ], |
|
335 | - $this->mergeStoredMetadata( $cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata ) |
|
333 | + [$entityId->getSerialization() => $value['results']], |
|
334 | + $this->mergeStoredMetadata($cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata) |
|
336 | 335 | ); |
337 | 336 | } |
338 | 337 | |
@@ -347,19 +346,19 @@ discard block |
||
347 | 346 | array $dependedEntityIds, |
348 | 347 | DependencyMetadata $futureTimeDependencyMetadata = null |
349 | 348 | ) { |
350 | - return Metadata::merge( [ |
|
351 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
352 | - Metadata::ofDependencyMetadata( array_reduce( |
|
349 | + return Metadata::merge([ |
|
350 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
351 | + Metadata::ofDependencyMetadata(array_reduce( |
|
353 | 352 | $dependedEntityIds, |
354 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
355 | - return DependencyMetadata::merge( [ |
|
353 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
354 | + return DependencyMetadata::merge([ |
|
356 | 355 | $metadata, |
357 | - DependencyMetadata::ofEntityId( $entityId ) |
|
358 | - ] ); |
|
356 | + DependencyMetadata::ofEntityId($entityId) |
|
357 | + ]); |
|
359 | 358 | }, |
360 | 359 | $futureTimeDependencyMetadata |
361 | - ) ) |
|
362 | - ] ); |
|
360 | + )) |
|
361 | + ]); |
|
363 | 362 | } |
364 | 363 | |
365 | 364 | /** |
@@ -367,14 +366,14 @@ discard block |
||
367 | 366 | * @return int[]|null array from entity ID serializations to revision ID, |
368 | 367 | * or null to indicate that not all revision IDs could be loaded |
369 | 368 | */ |
370 | - private function getLatestRevisionIds( array $entityIds ) { |
|
371 | - if ( $entityIds === [] ) { |
|
369 | + private function getLatestRevisionIds(array $entityIds) { |
|
370 | + if ($entityIds === []) { |
|
372 | 371 | $this->loggingHelper->logEmptyDependencyMetadata(); |
373 | 372 | return []; |
374 | 373 | } |
375 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
374 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
376 | 375 | // one of those entities will probably be edited soon, so might as well skip caching |
377 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
376 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
378 | 377 | return null; |
379 | 378 | } |
380 | 379 | |
@@ -382,11 +381,11 @@ discard block |
||
382 | 381 | $entityIds, |
383 | 382 | EntityRevisionLookup::LATEST_FROM_REPLICA |
384 | 383 | ); |
385 | - if ( $this->hasFalseElements( $revisionInformations ) ) { |
|
384 | + if ($this->hasFalseElements($revisionInformations)) { |
|
386 | 385 | return null; |
387 | 386 | } |
388 | 387 | $latestRevisionIds = []; |
389 | - foreach ( $revisionInformations as $serialization => $revisionInformation ) { |
|
388 | + foreach ($revisionInformations as $serialization => $revisionInformation) { |
|
390 | 389 | $latestRevisionIds[$serialization] = $revisionInformation->page_latest; |
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 |
@@ -36,29 +36,29 @@ discard block |
||
36 | 36 | $statementPropertyId, |
37 | 37 | $statementGuid |
38 | 38 | ) { |
39 | - if ( !array_key_exists( $entityId, $container ) ) { |
|
39 | + if (!array_key_exists($entityId, $container)) { |
|
40 | 40 | $container[$entityId] = []; |
41 | 41 | } |
42 | 42 | $entityContainer = &$container[$entityId]; |
43 | 43 | |
44 | - if ( !array_key_exists( 'claims', $entityContainer ) ) { |
|
44 | + if (!array_key_exists('claims', $entityContainer)) { |
|
45 | 45 | $entityContainer['claims'] = []; |
46 | 46 | } |
47 | 47 | $claimsContainer = &$entityContainer['claims']; |
48 | 48 | |
49 | - if ( !array_key_exists( $statementPropertyId, $claimsContainer ) ) { |
|
49 | + if (!array_key_exists($statementPropertyId, $claimsContainer)) { |
|
50 | 50 | $claimsContainer[$statementPropertyId] = []; |
51 | 51 | } |
52 | 52 | $propertyContainer = &$claimsContainer[$statementPropertyId]; |
53 | 53 | |
54 | - foreach ( $propertyContainer as &$statement ) { |
|
55 | - if ( $statement['id'] === $statementGuid ) { |
|
54 | + foreach ($propertyContainer as &$statement) { |
|
55 | + if ($statement['id'] === $statementGuid) { |
|
56 | 56 | $statementArray = &$statement; |
57 | 57 | break; |
58 | 58 | } |
59 | 59 | } |
60 | - if ( !isset( $statementArray ) ) { |
|
61 | - $statementArray = [ 'id' => $statementGuid ]; |
|
60 | + if (!isset($statementArray)) { |
|
61 | + $statementArray = ['id' => $statementGuid]; |
|
62 | 62 | $propertyContainer[] = &$statementArray; |
63 | 63 | } |
64 | 64 | |
@@ -73,19 +73,19 @@ discard block |
||
73 | 73 | * @param array[] &$container |
74 | 74 | * @return array |
75 | 75 | */ |
76 | - abstract protected function &getMainArray( array &$container ); |
|
76 | + abstract protected function &getMainArray(array &$container); |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param array|null $result |
80 | 80 | * @param array[] &$container |
81 | 81 | */ |
82 | - public function storeCheckResultInArray( array $result = null, array &$container ) { |
|
83 | - $mainArray = &$this->getMainArray( $container ); |
|
84 | - if ( !array_key_exists( 'results', $mainArray ) ) { |
|
82 | + public function storeCheckResultInArray(array $result = null, array &$container) { |
|
83 | + $mainArray = &$this->getMainArray($container); |
|
84 | + if (!array_key_exists('results', $mainArray)) { |
|
85 | 85 | $mainArray['results'] = []; |
86 | 86 | } |
87 | 87 | |
88 | - if ( $result !== null ) { |
|
88 | + if ($result !== null) { |
|
89 | 89 | $mainArray['results'][] = $result; |
90 | 90 | } |
91 | 91 | } |
@@ -86,6 +86,6 @@ |
||
86 | 86 | * @param array|null $result |
87 | 87 | * @param array[] &$container |
88 | 88 | */ |
89 | - public function storeCheckResultInArray( array $result = null, array &$container ); |
|
89 | + public function storeCheckResultInArray(array $result = null, array &$container); |
|
90 | 90 | |
91 | 91 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | return $this->snakHash; |
62 | 62 | } |
63 | 63 | |
64 | - protected function &getMainArray( array &$container ) { |
|
64 | + protected function &getMainArray(array &$container) { |
|
65 | 65 | $statementArray = &$this->getStatementArray( |
66 | 66 | $container, |
67 | 67 | $this->entityId, |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | $this->statementGuid |
70 | 70 | ); |
71 | 71 | |
72 | - if ( !array_key_exists( 'mainsnak', $statementArray ) ) { |
|
73 | - $statementArray['mainsnak'] = [ 'hash' => $this->snakHash ]; |
|
72 | + if (!array_key_exists('mainsnak', $statementArray)) { |
|
73 | + $statementArray['mainsnak'] = ['hash' => $this->snakHash]; |
|
74 | 74 | } |
75 | 75 | $mainsnakArray = &$statementArray['mainsnak']; |
76 | 76 |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | return $this->snakHash; |
78 | 78 | } |
79 | 79 | |
80 | - protected function &getMainArray( array &$container ) { |
|
80 | + protected function &getMainArray(array &$container) { |
|
81 | 81 | $statementArray = &$this->getStatementArray( |
82 | 82 | $container, |
83 | 83 | $this->entityId, |
@@ -85,37 +85,37 @@ discard block |
||
85 | 85 | $this->statementGuid |
86 | 86 | ); |
87 | 87 | |
88 | - if ( !array_key_exists( 'references', $statementArray ) ) { |
|
88 | + if (!array_key_exists('references', $statementArray)) { |
|
89 | 89 | $statementArray['references'] = []; |
90 | 90 | } |
91 | 91 | $referencesArray = &$statementArray['references']; |
92 | 92 | |
93 | - foreach ( $referencesArray as &$potentialReferenceArray ) { |
|
94 | - if ( $potentialReferenceArray['hash'] === $this->referenceHash ) { |
|
93 | + foreach ($referencesArray as &$potentialReferenceArray) { |
|
94 | + if ($potentialReferenceArray['hash'] === $this->referenceHash) { |
|
95 | 95 | $referenceArray = &$potentialReferenceArray; |
96 | 96 | break; |
97 | 97 | } |
98 | 98 | } |
99 | - if ( !isset( $referenceArray ) ) { |
|
100 | - $referenceArray = [ 'hash' => $this->referenceHash, 'snaks' => [] ]; |
|
99 | + if (!isset($referenceArray)) { |
|
100 | + $referenceArray = ['hash' => $this->referenceHash, 'snaks' => []]; |
|
101 | 101 | $referencesArray[] = &$referenceArray; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $snaksArray = &$referenceArray['snaks']; |
105 | 105 | |
106 | - if ( !array_key_exists( $this->snakPropertyId, $snaksArray ) ) { |
|
106 | + if (!array_key_exists($this->snakPropertyId, $snaksArray)) { |
|
107 | 107 | $snaksArray[$this->snakPropertyId] = []; |
108 | 108 | } |
109 | 109 | $propertyArray = &$snaksArray[$this->snakPropertyId]; |
110 | 110 | |
111 | - foreach ( $propertyArray as &$potentialSnakArray ) { |
|
112 | - if ( $potentialSnakArray['hash'] === $this->snakHash ) { |
|
111 | + foreach ($propertyArray as &$potentialSnakArray) { |
|
112 | + if ($potentialSnakArray['hash'] === $this->snakHash) { |
|
113 | 113 | $snakArray = &$potentialSnakArray; |
114 | 114 | break; |
115 | 115 | } |
116 | 116 | } |
117 | - if ( !isset( $snakArray ) ) { |
|
118 | - $snakArray = [ 'hash' => $this->snakHash ]; |
|
117 | + if (!isset($snakArray)) { |
|
118 | + $snakArray = ['hash' => $this->snakHash]; |
|
119 | 119 | $propertyArray[] = &$snakArray; |
120 | 120 | } |
121 | 121 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | return $this->snakHash; |
70 | 70 | } |
71 | 71 | |
72 | - protected function &getMainArray( array &$container ) { |
|
72 | + protected function &getMainArray(array &$container) { |
|
73 | 73 | $statementArray = &$this->getStatementArray( |
74 | 74 | $container, |
75 | 75 | $this->entityId, |
@@ -77,24 +77,24 @@ discard block |
||
77 | 77 | $this->statementGuid |
78 | 78 | ); |
79 | 79 | |
80 | - if ( !array_key_exists( 'qualifiers', $statementArray ) ) { |
|
80 | + if (!array_key_exists('qualifiers', $statementArray)) { |
|
81 | 81 | $statementArray['qualifiers'] = []; |
82 | 82 | } |
83 | 83 | $qualifiersArray = &$statementArray['qualifiers']; |
84 | 84 | |
85 | - if ( !array_key_exists( $this->snakPropertyId, $qualifiersArray ) ) { |
|
85 | + if (!array_key_exists($this->snakPropertyId, $qualifiersArray)) { |
|
86 | 86 | $qualifiersArray[$this->snakPropertyId] = []; |
87 | 87 | } |
88 | 88 | $propertyArray = &$qualifiersArray[$this->snakPropertyId]; |
89 | 89 | |
90 | - foreach ( $propertyArray as &$potentialQualifierArray ) { |
|
91 | - if ( $potentialQualifierArray['hash'] === $this->snakHash ) { |
|
90 | + foreach ($propertyArray as &$potentialQualifierArray) { |
|
91 | + if ($potentialQualifierArray['hash'] === $this->snakHash) { |
|
92 | 92 | $qualifierArray = &$potentialQualifierArray; |
93 | 93 | break; |
94 | 94 | } |
95 | 95 | } |
96 | - if ( !isset( $qualifierArray ) ) { |
|
97 | - $qualifierArray = [ 'hash' => $this->snakHash ]; |
|
96 | + if (!isset($qualifierArray)) { |
|
97 | + $qualifierArray = ['hash' => $this->snakHash]; |
|
98 | 98 | $propertyArray[] = &$qualifierArray; |
99 | 99 | } |
100 | 100 |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | callable $defaultResults = null |
138 | 138 | ) { |
139 | 139 | |
140 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
141 | - if ( $entity instanceof StatementListProvider ) { |
|
140 | + $entity = $this->entityLookup->getEntity($entityId); |
|
141 | + if ($entity instanceof StatementListProvider) { |
|
142 | 142 | $result = $this->checkEveryStatement( |
143 | - $this->entityLookup->getEntity( $entityId ), |
|
143 | + $this->entityLookup->getEntity($entityId), |
|
144 | 144 | $constraintIds, |
145 | 145 | $defaultResults |
146 | 146 | ); |
147 | - $output = $this->sortResult( $result ); |
|
147 | + $output = $this->sortResult($result); |
|
148 | 148 | return $output; |
149 | 149 | } |
150 | 150 | |
@@ -170,19 +170,19 @@ discard block |
||
170 | 170 | callable $defaultResults = null |
171 | 171 | ) { |
172 | 172 | |
173 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
173 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
174 | 174 | $entityId = $parsedGuid->getEntityId(); |
175 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
176 | - if ( $entity instanceof StatementListProvider ) { |
|
177 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
178 | - if ( $statement ) { |
|
175 | + $entity = $this->entityLookup->getEntity($entityId); |
|
176 | + if ($entity instanceof StatementListProvider) { |
|
177 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
178 | + if ($statement) { |
|
179 | 179 | $result = $this->checkStatement( |
180 | 180 | $entity, |
181 | 181 | $statement, |
182 | 182 | $constraintIds, |
183 | 183 | $defaultResults |
184 | 184 | ); |
185 | - $output = $this->sortResult( $result ); |
|
185 | + $output = $this->sortResult($result); |
|
186 | 186 | return $output; |
187 | 187 | } |
188 | 188 | } |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | return []; |
191 | 191 | } |
192 | 192 | |
193 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
194 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
193 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
194 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
195 | 195 | return [ |
196 | 196 | Context::TYPE_STATEMENT, |
197 | 197 | Context::TYPE_QUALIFIER, |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | ]; |
200 | 200 | } |
201 | 201 | |
202 | - return array_keys( array_filter( |
|
202 | + return array_keys(array_filter( |
|
203 | 203 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
204 | - function ( $resultStatus ) { |
|
204 | + function($resultStatus) { |
|
205 | 205 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
206 | 206 | } |
207 | - ) ); |
|
207 | + )); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -215,32 +215,32 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return ConstraintParameterException[] |
217 | 217 | */ |
218 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
218 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
219 | 219 | $constraintParameters = $constraint->getConstraintParameters(); |
220 | 220 | try { |
221 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
222 | - } catch ( ConstraintParameterException $e ) { |
|
223 | - return [ $e ]; |
|
221 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
222 | + } catch (ConstraintParameterException $e) { |
|
223 | + return [$e]; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | $problems = []; |
227 | 227 | try { |
228 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
229 | - } catch ( ConstraintParameterException $e ) { |
|
228 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
229 | + } catch (ConstraintParameterException $e) { |
|
230 | 230 | $problems[] = $e; |
231 | 231 | } |
232 | 232 | try { |
233 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
234 | - } catch ( ConstraintParameterException $e ) { |
|
233 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
234 | + } catch (ConstraintParameterException $e) { |
|
235 | 235 | $problems[] = $e; |
236 | 236 | } |
237 | 237 | try { |
238 | 238 | $this->constraintParameterParser->parseConstraintScopeParameter( |
239 | 239 | $constraintParameters, |
240 | 240 | $constraint->getConstraintTypeItemId(), |
241 | - $this->getAllowedContextTypes( $constraint ) |
|
241 | + $this->getAllowedContextTypes($constraint) |
|
242 | 242 | ); |
243 | - } catch ( ConstraintParameterException $e ) { |
|
243 | + } catch (ConstraintParameterException $e) { |
|
244 | 244 | $problems[] = $e; |
245 | 245 | } |
246 | 246 | return $problems; |
@@ -253,16 +253,16 @@ discard block |
||
253 | 253 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
254 | 254 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
255 | 255 | */ |
256 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
257 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
256 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
257 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
258 | 258 | $result = []; |
259 | 259 | |
260 | - foreach ( $constraints as $constraint ) { |
|
261 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
260 | + foreach ($constraints as $constraint) { |
|
261 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
262 | 262 | |
263 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
263 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
264 | 264 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
265 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
265 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $result[$constraint->getConstraintId()] = $problems; |
@@ -279,17 +279,17 @@ discard block |
||
279 | 279 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
280 | 280 | * (empty means all parameters okay), or null if constraint is not found |
281 | 281 | */ |
282 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
283 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
284 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
282 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
283 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
284 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
285 | 285 | |
286 | - foreach ( $constraints as $constraint ) { |
|
287 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
288 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
286 | + foreach ($constraints as $constraint) { |
|
287 | + if ($constraint->getConstraintId() === $constraintId) { |
|
288 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
289 | 289 | |
290 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
290 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
291 | 291 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
292 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
292 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | return $problems; |
@@ -314,14 +314,14 @@ discard block |
||
314 | 314 | $result = []; |
315 | 315 | |
316 | 316 | /** @var Statement $statement */ |
317 | - foreach ( $entity->getStatements() as $statement ) { |
|
318 | - $result = array_merge( $result, |
|
317 | + foreach ($entity->getStatements() as $statement) { |
|
318 | + $result = array_merge($result, |
|
319 | 319 | $this->checkStatement( |
320 | 320 | $entity, |
321 | 321 | $statement, |
322 | 322 | $constraintIds, |
323 | 323 | $defaultResults |
324 | - ) ); |
|
324 | + )); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | return $result; |
@@ -343,32 +343,32 @@ discard block |
||
343 | 343 | ) { |
344 | 344 | $result = []; |
345 | 345 | |
346 | - $result = array_merge( $result, |
|
346 | + $result = array_merge($result, |
|
347 | 347 | $this->checkConstraintsForMainSnak( |
348 | 348 | $entity, |
349 | 349 | $statement, |
350 | 350 | $constraintIds, |
351 | 351 | $defaultResults |
352 | - ) ); |
|
352 | + )); |
|
353 | 353 | |
354 | - if ( $this->checkQualifiers ) { |
|
355 | - $result = array_merge( $result, |
|
354 | + if ($this->checkQualifiers) { |
|
355 | + $result = array_merge($result, |
|
356 | 356 | $this->checkConstraintsForQualifiers( |
357 | 357 | $entity, |
358 | 358 | $statement, |
359 | 359 | $constraintIds, |
360 | 360 | $defaultResults |
361 | - ) ); |
|
361 | + )); |
|
362 | 362 | } |
363 | 363 | |
364 | - if ( $this->checkReferences ) { |
|
365 | - $result = array_merge( $result, |
|
364 | + if ($this->checkReferences) { |
|
365 | + $result = array_merge($result, |
|
366 | 366 | $this->checkConstraintsForReferences( |
367 | 367 | $entity, |
368 | 368 | $statement, |
369 | 369 | $constraintIds, |
370 | 370 | $defaultResults |
371 | - ) ); |
|
371 | + )); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | return $result; |
@@ -383,12 +383,12 @@ discard block |
||
383 | 383 | * @param string[]|null $constraintIds |
384 | 384 | * @return Constraint[] |
385 | 385 | */ |
386 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
387 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
388 | - if ( $constraintIds !== null ) { |
|
386 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
387 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
388 | + if ($constraintIds !== null) { |
|
389 | 389 | $constraintsToUse = []; |
390 | - foreach ( $constraints as $constraint ) { |
|
391 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
390 | + foreach ($constraints as $constraint) { |
|
391 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
392 | 392 | $constraintsToUse[] = $constraint; |
393 | 393 | } |
394 | 394 | } |
@@ -412,29 +412,29 @@ discard block |
||
412 | 412 | array $constraintIds = null, |
413 | 413 | callable $defaultResults = null |
414 | 414 | ) { |
415 | - $context = new MainSnakContext( $entity, $statement ); |
|
415 | + $context = new MainSnakContext($entity, $statement); |
|
416 | 416 | $constraints = $this->getConstraintsToUse( |
417 | 417 | $statement->getPropertyId(), |
418 | 418 | $constraintIds |
419 | 419 | ); |
420 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
420 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
421 | 421 | |
422 | - foreach ( $constraints as $constraint ) { |
|
422 | + foreach ($constraints as $constraint) { |
|
423 | 423 | $parameters = $constraint->getConstraintParameters(); |
424 | 424 | try { |
425 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
426 | - } catch ( ConstraintParameterException $e ) { |
|
427 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
425 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
426 | + } catch (ConstraintParameterException $e) { |
|
427 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
428 | 428 | continue; |
429 | 429 | } |
430 | 430 | |
431 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
432 | - $message = wfMessage( 'wbqc-exception-message' )->escaped(); |
|
433 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
431 | + if (in_array($entity->getId(), $exceptions)) { |
|
432 | + $message = wfMessage('wbqc-exception-message')->escaped(); |
|
433 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
434 | 434 | continue; |
435 | 435 | } |
436 | 436 | |
437 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
437 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | return $result; |
@@ -456,24 +456,24 @@ discard block |
||
456 | 456 | ) { |
457 | 457 | $result = []; |
458 | 458 | |
459 | - if ( in_array( |
|
459 | + if (in_array( |
|
460 | 460 | $statement->getPropertyId()->getSerialization(), |
461 | 461 | $this->propertiesWithViolatingQualifiers |
462 | - ) ) { |
|
462 | + )) { |
|
463 | 463 | return $result; |
464 | 464 | } |
465 | 465 | |
466 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
467 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
468 | - if ( $defaultResults !== null ) { |
|
469 | - $result = array_merge( $result, $defaultResults( $qualifierContext ) ); |
|
466 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
467 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
468 | + if ($defaultResults !== null) { |
|
469 | + $result = array_merge($result, $defaultResults($qualifierContext)); |
|
470 | 470 | } |
471 | 471 | $qualifierConstraints = $this->getConstraintsToUse( |
472 | 472 | $qualifierContext->getSnak()->getPropertyId(), |
473 | 473 | $constraintIds |
474 | 474 | ); |
475 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
476 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
475 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
476 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
@@ -497,19 +497,19 @@ discard block |
||
497 | 497 | $result = []; |
498 | 498 | |
499 | 499 | /** @var Reference $reference */ |
500 | - foreach ( $statement->getReferences() as $reference ) { |
|
501 | - foreach ( $reference->getSnaks() as $snak ) { |
|
500 | + foreach ($statement->getReferences() as $reference) { |
|
501 | + foreach ($reference->getSnaks() as $snak) { |
|
502 | 502 | $referenceContext = new ReferenceContext( |
503 | 503 | $entity, $statement, $reference, $snak |
504 | 504 | ); |
505 | - if ( $defaultResults !== null ) { |
|
506 | - $result = array_merge( $result, $defaultResults( $referenceContext ) ); |
|
505 | + if ($defaultResults !== null) { |
|
506 | + $result = array_merge($result, $defaultResults($referenceContext)); |
|
507 | 507 | } |
508 | 508 | $referenceConstraints = $this->getConstraintsToUse( |
509 | 509 | $referenceContext->getSnak()->getPropertyId(), |
510 | 510 | $constraintIds |
511 | 511 | ); |
512 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
512 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
513 | 513 | $result[] = $this->getCheckResultFor( |
514 | 514 | $referenceContext, |
515 | 515 | $referenceConstraint |
@@ -528,65 +528,65 @@ discard block |
||
528 | 528 | * @throws InvalidArgumentException |
529 | 529 | * @return CheckResult |
530 | 530 | */ |
531 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
532 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
531 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
532 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
533 | 533 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
534 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
534 | + $result = $this->handleScope($checker, $context, $constraint); |
|
535 | 535 | |
536 | - if ( $result !== null ) { |
|
537 | - $this->addMetadata( $context, $result ); |
|
536 | + if ($result !== null) { |
|
537 | + $this->addMetadata($context, $result); |
|
538 | 538 | return $result; |
539 | 539 | } |
540 | 540 | |
541 | - $startTime = microtime( true ); |
|
541 | + $startTime = microtime(true); |
|
542 | 542 | try { |
543 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
544 | - } catch ( ConstraintParameterException $e ) { |
|
545 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
546 | - } catch ( SparqlHelperException $e ) { |
|
547 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
548 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
543 | + $result = $checker->checkConstraint($context, $constraint); |
|
544 | + } catch (ConstraintParameterException $e) { |
|
545 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
546 | + } catch (SparqlHelperException $e) { |
|
547 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
548 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
549 | 549 | } |
550 | - $endTime = microtime( true ); |
|
550 | + $endTime = microtime(true); |
|
551 | 551 | |
552 | - $this->addMetadata( $context, $result ); |
|
552 | + $this->addMetadata($context, $result); |
|
553 | 553 | |
554 | 554 | try { |
555 | 555 | $constraintStatus = $this->constraintParameterParser |
556 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
557 | - } catch ( ConstraintParameterException $e ) { |
|
558 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
556 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
557 | + } catch (ConstraintParameterException $e) { |
|
558 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
559 | 559 | $constraintStatus = null; |
560 | 560 | } |
561 | - if ( $constraintStatus === null ) { |
|
561 | + if ($constraintStatus === null) { |
|
562 | 562 | // downgrade violation to warning |
563 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
564 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
563 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
564 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
565 | 565 | } |
566 | 566 | } else { |
567 | - if ( $constraintStatus !== 'mandatory' ) { |
|
567 | + if ($constraintStatus !== 'mandatory') { |
|
568 | 568 | // @codeCoverageIgnoreStart |
569 | 569 | throw new LogicException( |
570 | - "Unknown constraint status '$constraintStatus', " . |
|
570 | + "Unknown constraint status '$constraintStatus', ". |
|
571 | 571 | "only known status is 'mandatory'" |
572 | 572 | ); |
573 | 573 | // @codeCoverageIgnoreEnd |
574 | 574 | } |
575 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
575 | + $result->addParameter('constraint_status', $constraintStatus); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | $this->loggingHelper->logConstraintCheck( |
579 | 579 | $context, |
580 | 580 | $constraint, |
581 | 581 | $result, |
582 | - get_class( $checker ), |
|
582 | + get_class($checker), |
|
583 | 583 | $endTime - $startTime, |
584 | 584 | __METHOD__ |
585 | 585 | ); |
586 | 586 | |
587 | 587 | return $result; |
588 | 588 | } else { |
589 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
589 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
590 | 590 | } |
591 | 591 | } |
592 | 592 | |
@@ -600,29 +600,29 @@ discard block |
||
600 | 600 | $constraint->getConstraintParameters(), |
601 | 601 | $constraint->getConstraintTypeItemId() |
602 | 602 | ); |
603 | - } catch ( ConstraintParameterException $e ) { |
|
604 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
603 | + } catch (ConstraintParameterException $e) { |
|
604 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
605 | 605 | } |
606 | - if ( $checkedContextTypes === null ) { |
|
606 | + if ($checkedContextTypes === null) { |
|
607 | 607 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
608 | 608 | } |
609 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
610 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
609 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
610 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
611 | 611 | } |
612 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
613 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
612 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
613 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
614 | 614 | } |
615 | 615 | return null; |
616 | 616 | } |
617 | 617 | |
618 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
619 | - $result->withMetadata( Metadata::merge( [ |
|
618 | + private function addMetadata(Context $context, CheckResult $result) { |
|
619 | + $result->withMetadata(Metadata::merge([ |
|
620 | 620 | $result->getMetadata(), |
621 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
622 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
623 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
624 | - ] ) ), |
|
625 | - ] ) ); |
|
621 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
622 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
623 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
624 | + ])), |
|
625 | + ])); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | /** |
@@ -630,12 +630,12 @@ discard block |
||
630 | 630 | * |
631 | 631 | * @return CheckResult[] |
632 | 632 | */ |
633 | - private function sortResult( array $result ) { |
|
634 | - if ( count( $result ) < 2 ) { |
|
633 | + private function sortResult(array $result) { |
|
634 | + if (count($result) < 2) { |
|
635 | 635 | return $result; |
636 | 636 | } |
637 | 637 | |
638 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
638 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
639 | 639 | $orderNum = 0; |
640 | 640 | $order = [ |
641 | 641 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -651,45 +651,45 @@ discard block |
||
651 | 651 | $statusA = $a->getStatus(); |
652 | 652 | $statusB = $b->getStatus(); |
653 | 653 | |
654 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
655 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
654 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
655 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
656 | 656 | |
657 | - if ( $orderA === $orderB ) { |
|
657 | + if ($orderA === $orderB) { |
|
658 | 658 | $pidA = $a->getContextCursor()->getSnakPropertyId(); |
659 | 659 | $pidB = $b->getContextCursor()->getSnakPropertyId(); |
660 | 660 | |
661 | - if ( $pidA === $pidB ) { |
|
661 | + if ($pidA === $pidB) { |
|
662 | 662 | $hashA = $a->getContextCursor()->getSnakHash(); |
663 | 663 | $hashB = $b->getContextCursor()->getSnakHash(); |
664 | 664 | |
665 | - if ( $hashA === $hashB ) { |
|
666 | - if ( $a instanceof NullResult ) { |
|
665 | + if ($hashA === $hashB) { |
|
666 | + if ($a instanceof NullResult) { |
|
667 | 667 | return $b instanceof NullResult ? 0 : -1; |
668 | 668 | } |
669 | - if ( $b instanceof NullResult ) { |
|
669 | + if ($b instanceof NullResult) { |
|
670 | 670 | return $a instanceof NullResult ? 0 : 1; |
671 | 671 | } |
672 | 672 | |
673 | 673 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
674 | 674 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
675 | 675 | |
676 | - if ( $typeA == $typeB ) { |
|
676 | + if ($typeA == $typeB) { |
|
677 | 677 | return 0; |
678 | 678 | } else { |
679 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
679 | + return ($typeA > $typeB) ? 1 : -1; |
|
680 | 680 | } |
681 | 681 | } else { |
682 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
682 | + return ($hashA > $hashB) ? 1 : -1; |
|
683 | 683 | } |
684 | 684 | } else { |
685 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
685 | + return ($pidA > $pidB) ? 1 : -1; |
|
686 | 686 | } |
687 | 687 | } else { |
688 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
688 | + return ($orderA > $orderB) ? 1 : -1; |
|
689 | 689 | } |
690 | 690 | }; |
691 | 691 | |
692 | - uasort( $result, $sortFunction ); |
|
692 | + uasort($result, $sortFunction); |
|
693 | 693 | |
694 | 694 | return $result; |
695 | 695 | } |
@@ -84,65 +84,64 @@ discard block |
||
84 | 84 | ) { |
85 | 85 | $response = []; |
86 | 86 | $metadatas = []; |
87 | - $statusesFlipped = array_flip( $statuses ); |
|
88 | - foreach ( $entityIds as $entityId ) { |
|
87 | + $statusesFlipped = array_flip($statuses); |
|
88 | + foreach ($entityIds as $entityId) { |
|
89 | 89 | $results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnEntityId( |
90 | 90 | $entityId, |
91 | 91 | $constraintIds, |
92 | - [ $this, 'defaultResults' ] |
|
92 | + [$this, 'defaultResults'] |
|
93 | 93 | ); |
94 | - foreach ( $results as $result ) { |
|
94 | + foreach ($results as $result) { |
|
95 | 95 | $metadatas[] = $result->getMetadata(); |
96 | - if ( $this->statusSelected( $statusesFlipped, $result ) ) { |
|
97 | - $resultArray = $this->checkResultToArray( $result ); |
|
98 | - $result->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
96 | + if ($this->statusSelected($statusesFlipped, $result)) { |
|
97 | + $resultArray = $this->checkResultToArray($result); |
|
98 | + $result->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | - foreach ( $claimIds as $claimId ) { |
|
102 | + foreach ($claimIds as $claimId) { |
|
103 | 103 | $results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnClaimId( |
104 | 104 | $claimId, |
105 | 105 | $constraintIds, |
106 | - [ $this, 'defaultResults' ] |
|
106 | + [$this, 'defaultResults'] |
|
107 | 107 | ); |
108 | - foreach ( $results as $result ) { |
|
108 | + foreach ($results as $result) { |
|
109 | 109 | $metadatas[] = $result->getMetadata(); |
110 | - if ( $this->statusSelected( $statusesFlipped, $result ) ) { |
|
111 | - $resultArray = $this->checkResultToArray( $result ); |
|
112 | - $result->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
110 | + if ($this->statusSelected($statusesFlipped, $result)) { |
|
111 | + $resultArray = $this->checkResultToArray($result); |
|
112 | + $result->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | } |
116 | 116 | return new CachedCheckConstraintsResponse( |
117 | 117 | $response, |
118 | - Metadata::merge( $metadatas ) |
|
118 | + Metadata::merge($metadatas) |
|
119 | 119 | ); |
120 | 120 | } |
121 | 121 | |
122 | - public function defaultResults( Context $context ) { |
|
122 | + public function defaultResults(Context $context) { |
|
123 | 123 | return $context->getType() === Context::TYPE_STATEMENT ? |
124 | - [ new NullResult( $context ) ] : |
|
125 | - []; |
|
124 | + [new NullResult($context)] : []; |
|
126 | 125 | } |
127 | 126 | |
128 | - public function statusSelected( array $statusesFlipped, CheckResult $result ) { |
|
129 | - return array_key_exists( $result->getStatus(), $statusesFlipped ) || |
|
127 | + public function statusSelected(array $statusesFlipped, CheckResult $result) { |
|
128 | + return array_key_exists($result->getStatus(), $statusesFlipped) || |
|
130 | 129 | $result instanceof NullResult; |
131 | 130 | } |
132 | 131 | |
133 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
134 | - if ( $checkResult instanceof NullResult ) { |
|
132 | + public function checkResultToArray(CheckResult $checkResult) { |
|
133 | + if ($checkResult instanceof NullResult) { |
|
135 | 134 | return null; |
136 | 135 | } |
137 | 136 | |
138 | 137 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
139 | 138 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
140 | - $constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
139 | + $constraintPropertyId = new PropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
141 | 140 | |
142 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
143 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
141 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
142 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
144 | 143 | // TODO link to the statement when possible (T169224) |
145 | - $link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
144 | + $link = $title->getFullURL().'#'.$this->config->get('WBQualityConstraintsPropertyConstraintId'); |
|
146 | 145 | |
147 | 146 | $constraint = [ |
148 | 147 | 'id' => $constraintId, |
@@ -151,11 +150,11 @@ discard block |
||
151 | 150 | 'link' => $link, |
152 | 151 | 'discussLink' => $title->getTalkPage()->getFullURL(), |
153 | 152 | ]; |
154 | - if ( $this->config->get( 'WBQualityConstraintsIncludeDetailInApi' ) ) { |
|
153 | + if ($this->config->get('WBQualityConstraintsIncludeDetailInApi')) { |
|
155 | 154 | $parameters = $checkResult->getParameters(); |
156 | 155 | $constraint += [ |
157 | 156 | 'detail' => $parameters, |
158 | - 'detailHTML' => $this->constraintParameterRenderer->formatParameters( $parameters ), |
|
157 | + 'detailHTML' => $this->constraintParameterRenderer->formatParameters($parameters), |
|
159 | 158 | ]; |
160 | 159 | } |
161 | 160 | |
@@ -165,14 +164,14 @@ discard block |
||
165 | 164 | 'constraint' => $constraint |
166 | 165 | ]; |
167 | 166 | $message = $checkResult->getMessage(); |
168 | - if ( $message ) { |
|
169 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
167 | + if ($message) { |
|
168 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
170 | 169 | } |
171 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
170 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
172 | 171 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
173 | 172 | } |
174 | 173 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
175 | - if ( $cachingMetadataArray !== null ) { |
|
174 | + if ($cachingMetadataArray !== null) { |
|
176 | 175 | $result['cached'] = $cachingMetadataArray; |
177 | 176 | } |
178 | 177 |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | $status = self::STATUS_TODO, |
123 | 123 | $message = null |
124 | 124 | ) { |
125 | - if ( $contextCursor instanceof Context ) { |
|
125 | + if ($contextCursor instanceof Context) { |
|
126 | 126 | $context = $contextCursor; |
127 | 127 | $this->contextCursor = $context->getCursor(); |
128 | 128 | $this->snakType = $context->getSnak()->getType(); |
129 | 129 | $mainSnak = $context->getSnak(); |
130 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
130 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
131 | 131 | $this->dataValue = $mainSnak->getDataValue(); |
132 | 132 | } else { |
133 | 133 | $this->dataValue = null; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @param string $key |
191 | 191 | * @param string $value |
192 | 192 | */ |
193 | - public function addParameter( $key, $value ) { |
|
193 | + public function addParameter($key, $value) { |
|
194 | 194 | $this->parameters[$key][] = $value; |
195 | 195 | } |
196 | 196 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | /** |
205 | 205 | * @param string $status |
206 | 206 | */ |
207 | - public function setStatus( $status ) { |
|
207 | + public function setStatus($status) { |
|
208 | 208 | $this->status = $status; |
209 | 209 | } |
210 | 210 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @param Metadata $metadata |
220 | 220 | * @return self |
221 | 221 | */ |
222 | - public function withMetadata( Metadata $metadata ) { |
|
222 | + public function withMetadata(Metadata $metadata) { |
|
223 | 223 | $this->metadata = $metadata; |
224 | 224 | return $this; |
225 | 225 | } |