@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | ) { |
143 | 143 | $results = []; |
144 | 144 | $metadatas = []; |
145 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
145 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
146 | 146 | $storedEntityIds = []; |
147 | - foreach ( $entityIds as $entityId ) { |
|
148 | - $storedResults = $this->getStoredResults( $entityId ); |
|
149 | - if ( $storedResults !== null ) { |
|
150 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
151 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
152 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
147 | + foreach ($entityIds as $entityId) { |
|
148 | + $storedResults = $this->getStoredResults($entityId); |
|
149 | + if ($storedResults !== null) { |
|
150 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
151 | + foreach ($storedResults->getArray() as $checkResult) { |
|
152 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
153 | 153 | $results[] = $checkResult; |
154 | 154 | } |
155 | 155 | } |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | $storedEntityIds[] = $entityId; |
158 | 158 | } |
159 | 159 | } |
160 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
160 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
161 | 161 | } |
162 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
163 | - if ( $entityIds !== [] ) { |
|
164 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
162 | + if ($entityIds !== [] || $claimIds !== []) { |
|
163 | + if ($entityIds !== []) { |
|
164 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
165 | 165 | } |
166 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
167 | - $results = array_merge( $results, $response->getArray() ); |
|
166 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
167 | + $results = array_merge($results, $response->getArray()); |
|
168 | 168 | $metadatas[] = $response->getMetadata(); |
169 | 169 | } |
170 | 170 | return new CachedCheckResults( |
171 | 171 | $results, |
172 | - Metadata::merge( $metadatas ) |
|
172 | + Metadata::merge($metadatas) |
|
173 | 173 | ); |
174 | 174 | } |
175 | 175 | |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | ?array $constraintIds, |
193 | 193 | array $statuses |
194 | 194 | ) { |
195 | - if ( $claimIds !== [] ) { |
|
195 | + if ($claimIds !== []) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | - if ( $constraintIds !== null ) { |
|
198 | + if ($constraintIds !== null) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
201 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | return true; |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @param CheckResult $result |
214 | 214 | * @return bool |
215 | 215 | */ |
216 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
217 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
216 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
217 | + return in_array($result->getStatus(), $statuses, true) || |
|
218 | 218 | $result instanceof NullResult; |
219 | 219 | } |
220 | 220 | |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | ?array $constraintIds, |
232 | 232 | array $statuses |
233 | 233 | ) { |
234 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
234 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
235 | 235 | |
236 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
237 | - foreach ( $entityIds as $entityId ) { |
|
238 | - $this->storeResults( $entityId, $results ); |
|
236 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
237 | + foreach ($entityIds as $entityId) { |
|
238 | + $this->storeResults($entityId, $results); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | ?array $constraintIds, |
267 | 267 | array $statuses |
268 | 268 | ) { |
269 | - if ( $constraintIds !== null ) { |
|
269 | + if ($constraintIds !== null) { |
|
270 | 270 | return false; |
271 | 271 | } |
272 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
272 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | return true; |
@@ -283,21 +283,21 @@ discard block |
||
283 | 283 | * May include check results for other entity IDs as well, |
284 | 284 | * or check results with statuses that we’re not interested in caching. |
285 | 285 | */ |
286 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
286 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
287 | 287 | $latestRevisionIds = $this->getLatestRevisionIds( |
288 | 288 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
289 | 289 | ); |
290 | - if ( $latestRevisionIds === null ) { |
|
290 | + if ($latestRevisionIds === null) { |
|
291 | 291 | return; |
292 | 292 | } |
293 | 293 | |
294 | 294 | $resultSerializations = []; |
295 | - foreach ( $results->getArray() as $checkResult ) { |
|
296 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
295 | + foreach ($results->getArray() as $checkResult) { |
|
296 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
297 | 297 | continue; |
298 | 298 | } |
299 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
300 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
299 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
300 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | 'latestRevisionIds' => $latestRevisionIds, |
307 | 307 | ]; |
308 | 308 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
309 | - if ( $futureTime !== null ) { |
|
309 | + if ($futureTime !== null) { |
|
310 | 310 | $value['futureTime'] = $futureTime->getArrayValue(); |
311 | 311 | } |
312 | 312 | |
313 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
313 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -324,31 +324,30 @@ discard block |
||
324 | 324 | EntityId $entityId, |
325 | 325 | $forRevision = 0 |
326 | 326 | ) { |
327 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
328 | - $now = call_user_func( $this->microtime, true ); |
|
327 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
328 | + $now = call_user_func($this->microtime, true); |
|
329 | 329 | |
330 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
331 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
332 | - if ( $dependencyMetadata === null ) { |
|
330 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
331 | + [$entityId->getSerialization() => $forRevision]); |
|
332 | + if ($dependencyMetadata === null) { |
|
333 | 333 | return null; |
334 | 334 | } |
335 | 335 | |
336 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
336 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
337 | 337 | $cachingMetadata = $ageInSeconds > 0 ? |
338 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
339 | - CachingMetadata::fresh(); |
|
338 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
340 | 339 | |
341 | 340 | $results = []; |
342 | - foreach ( $value['results'] as $resultSerialization ) { |
|
343 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
341 | + foreach ($value['results'] as $resultSerialization) { |
|
342 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
344 | 343 | } |
345 | 344 | |
346 | 345 | return new CachedCheckResults( |
347 | 346 | $results, |
348 | - Metadata::merge( [ |
|
349 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
350 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
351 | - ] ) |
|
347 | + Metadata::merge([ |
|
348 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
349 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
350 | + ]) |
|
352 | 351 | ); |
353 | 352 | } |
354 | 353 | |
@@ -364,43 +363,43 @@ discard block |
||
364 | 363 | * @return DependencyMetadata|null the dependency metadata, |
365 | 364 | * or null if $value should no longer be used |
366 | 365 | */ |
367 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
368 | - if ( $value === false ) { |
|
366 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
367 | + if ($value === false) { |
|
369 | 368 | return null; |
370 | 369 | } |
371 | 370 | |
372 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
373 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
374 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
371 | + if (array_key_exists('futureTime', $value)) { |
|
372 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
373 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
375 | 374 | return null; |
376 | 375 | } |
377 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
376 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
378 | 377 | } else { |
379 | 378 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
380 | 379 | } |
381 | 380 | |
382 | - foreach ( $paramRevs as $id => $revision ) { |
|
383 | - if ( $revision > 0 ) { |
|
384 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
381 | + foreach ($paramRevs as $id => $revision) { |
|
382 | + if ($revision > 0) { |
|
383 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
385 | 384 | } |
386 | 385 | } |
387 | 386 | |
388 | 387 | $dependedEntityIds = array_map( |
389 | - [ $this->entityIdParser, "parse" ], |
|
390 | - array_keys( $value['latestRevisionIds'] ) |
|
388 | + [$this->entityIdParser, "parse"], |
|
389 | + array_keys($value['latestRevisionIds']) |
|
391 | 390 | ); |
392 | 391 | |
393 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
392 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
394 | 393 | return null; |
395 | 394 | } |
396 | 395 | |
397 | 396 | return array_reduce( |
398 | 397 | $dependedEntityIds, |
399 | - static function ( DependencyMetadata $metadata, EntityId $entityId ) { |
|
400 | - return DependencyMetadata::merge( [ |
|
398 | + static function(DependencyMetadata $metadata, EntityId $entityId) { |
|
399 | + return DependencyMetadata::merge([ |
|
401 | 400 | $metadata, |
402 | - DependencyMetadata::ofEntityId( $entityId ) |
|
403 | - ] ); |
|
401 | + DependencyMetadata::ofEntityId($entityId) |
|
402 | + ]); |
|
404 | 403 | }, |
405 | 404 | $futureTimeDependencyMetadata |
406 | 405 | ); |
@@ -420,13 +419,13 @@ discard block |
||
420 | 419 | array $resultSerialization, |
421 | 420 | CachingMetadata $cachingMetadata |
422 | 421 | ) { |
423 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
424 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
422 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
423 | + if ($this->isPossiblyStaleResult($result)) { |
|
425 | 424 | $result->withMetadata( |
426 | - Metadata::merge( [ |
|
425 | + Metadata::merge([ |
|
427 | 426 | $result->getMetadata(), |
428 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
429 | - ] ) |
|
427 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
428 | + ]) |
|
430 | 429 | ); |
431 | 430 | } |
432 | 431 | return $result; |
@@ -436,8 +435,8 @@ discard block |
||
436 | 435 | * @param CheckResult $result |
437 | 436 | * @return bool |
438 | 437 | */ |
439 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
440 | - if ( $result instanceof NullResult ) { |
|
438 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
439 | + if ($result instanceof NullResult) { |
|
441 | 440 | return false; |
442 | 441 | } |
443 | 442 | |
@@ -452,14 +451,14 @@ discard block |
||
452 | 451 | * @return int[]|null array from entity ID serializations to revision ID, |
453 | 452 | * or null to indicate that not all revision IDs could be loaded |
454 | 453 | */ |
455 | - private function getLatestRevisionIds( array $entityIds ) { |
|
456 | - if ( $entityIds === [] ) { |
|
454 | + private function getLatestRevisionIds(array $entityIds) { |
|
455 | + if ($entityIds === []) { |
|
457 | 456 | $this->loggingHelper->logEmptyDependencyMetadata(); |
458 | 457 | return []; |
459 | 458 | } |
460 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
459 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
461 | 460 | // one of those entities will probably be edited soon, so might as well skip caching |
462 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
461 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
463 | 462 | return null; |
464 | 463 | } |
465 | 464 | |
@@ -467,7 +466,7 @@ discard block |
||
467 | 466 | $entityIds, |
468 | 467 | LookupConstants::LATEST_FROM_REPLICA |
469 | 468 | ); |
470 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
469 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
471 | 470 | return null; |
472 | 471 | } |
473 | 472 | return $latestRevisionIds; |
@@ -477,8 +476,8 @@ discard block |
||
477 | 476 | * @param array $array |
478 | 477 | * @return bool |
479 | 478 | */ |
480 | - private function hasFalseElements( array $array ) { |
|
481 | - return in_array( false, $array, true ); |
|
479 | + private function hasFalseElements(array $array) { |
|
480 | + return in_array(false, $array, true); |
|
482 | 481 | } |
483 | 482 | |
484 | 483 | /** |
@@ -486,7 +485,7 @@ discard block |
||
486 | 485 | * |
487 | 486 | * @param callable $microtime |
488 | 487 | */ |
489 | - public function setMicrotimeFunction( callable $microtime ) { |
|
488 | + public function setMicrotimeFunction(callable $microtime) { |
|
490 | 489 | $this->microtime = $microtime; |
491 | 490 | } |
492 | 491 |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | $this->dataFactory = $dataFactory; |
54 | 54 | $this->logger = $logger; |
55 | 55 | $this->constraintCheckDurationLimits = [ |
56 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
57 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
56 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
57 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
58 | 58 | ]; |
59 | 59 | $this->constraintCheckOnEntityDurationLimits = [ |
60 | - 'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ), |
|
61 | - 'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ), |
|
60 | + 'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'), |
|
61 | + 'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'), |
|
62 | 62 | ]; |
63 | 63 | } |
64 | 64 | |
@@ -69,23 +69,23 @@ discard block |
||
69 | 69 | * @param float $durationSeconds |
70 | 70 | * @return array [ $limitSeconds, $logLevel ] |
71 | 71 | */ |
72 | - private function findLimit( $limits, $durationSeconds ) { |
|
72 | + private function findLimit($limits, $durationSeconds) { |
|
73 | 73 | $limitSeconds = null; |
74 | 74 | $logLevel = null; |
75 | 75 | |
76 | - foreach ( $limits as $level => $limit ) { |
|
76 | + foreach ($limits as $level => $limit) { |
|
77 | 77 | if ( |
78 | 78 | // duration exceeds this limit |
79 | - isset( $limit ) && $durationSeconds > $limit && |
|
79 | + isset($limit) && $durationSeconds > $limit && |
|
80 | 80 | // this limit is longer than previous longest limit |
81 | - ( $limitSeconds === null || $limit > $limitSeconds ) |
|
81 | + ($limitSeconds === null || $limit > $limitSeconds) |
|
82 | 82 | ) { |
83 | 83 | $limitSeconds = $limit; |
84 | 84 | $logLevel = $level; |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - return [ $limitSeconds, $logLevel ]; |
|
88 | + return [$limitSeconds, $logLevel]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -110,31 +110,31 @@ discard block |
||
110 | 110 | $durationSeconds, |
111 | 111 | $method |
112 | 112 | ) { |
113 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
113 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
114 | 114 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
115 | 115 | |
116 | 116 | $this->dataFactory->timing( |
117 | - 'wikibase.quality.constraints.check.timing.' . |
|
118 | - $constraintTypeItemId . '-' . |
|
117 | + 'wikibase.quality.constraints.check.timing.'. |
|
118 | + $constraintTypeItemId.'-'. |
|
119 | 119 | $constraintCheckerClassShortName, |
120 | 120 | $durationSeconds * 1000 |
121 | 121 | ); |
122 | 122 | |
123 | 123 | // find the longest limit (and associated log level) that the duration exceeds |
124 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
124 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
125 | 125 | $this->constraintCheckDurationLimits, |
126 | 126 | $durationSeconds |
127 | 127 | ); |
128 | - if ( $limitSeconds === null ) { |
|
128 | + if ($limitSeconds === null) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
131 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
132 | 132 | // TODO log less details but still log something |
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $resultMessage = $result->getMessage(); |
137 | - if ( $resultMessage !== null ) { |
|
137 | + if ($resultMessage !== null) { |
|
138 | 138 | $resultMessageKey = $resultMessage->getMessageKey(); |
139 | 139 | } else { |
140 | 140 | $resultMessageKey = null; |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | |
143 | 143 | $this->logger->log( |
144 | 144 | $logLevel, |
145 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
146 | - 'took longer than {limitSeconds} second(s) ' . |
|
145 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
146 | + 'took longer than {limitSeconds} second(s) '. |
|
147 | 147 | '(duration: {durationSeconds} seconds).', |
148 | 148 | [ |
149 | 149 | 'method' => $method, |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | 'constraintId' => $constraint->getConstraintId(), |
154 | 154 | 'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(), |
155 | 155 | 'constraintTypeItemId' => $constraintTypeItemId, |
156 | - 'constraintParameters' => json_encode( $constraint->getConstraintParameters() ), |
|
156 | + 'constraintParameters' => json_encode($constraint->getConstraintParameters()), |
|
157 | 157 | 'constraintCheckerClass' => $constraintCheckerClass, |
158 | 158 | 'constraintCheckerClassShortName' => $constraintCheckerClassShortName, |
159 | 159 | 'entityId' => $context->getEntity()->getId()->getSerialization(), |
160 | 160 | 'statementGuid' => $context->getSnakStatement()->getGuid(), |
161 | 161 | 'resultStatus' => $result->getStatus(), |
162 | - 'resultParameters' => json_encode( $result->getParameters() ), |
|
162 | + 'resultParameters' => json_encode($result->getParameters()), |
|
163 | 163 | 'resultMessage' => $resultMessageKey, |
164 | 164 | ] |
165 | 165 | ); |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | ); |
190 | 190 | |
191 | 191 | // find the longest limit (and associated log level) that the duration exceeds |
192 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
192 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
193 | 193 | $this->constraintCheckOnEntityDurationLimits, |
194 | 194 | $durationSeconds |
195 | 195 | ); |
196 | - if ( $limitSeconds === null ) { |
|
196 | + if ($limitSeconds === null) { |
|
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
200 | 200 | $this->logger->log( |
201 | 201 | $logLevel, |
202 | - 'Full constraint check on {entityId} ' . |
|
203 | - 'took longer than {limitSeconds} second(s) ' . |
|
202 | + 'Full constraint check on {entityId} '. |
|
203 | + 'took longer than {limitSeconds} second(s) '. |
|
204 | 204 | '(duration: {durationSeconds} seconds).', |
205 | 205 | [ |
206 | 206 | 'method' => $method, |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @param EntityId $entityId |
220 | 220 | */ |
221 | - public function logCheckConstraintsCacheHit( EntityId $entityId ) { |
|
221 | + public function logCheckConstraintsCacheHit(EntityId $entityId) { |
|
222 | 222 | $this->dataFactory->increment( |
223 | 223 | 'wikibase.quality.constraints.cache.entity.hit' |
224 | 224 | ); |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @param EntityId[] $entityIds |
231 | 231 | */ |
232 | - public function logCheckConstraintsCacheMisses( array $entityIds ) { |
|
232 | + public function logCheckConstraintsCacheMisses(array $entityIds) { |
|
233 | 233 | $this->dataFactory->updateCount( |
234 | 234 | 'wikibase.quality.constraints.cache.entity.miss', |
235 | - count( $entityIds ) |
|
235 | + count($entityIds) |
|
236 | 236 | ); |
237 | 237 | } |
238 | 238 | |
@@ -259,17 +259,17 @@ discard block |
||
259 | 259 | * @param EntityId[] $entityIds |
260 | 260 | * @param int $maxRevisionIds |
261 | 261 | */ |
262 | - public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) { |
|
262 | + public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) { |
|
263 | 263 | $this->logger->log( |
264 | 264 | 'warning', |
265 | - 'Dependency metadata for constraint check result has huge set of entity IDs ' . |
|
266 | - '(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' . |
|
265 | + 'Dependency metadata for constraint check result has huge set of entity IDs '. |
|
266 | + '(count '.count($entityIds).', limit '.$maxRevisionIds.'); '. |
|
267 | 267 | 'caching disabled for this check result.', |
268 | 268 | [ |
269 | 269 | 'loggingMethod' => __METHOD__, |
270 | 270 | 'entityIds' => json_encode( |
271 | 271 | array_map( |
272 | - static function ( EntityId $entityId ) { |
|
272 | + static function(EntityId $entityId) { |
|
273 | 273 | return $entityId->getSerialization(); |
274 | 274 | }, |
275 | 275 | $entityIds |
@@ -288,17 +288,17 @@ discard block |
||
288 | 288 | 'Sparql API replied with status 429 and a retry-after header. Requesting to retry after {retryAfterTime}', |
289 | 289 | [ |
290 | 290 | 'retryAfterTime' => $retryAfterTime, |
291 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
291 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
292 | 292 | 'responseContent' => $request->getContent(), |
293 | 293 | ] |
294 | 294 | ); |
295 | 295 | } |
296 | 296 | |
297 | - public function logSparqlHelperTooManyRequestsRetryAfterInvalid( MWHttpRequest $request ) { |
|
297 | + public function logSparqlHelperTooManyRequestsRetryAfterInvalid(MWHttpRequest $request) { |
|
298 | 298 | $this->logger->warning( |
299 | 299 | 'Sparql API replied with status 429 and no valid retry-after header.', |
300 | 300 | [ |
301 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
301 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
302 | 302 | 'responseContent' => $request->getContent(), |
303 | 303 | ] |
304 | 304 | ); |
@@ -20,13 +20,13 @@ |
||
20 | 20 | * @param PropertyId $propertyId |
21 | 21 | * @return int |
22 | 22 | */ |
23 | - public function getPropertyCount( array $snaks, PropertyId $propertyId ) { |
|
24 | - return count( array_filter( |
|
23 | + public function getPropertyCount(array $snaks, PropertyId $propertyId) { |
|
24 | + return count(array_filter( |
|
25 | 25 | $snaks, |
26 | - static function ( Snak $snak ) use ( $propertyId ) { |
|
27 | - return $snak->getPropertyId()->equals( $propertyId ); |
|
26 | + static function(Snak $snak) use ($propertyId) { |
|
27 | + return $snak->getPropertyId()->equals($propertyId); |
|
28 | 28 | } |
29 | - ) ); |
|
29 | + )); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | } |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | * @param CheckResult $checkResult |
77 | 77 | * @return array |
78 | 78 | */ |
79 | - public function serialize( CheckResult $checkResult ) { |
|
79 | + public function serialize(CheckResult $checkResult) { |
|
80 | 80 | $contextCursor = $checkResult->getContextCursor(); |
81 | 81 | |
82 | 82 | $serialization = [ |
83 | - self::KEY_CONTEXT_CURSOR => $this->contextCursorSerializer->serialize( $contextCursor ), |
|
83 | + self::KEY_CONTEXT_CURSOR => $this->contextCursorSerializer->serialize($contextCursor), |
|
84 | 84 | ]; |
85 | 85 | |
86 | - if ( $checkResult instanceof NullResult ) { |
|
86 | + if ($checkResult instanceof NullResult) { |
|
87 | 87 | $serialization[self::KEY_NULL_RESULT] = 1; |
88 | 88 | } else { |
89 | 89 | $constraint = $checkResult->getConstraint(); |
@@ -91,21 +91,21 @@ discard block |
||
91 | 91 | $violationMessage = $checkResult->getMessage(); |
92 | 92 | |
93 | 93 | $serialization[self::KEY_CONSTRAINT] = |
94 | - $this->constraintSerializer->serialize( $constraint ); |
|
94 | + $this->constraintSerializer->serialize($constraint); |
|
95 | 95 | $serialization[self::KEY_CHECK_RESULT_STATUS] = |
96 | 96 | $checkResult->getStatus(); |
97 | 97 | $serialization[self::KEY_CACHING_METADATA] = |
98 | - $this->serializeCachingMetadata( $cachingMetadata ); |
|
98 | + $this->serializeCachingMetadata($cachingMetadata); |
|
99 | 99 | |
100 | - if ( $violationMessage !== null ) { |
|
100 | + if ($violationMessage !== null) { |
|
101 | 101 | $serialization[self::KEY_VIOLATION_MESSAGE] = |
102 | - $this->violationMessageSerializer->serialize( $violationMessage ); |
|
102 | + $this->violationMessageSerializer->serialize($violationMessage); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - if ( $this->serializeDependencyMetadata ) { |
|
106 | + if ($this->serializeDependencyMetadata) { |
|
107 | 107 | $serialization[self::KEY_DEPENDENCY_METADATA] = |
108 | - $this->serializeDependencyMetadata( $checkResult ); |
|
108 | + $this->serializeDependencyMetadata($checkResult); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | return $serialization; |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | * @param CachingMetadata $cachingMetadata |
116 | 116 | * @return array |
117 | 117 | */ |
118 | - private function serializeCachingMetadata( CachingMetadata $cachingMetadata ) { |
|
118 | + private function serializeCachingMetadata(CachingMetadata $cachingMetadata) { |
|
119 | 119 | $maximumAge = $cachingMetadata->getMaximumAgeInSeconds(); |
120 | 120 | |
121 | 121 | $serialization = []; |
122 | 122 | |
123 | - if ( $maximumAge > 0 ) { |
|
123 | + if ($maximumAge > 0) { |
|
124 | 124 | $serialization[self::KEY_CACHING_METADATA_MAX_AGE] = $maximumAge; |
125 | 125 | } |
126 | 126 | |
@@ -131,21 +131,21 @@ discard block |
||
131 | 131 | * @param CheckResult $checkResult |
132 | 132 | * @return array |
133 | 133 | */ |
134 | - private function serializeDependencyMetadata( CheckResult $checkResult ) { |
|
134 | + private function serializeDependencyMetadata(CheckResult $checkResult) { |
|
135 | 135 | $dependencyMetadata = $checkResult->getMetadata()->getDependencyMetadata(); |
136 | 136 | $entityIds = $dependencyMetadata->getEntityIds(); |
137 | 137 | $futureTime = $dependencyMetadata->getFutureTime(); |
138 | 138 | |
139 | 139 | $serialization = [ |
140 | 140 | self::KEY_DEPENDENCY_METADATA_ENTITY_IDS => array_map( |
141 | - static function ( EntityId $entityId ) { |
|
141 | + static function(EntityId $entityId) { |
|
142 | 142 | return $entityId->getSerialization(); |
143 | 143 | }, |
144 | 144 | $entityIds |
145 | 145 | ), |
146 | 146 | ]; |
147 | 147 | |
148 | - if ( $futureTime !== null ) { |
|
148 | + if ($futureTime !== null) { |
|
149 | 149 | $serialization[self::KEY_DEPENDENCY_METADATA_FUTURE_TIME] = |
150 | 150 | $futureTime->getArrayValue(); |
151 | 151 | } |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
76 | 76 | * @return CheckResult |
77 | 77 | */ |
78 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
79 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
80 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
78 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
79 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
80 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
81 | 81 | } |
82 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
83 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE ); |
|
82 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
83 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $parameters = []; |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | $constraintTypeItemId |
93 | 93 | ); |
94 | 94 | $parameters['class'] = array_map( |
95 | - static function ( $id ) { |
|
96 | - return new ItemId( $id ); |
|
95 | + static function($id) { |
|
96 | + return new ItemId($id); |
|
97 | 97 | }, |
98 | 98 | $classes |
99 | 99 | ); |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | $constraintTypeItemId |
104 | 104 | ); |
105 | 105 | $relationIds = []; |
106 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
107 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
106 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
107 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
108 | 108 | } |
109 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
110 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
109 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
110 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
111 | 111 | } |
112 | - $parameters['relation'] = [ $relation ]; |
|
112 | + $parameters['relation'] = [$relation]; |
|
113 | 113 | |
114 | 114 | $result = $this->typeCheckerHelper->hasClassInRelation( |
115 | 115 | $context->getEntity()->getStatements(), |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $classes |
118 | 118 | ); |
119 | 119 | |
120 | - if ( $result->getBool() ) { |
|
120 | + if ($result->getBool()) { |
|
121 | 121 | $message = null; |
122 | 122 | $status = CheckResult::STATUS_COMPLIANCE; |
123 | 123 | } else { |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | $status = CheckResult::STATUS_VIOLATION; |
132 | 132 | } |
133 | 133 | |
134 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
135 | - ->withMetadata( $result->getMetadata() ); |
|
134 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
135 | + ->withMetadata($result->getMetadata()); |
|
136 | 136 | } |
137 | 137 | |
138 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
138 | + public function checkConstraintParameters(Constraint $constraint) { |
|
139 | 139 | $constraintParameters = $constraint->getConstraintParameters(); |
140 | 140 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
141 | 141 | $exceptions = []; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $constraintParameters, |
145 | 145 | $constraintTypeItemId |
146 | 146 | ); |
147 | - } catch ( ConstraintParameterException $e ) { |
|
147 | + } catch (ConstraintParameterException $e) { |
|
148 | 148 | $exceptions[] = $e; |
149 | 149 | } |
150 | 150 | try { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $constraintParameters, |
153 | 153 | $constraintTypeItemId |
154 | 154 | ); |
155 | - } catch ( ConstraintParameterException $e ) { |
|
155 | + } catch (ConstraintParameterException $e) { |
|
156 | 156 | $exceptions[] = $e; |
157 | 157 | } |
158 | 158 | return $exceptions; |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
92 | 92 | * @return CheckResult |
93 | 93 | */ |
94 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
95 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
96 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
94 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
95 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
96 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | $parameters = []; |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | $constraintTypeItemId |
106 | 106 | ); |
107 | 107 | $parameters['class'] = array_map( |
108 | - static function ( $id ) { |
|
109 | - return new ItemId( $id ); |
|
108 | + static function($id) { |
|
109 | + return new ItemId($id); |
|
110 | 110 | }, |
111 | 111 | $classes |
112 | 112 | ); |
@@ -116,19 +116,19 @@ discard block |
||
116 | 116 | $constraintTypeItemId |
117 | 117 | ); |
118 | 118 | $relationIds = []; |
119 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
120 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
119 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
120 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
121 | 121 | } |
122 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
123 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
122 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
123 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
124 | 124 | } |
125 | - $parameters['relation'] = [ $relation ]; |
|
125 | + $parameters['relation'] = [$relation]; |
|
126 | 126 | |
127 | 127 | $snak = $context->getSnak(); |
128 | 128 | |
129 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
129 | + if (!$snak instanceof PropertyValueSnak) { |
|
130 | 130 | // nothing to check |
131 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
131 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | $dataValue = $snak->getDataValue(); |
@@ -137,23 +137,23 @@ discard block |
||
137 | 137 | * error handling: |
138 | 138 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
139 | 139 | */ |
140 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
141 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
142 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
143 | - ->withDataValueType( 'wikibase-entityid' ); |
|
144 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
140 | + if (!$dataValue instanceof EntityIdValue) { |
|
141 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
142 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
143 | + ->withDataValueType('wikibase-entityid'); |
|
144 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | try { |
148 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
149 | - } catch ( UnresolvedEntityRedirectException $e ) { |
|
148 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
149 | + } catch (UnresolvedEntityRedirectException $e) { |
|
150 | 150 | // Edge case (double redirect): Pretend the entity doesn't exist |
151 | 151 | $item = null; |
152 | 152 | } |
153 | 153 | |
154 | - if ( !( $item instanceof StatementListProvidingEntity ) ) { |
|
155 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
156 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
154 | + if (!($item instanceof StatementListProvidingEntity)) { |
|
155 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
156 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | $statements = $item->getStatements(); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $classes |
165 | 165 | ); |
166 | 166 | |
167 | - if ( $result->getBool() ) { |
|
167 | + if ($result->getBool()) { |
|
168 | 168 | $message = null; |
169 | 169 | $status = CheckResult::STATUS_COMPLIANCE; |
170 | 170 | } else { |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | $status = CheckResult::STATUS_VIOLATION; |
179 | 179 | } |
180 | 180 | |
181 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
182 | - ->withMetadata( $result->getMetadata() ); |
|
181 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
182 | + ->withMetadata($result->getMetadata()); |
|
183 | 183 | } |
184 | 184 | |
185 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
185 | + public function checkConstraintParameters(Constraint $constraint) { |
|
186 | 186 | $constraintParameters = $constraint->getConstraintParameters(); |
187 | 187 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
188 | 188 | $exceptions = []; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $constraintParameters, |
192 | 192 | $constraintTypeItemId |
193 | 193 | ); |
194 | - } catch ( ConstraintParameterException $e ) { |
|
194 | + } catch (ConstraintParameterException $e) { |
|
195 | 195 | $exceptions[] = $e; |
196 | 196 | } |
197 | 197 | try { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $constraintParameters, |
200 | 200 | $constraintTypeItemId |
201 | 201 | ); |
202 | - } catch ( ConstraintParameterException $e ) { |
|
202 | + } catch (ConstraintParameterException $e) { |
|
203 | 203 | $exceptions[] = $e; |
204 | 204 | } |
205 | 205 | return $exceptions; |
@@ -8,20 +8,20 @@ |
||
8 | 8 | use Wikibase\Repo\WikibaseRepo; |
9 | 9 | |
10 | 10 | return [ |
11 | - WikibaseServices::ENTITY_LOOKUP => static function ( MediaWikiServices $services ) { |
|
11 | + WikibaseServices::ENTITY_LOOKUP => static function(MediaWikiServices $services) { |
|
12 | 12 | return new ExceptionIgnoringEntityLookup( |
13 | - WikibaseRepo::getEntityLookup( $services ) |
|
13 | + WikibaseRepo::getEntityLookup($services) |
|
14 | 14 | ); |
15 | 15 | }, |
16 | 16 | |
17 | - WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function ( MediaWikiServices $services ) { |
|
17 | + WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function(MediaWikiServices $services) { |
|
18 | 18 | return new ExceptionIgnoringEntityLookup( |
19 | - WikibaseRepo::getStore( $services ) |
|
20 | - ->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY ) |
|
19 | + WikibaseRepo::getStore($services) |
|
20 | + ->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY) |
|
21 | 21 | ); |
22 | 22 | }, |
23 | 23 | |
24 | - WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function ( MediaWikiServices $services ) { |
|
25 | - return WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
24 | + WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function(MediaWikiServices $services) { |
|
25 | + return WikibaseRepo::getPropertyDataTypeLookup($services); |
|
26 | 26 | }, |
27 | 27 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker; |
6 | 6 | |
@@ -77,26 +77,26 @@ discard block |
||
77 | 77 | * @return array first element is the namespace number (default namespace for TitleParser), |
78 | 78 | * second element is a string to prepend to the title before giving it to the TitleParser |
79 | 79 | */ |
80 | - private function getCommonsNamespace( string $namespace ): array { |
|
81 | - switch ( $namespace ) { |
|
80 | + private function getCommonsNamespace(string $namespace): array { |
|
81 | + switch ($namespace) { |
|
82 | 82 | case '': |
83 | - return [ NS_MAIN, '' ]; |
|
83 | + return [NS_MAIN, '']; |
|
84 | 84 | // extra namespaces, see operations/mediawiki-config.git, |
85 | 85 | // wmf-config/InitialiseSettings.php, 'wgExtraNamespaces' key, 'commonswiki' subkey |
86 | 86 | case 'Creator': |
87 | - return [ 100, '' ]; |
|
87 | + return [100, '']; |
|
88 | 88 | case 'TimedText': |
89 | - return [ 102, '' ]; |
|
89 | + return [102, '']; |
|
90 | 90 | case 'Sequence': |
91 | - return [ 104, '' ]; |
|
91 | + return [104, '']; |
|
92 | 92 | case 'Institution': |
93 | - return [ 106, '' ]; |
|
93 | + return [106, '']; |
|
94 | 94 | // extension namespace, see mediawiki/extensions/JsonConfig.git, |
95 | 95 | // extension.json, 'namespaces' key, third element |
96 | 96 | case 'Data': |
97 | - return [ 486, '' ]; |
|
97 | + return [486, '']; |
|
98 | 98 | default: |
99 | - return [ NS_MAIN, $namespace . ':' ]; |
|
99 | + return [NS_MAIN, $namespace.':']; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @throws ConstraintParameterException |
107 | 107 | */ |
108 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
108 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
109 | 109 | $parameters = []; |
110 | 110 | $constraintParameters = $constraint->getConstraintParameters(); |
111 | 111 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | $constraintParameters, |
115 | 115 | $constraintTypeItemId |
116 | 116 | ); |
117 | - $parameters['namespace'] = [ $namespace ]; |
|
117 | + $parameters['namespace'] = [$namespace]; |
|
118 | 118 | |
119 | 119 | $snak = $context->getSnak(); |
120 | 120 | |
121 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
121 | + if (!$snak instanceof PropertyValueSnak) { |
|
122 | 122 | // nothing to check |
123 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
123 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | $dataValue = $snak->getDataValue(); |
@@ -130,52 +130,52 @@ discard block |
||
130 | 130 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
131 | 131 | * parameter $namespace can be null, works for commons galleries |
132 | 132 | */ |
133 | - if ( $dataValue->getType() !== 'string' ) { |
|
134 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
135 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
136 | - ->withDataValueType( 'string' ); |
|
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
133 | + if ($dataValue->getType() !== 'string') { |
|
134 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
135 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
136 | + ->withDataValueType('string'); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $commonsLink = $dataValue->getValue(); |
141 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
141 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
144 | 144 | } |
145 | 145 | |
146 | - $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty( $snak->getPropertyId() ); |
|
147 | - switch ( $dataType ) { |
|
146 | + $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty($snak->getPropertyId()); |
|
147 | + switch ($dataType) { |
|
148 | 148 | case 'geo-shape': |
149 | 149 | case 'tabular-data': |
150 | - if ( strpos( $commonsLink, $namespace . ':' ) !== 0 ) { |
|
151 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
150 | + if (strpos($commonsLink, $namespace.':') !== 0) { |
|
151 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
153 | 153 | } |
154 | 154 | $pageName = $commonsLink; |
155 | 155 | break; |
156 | 156 | default: |
157 | - $pageName = $namespace ? $namespace . ':' . $commonsLink : $commonsLink; |
|
157 | + $pageName = $namespace ? $namespace.':'.$commonsLink : $commonsLink; |
|
158 | 158 | break; |
159 | 159 | } |
160 | 160 | |
161 | - $prefix = $this->getCommonsNamespace( $namespace )[1]; |
|
161 | + $prefix = $this->getCommonsNamespace($namespace)[1]; |
|
162 | 162 | $normalizedTitle = $this->pageNameNormalizer->normalizePageName( |
163 | 163 | $pageName, |
164 | 164 | 'https://commons.wikimedia.org/w/api.php' |
165 | 165 | ); |
166 | - if ( $normalizedTitle === false ) { |
|
167 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
168 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
166 | + if ($normalizedTitle === false) { |
|
167 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
168 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
170 | 170 | } |
171 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | - new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ) ); |
|
171 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | + new ViolationMessage('wbqc-violation-message-commons-link-no-existent')); |
|
173 | 173 | } |
174 | 174 | |
175 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null ); |
|
175 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null); |
|
176 | 176 | } |
177 | 177 | |
178 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
178 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
179 | 179 | $constraintParameters = $constraint->getConstraintParameters(); |
180 | 180 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
181 | 181 | $exceptions = []; |
@@ -184,15 +184,15 @@ discard block |
||
184 | 184 | $constraintParameters, |
185 | 185 | $constraintTypeItemId |
186 | 186 | ); |
187 | - } catch ( ConstraintParameterException $e ) { |
|
187 | + } catch (ConstraintParameterException $e) { |
|
188 | 188 | $exceptions[] = $e; |
189 | 189 | } |
190 | 190 | return $exceptions; |
191 | 191 | } |
192 | 192 | |
193 | - private function commonsLinkIsWellFormed( string $commonsLink ): bool { |
|
194 | - $toReplace = [ "_", "%20" ]; |
|
195 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
193 | + private function commonsLinkIsWellFormed(string $commonsLink): bool { |
|
194 | + $toReplace = ["_", "%20"]; |
|
195 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
196 | 196 | |
197 | 197 | return $commonsLink === $compareString; |
198 | 198 | } |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * Checks whether the value of the statement already includes the namespace. |
202 | 202 | * This special case should be reported as “malformed title” instead of “title does not exist”. |
203 | 203 | */ |
204 | - private function valueIncludesNamespace( string $value, string $namespace ): bool { |
|
204 | + private function valueIncludesNamespace(string $value, string $namespace): bool { |
|
205 | 205 | return $namespace !== '' && |
206 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
206 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @throws ConstraintParameterException |
98 | 98 | * @return CheckResult |
99 | 99 | */ |
100 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
100 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
101 | 101 | $parameters = []; |
102 | 102 | $constraintParameters = $constraint->getConstraintParameters(); |
103 | 103 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $constraintParameters, |
107 | 107 | $constraintTypeItemId |
108 | 108 | ); |
109 | - $parameters['pattern'] = [ $format ]; |
|
109 | + $parameters['pattern'] = [$format]; |
|
110 | 110 | |
111 | 111 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
112 | 112 | $constraintParameters |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | |
115 | 115 | $snak = $context->getSnak(); |
116 | 116 | |
117 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
117 | + if (!$snak instanceof PropertyValueSnak) { |
|
118 | 118 | // nothing to check |
119 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
119 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $dataValue = $snak->getDataValue(); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * error handling: |
126 | 126 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
127 | 127 | */ |
128 | - switch ( $dataValue->getType() ) { |
|
128 | + switch ($dataValue->getType()) { |
|
129 | 129 | case 'string': |
130 | 130 | $text = $dataValue->getValue(); |
131 | 131 | break; |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | $text = $dataValue->getText(); |
136 | 136 | break; |
137 | 137 | default: |
138 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
139 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
140 | - ->withDataValueType( 'string' ) |
|
141 | - ->withDataValueType( 'monolingualtext' ); |
|
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
138 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
139 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
140 | + ->withDataValueType('string') |
|
141 | + ->withDataValueType('monolingualtext'); |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
143 | 143 | } |
144 | - $status = $this->runRegexCheck( $text, $format ); |
|
144 | + $status = $this->runRegexCheck($text, $format); |
|
145 | 145 | $message = $this->formatMessage( |
146 | 146 | $status, |
147 | 147 | $text, |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $syntaxClarifications, |
151 | 151 | $constraintTypeItemId |
152 | 152 | ); |
153 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
153 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | private function formatMessage( |
@@ -162,74 +162,74 @@ discard block |
||
162 | 162 | string $constraintTypeItemId |
163 | 163 | ): ?ViolationMessage { |
164 | 164 | $message = null; |
165 | - if ( $status === CheckResult::STATUS_VIOLATION ) { |
|
166 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
167 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
168 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
169 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
170 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
171 | - } elseif ( $status === CheckResult::STATUS_TODO ) { |
|
172 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
173 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ); |
|
165 | + if ($status === CheckResult::STATUS_VIOLATION) { |
|
166 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
167 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
168 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
169 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
170 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
171 | + } elseif ($status === CheckResult::STATUS_TODO) { |
|
172 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
173 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $message; |
177 | 177 | } |
178 | 178 | |
179 | - private function runRegexCheck( string $text, string $format ): string { |
|
180 | - if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
179 | + private function runRegexCheck(string $text, string $format): string { |
|
180 | + if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
181 | 181 | return CheckResult::STATUS_TODO; |
182 | 182 | } |
183 | 183 | if ( |
184 | - $this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom() |
|
184 | + $this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom() |
|
185 | 185 | ) { |
186 | - return $this->runRegexCheckUsingShellbox( $text, $format ); |
|
186 | + return $this->runRegexCheckUsingShellbox($text, $format); |
|
187 | 187 | } |
188 | 188 | |
189 | - return $this->runRegexCheckUsingSparql( $text, $format ); |
|
189 | + return $this->runRegexCheckUsingSparql($text, $format); |
|
190 | 190 | } |
191 | 191 | |
192 | - private function runRegexCheckUsingShellbox( string $text, string $format ): string { |
|
193 | - if ( !$this->shellboxClientFactory->isEnabled( 'constraint-regex-checker' ) ) { |
|
192 | + private function runRegexCheckUsingShellbox(string $text, string $format): string { |
|
193 | + if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) { |
|
194 | 194 | return CheckResult::STATUS_TODO; |
195 | 195 | } |
196 | 196 | try { |
197 | - $pattern = '/^(?:' . str_replace( '/', '\/', $format ) . ')$/u'; |
|
198 | - $shellboxResponse = $this->shellboxClientFactory->getClient( [ |
|
199 | - 'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000, |
|
197 | + $pattern = '/^(?:'.str_replace('/', '\/', $format).')$/u'; |
|
198 | + $shellboxResponse = $this->shellboxClientFactory->getClient([ |
|
199 | + 'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000, |
|
200 | 200 | 'service' => 'constraint-regex-checker', |
201 | - ] )->call( |
|
201 | + ])->call( |
|
202 | 202 | 'constraint-regex-checker', |
203 | 203 | 'preg_match', |
204 | - [ $pattern, $text ] |
|
204 | + [$pattern, $text] |
|
205 | 205 | ); |
206 | - } catch ( ShellboxError $exception ) { |
|
206 | + } catch (ShellboxError $exception) { |
|
207 | 207 | throw new ConstraintParameterException( |
208 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
209 | - ->withInlineCode( $pattern, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
208 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
209 | + ->withInlineCode($pattern, Role::CONSTRAINT_PARAMETER_VALUE) |
|
210 | 210 | ); |
211 | 211 | } |
212 | 212 | |
213 | - if ( $shellboxResponse ) { |
|
213 | + if ($shellboxResponse) { |
|
214 | 214 | return CheckResult::STATUS_COMPLIANCE; |
215 | 215 | } else { |
216 | 216 | return CheckResult::STATUS_VIOLATION; |
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - private function runRegexCheckUsingSparql( string $text, string $format ): string { |
|
221 | - if ( $this->sparqlHelper instanceof DummySparqlHelper ) { |
|
220 | + private function runRegexCheckUsingSparql(string $text, string $format): string { |
|
221 | + if ($this->sparqlHelper instanceof DummySparqlHelper) { |
|
222 | 222 | return CheckResult::STATUS_TODO; |
223 | 223 | } |
224 | 224 | |
225 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
225 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
226 | 226 | return CheckResult::STATUS_COMPLIANCE; |
227 | 227 | } else { |
228 | 228 | return CheckResult::STATUS_VIOLATION; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
232 | + public function checkConstraintParameters(Constraint $constraint) { |
|
233 | 233 | $constraintParameters = $constraint->getConstraintParameters(); |
234 | 234 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
235 | 235 | $exceptions = []; |
@@ -238,14 +238,14 @@ discard block |
||
238 | 238 | $constraintParameters, |
239 | 239 | $constraintTypeItemId |
240 | 240 | ); |
241 | - } catch ( ConstraintParameterException $e ) { |
|
241 | + } catch (ConstraintParameterException $e) { |
|
242 | 242 | $exceptions[] = $e; |
243 | 243 | } |
244 | 244 | try { |
245 | 245 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
246 | 246 | $constraintParameters |
247 | 247 | ); |
248 | - } catch ( ConstraintParameterException $e ) { |
|
248 | + } catch (ConstraintParameterException $e) { |
|
249 | 249 | $exceptions[] = $e; |
250 | 250 | } |
251 | 251 | return $exceptions; |