@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | use WikibaseQuality\ConstraintReport\Job\UpdateConstraintsTableJob; |
11 | 11 | |
12 | 12 | // @codeCoverageIgnoreStart |
13 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
14 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
13 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
14 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
15 | 15 | |
16 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
16 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
17 | 17 | // @codeCoverageIgnoreEnd |
18 | 18 | |
19 | 19 | /** |
@@ -42,56 +42,56 @@ discard block |
||
42 | 42 | |
43 | 43 | public function __construct() { |
44 | 44 | parent::__construct(); |
45 | - $this->newUpdateConstraintsTableJob = static function ( $propertyIdSerialization ) { |
|
45 | + $this->newUpdateConstraintsTableJob = static function($propertyIdSerialization) { |
|
46 | 46 | return UpdateConstraintsTableJob::newFromGlobalState( |
47 | 47 | Title::newMainPage(), |
48 | - [ 'propertyId' => $propertyIdSerialization ] |
|
48 | + ['propertyId' => $propertyIdSerialization] |
|
49 | 49 | ); |
50 | 50 | }; |
51 | 51 | |
52 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
53 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
54 | - $this->setBatchSize( 10 ); |
|
52 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
53 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
54 | + $this->setBatchSize(10); |
|
55 | 55 | |
56 | 56 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
57 | 57 | // that can be overridden in tests. |
58 | - $this->setupServices = function () { |
|
58 | + $this->setupServices = function() { |
|
59 | 59 | $services = MediaWikiServices::getInstance(); |
60 | - $this->propertyInfoLookup = WikibaseRepo::getStore( $services )->getPropertyInfoLookup(); |
|
60 | + $this->propertyInfoLookup = WikibaseRepo::getStore($services)->getPropertyInfoLookup(); |
|
61 | 61 | }; |
62 | 62 | } |
63 | 63 | |
64 | 64 | public function execute() { |
65 | - ( $this->setupServices )(); |
|
66 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
67 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
65 | + ($this->setupServices)(); |
|
66 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
67 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $propertyInfos = $this->propertyInfoLookup->getAllPropertyInfo(); |
72 | - $propertyIds = array_keys( $propertyInfos ); |
|
72 | + $propertyIds = array_keys($propertyInfos); |
|
73 | 73 | |
74 | - foreach ( array_chunk( $propertyIds, $this->getBatchSize() ) as $propertyIdsChunk ) { |
|
75 | - foreach ( $propertyIdsChunk as $propertyIdSerialization ) { |
|
76 | - $this->output( sprintf( |
|
74 | + foreach (array_chunk($propertyIds, $this->getBatchSize()) as $propertyIdsChunk) { |
|
75 | + foreach ($propertyIdsChunk as $propertyIdSerialization) { |
|
76 | + $this->output(sprintf( |
|
77 | 77 | 'Importing constraint statements for % 6s... ', |
78 | 78 | $propertyIdSerialization ), |
79 | 79 | $propertyIdSerialization |
80 | 80 | ); |
81 | - $startTime = microtime( true ); |
|
82 | - $job = ( $this->newUpdateConstraintsTableJob )( $propertyIdSerialization ); |
|
81 | + $startTime = microtime(true); |
|
82 | + $job = ($this->newUpdateConstraintsTableJob)($propertyIdSerialization); |
|
83 | 83 | $job->run(); |
84 | - $endTime = microtime( true ); |
|
85 | - $millis = ( $endTime - $startTime ) * 1000; |
|
86 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
84 | + $endTime = microtime(true); |
|
85 | + $millis = ($endTime - $startTime) * 1000; |
|
86 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
87 | 87 | } |
88 | 88 | |
89 | - $this->output( 'Waiting for replication... ', 'waitForReplication' ); |
|
90 | - $startTime = microtime( true ); |
|
89 | + $this->output('Waiting for replication... ', 'waitForReplication'); |
|
90 | + $startTime = microtime(true); |
|
91 | 91 | $this->waitForReplication(); |
92 | - $endTime = microtime( true ); |
|
93 | - $millis = ( $endTime - $startTime ) * 1000; |
|
94 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), 'waitForReplication' ); |
|
92 | + $endTime = microtime(true); |
|
93 | + $millis = ($endTime - $startTime) * 1000; |
|
94 | + $this->output(sprintf('done in % 6.2f ms.', $millis), 'waitForReplication'); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | ) { |
144 | 144 | $results = []; |
145 | 145 | $metadatas = []; |
146 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
146 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
147 | 147 | $storedEntityIds = []; |
148 | - foreach ( $entityIds as $entityId ) { |
|
149 | - $storedResults = $this->getStoredResults( $entityId ); |
|
150 | - if ( $storedResults !== null ) { |
|
151 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
152 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
153 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
148 | + foreach ($entityIds as $entityId) { |
|
149 | + $storedResults = $this->getStoredResults($entityId); |
|
150 | + if ($storedResults !== null) { |
|
151 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
152 | + foreach ($storedResults->getArray() as $checkResult) { |
|
153 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
154 | 154 | $results[] = $checkResult; |
155 | 155 | } |
156 | 156 | } |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | $storedEntityIds[] = $entityId; |
159 | 159 | } |
160 | 160 | } |
161 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
161 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
162 | 162 | } |
163 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
164 | - if ( $entityIds !== [] ) { |
|
165 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
163 | + if ($entityIds !== [] || $claimIds !== []) { |
|
164 | + if ($entityIds !== []) { |
|
165 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
166 | 166 | } |
167 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
168 | - $results = array_merge( $results, $response->getArray() ); |
|
167 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
168 | + $results = array_merge($results, $response->getArray()); |
|
169 | 169 | $metadatas[] = $response->getMetadata(); |
170 | 170 | } |
171 | 171 | return new CachedCheckResults( |
172 | 172 | $results, |
173 | - Metadata::merge( $metadatas ) |
|
173 | + Metadata::merge($metadatas) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | ?array $constraintIds, |
194 | 194 | array $statuses |
195 | 195 | ) { |
196 | - if ( $claimIds !== [] ) { |
|
196 | + if ($claimIds !== []) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | - if ( $constraintIds !== null ) { |
|
199 | + if ($constraintIds !== null) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
202 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
203 | 203 | return false; |
204 | 204 | } |
205 | 205 | return true; |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param CheckResult $result |
215 | 215 | * @return bool |
216 | 216 | */ |
217 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
218 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
217 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
218 | + return in_array($result->getStatus(), $statuses, true) || |
|
219 | 219 | $result instanceof NullResult; |
220 | 220 | } |
221 | 221 | |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | ?array $constraintIds, |
233 | 233 | array $statuses |
234 | 234 | ) { |
235 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
235 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
236 | 236 | |
237 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
238 | - foreach ( $entityIds as $entityId ) { |
|
239 | - $this->storeResults( $entityId, $results ); |
|
237 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
238 | + foreach ($entityIds as $entityId) { |
|
239 | + $this->storeResults($entityId, $results); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | ?array $constraintIds, |
268 | 268 | array $statuses |
269 | 269 | ) { |
270 | - if ( $constraintIds !== null ) { |
|
270 | + if ($constraintIds !== null) { |
|
271 | 271 | return false; |
272 | 272 | } |
273 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
273 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | return true; |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * May include check results for other entity IDs as well, |
285 | 285 | * or check results with statuses that we’re not interested in caching. |
286 | 286 | */ |
287 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
287 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
288 | 288 | $latestRevisionIds = $this->getLatestRevisionIds( |
289 | 289 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
290 | 290 | ); |
291 | - if ( $latestRevisionIds === null ) { |
|
291 | + if ($latestRevisionIds === null) { |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $resultSerializations = []; |
296 | - foreach ( $results->getArray() as $checkResult ) { |
|
297 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
296 | + foreach ($results->getArray() as $checkResult) { |
|
297 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
298 | 298 | continue; |
299 | 299 | } |
300 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
301 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
300 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
301 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | 'latestRevisionIds' => $latestRevisionIds, |
308 | 308 | ]; |
309 | 309 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
310 | - if ( $futureTime !== null ) { |
|
310 | + if ($futureTime !== null) { |
|
311 | 311 | $value['futureTime'] = $futureTime->getArrayValue(); |
312 | 312 | } |
313 | 313 | |
314 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
314 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -326,33 +326,32 @@ discard block |
||
326 | 326 | $forRevision = 0 |
327 | 327 | ) { |
328 | 328 | $cacheInfo = WANObjectCache::PASS_BY_REF; |
329 | - $value = $this->cache->get( $entityId, $curTTL, [], $cacheInfo ); |
|
330 | - $now = ( $this->microtime )( true ); |
|
329 | + $value = $this->cache->get($entityId, $curTTL, [], $cacheInfo); |
|
330 | + $now = ($this->microtime)(true); |
|
331 | 331 | |
332 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
333 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
334 | - if ( $dependencyMetadata === null ) { |
|
332 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
333 | + [$entityId->getSerialization() => $forRevision]); |
|
334 | + if ($dependencyMetadata === null) { |
|
335 | 335 | return null; |
336 | 336 | } |
337 | 337 | |
338 | 338 | // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive |
339 | 339 | $asOf = $cacheInfo[WANObjectCache::KEY_AS_OF]; |
340 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
340 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
341 | 341 | $cachingMetadata = $ageInSeconds > 0 ? |
342 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
343 | - CachingMetadata::fresh(); |
|
342 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
344 | 343 | |
345 | 344 | $results = []; |
346 | - foreach ( $value['results'] as $resultSerialization ) { |
|
347 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
345 | + foreach ($value['results'] as $resultSerialization) { |
|
346 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
348 | 347 | } |
349 | 348 | |
350 | 349 | return new CachedCheckResults( |
351 | 350 | $results, |
352 | - Metadata::merge( [ |
|
353 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
354 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
355 | - ] ) |
|
351 | + Metadata::merge([ |
|
352 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
353 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
354 | + ]) |
|
356 | 355 | ); |
357 | 356 | } |
358 | 357 | |
@@ -368,43 +367,43 @@ discard block |
||
368 | 367 | * @return DependencyMetadata|null the dependency metadata, |
369 | 368 | * or null if $value should no longer be used |
370 | 369 | */ |
371 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
372 | - if ( $value === false ) { |
|
370 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
371 | + if ($value === false) { |
|
373 | 372 | return null; |
374 | 373 | } |
375 | 374 | |
376 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
377 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
378 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
375 | + if (array_key_exists('futureTime', $value)) { |
|
376 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
377 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
379 | 378 | return null; |
380 | 379 | } |
381 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
380 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
382 | 381 | } else { |
383 | 382 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
384 | 383 | } |
385 | 384 | |
386 | - foreach ( $paramRevs as $id => $revision ) { |
|
387 | - if ( $revision > 0 ) { |
|
388 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
385 | + foreach ($paramRevs as $id => $revision) { |
|
386 | + if ($revision > 0) { |
|
387 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
389 | 388 | } |
390 | 389 | } |
391 | 390 | |
392 | 391 | $dependedEntityIds = array_map( |
393 | - [ $this->entityIdParser, "parse" ], |
|
394 | - array_keys( $value['latestRevisionIds'] ) |
|
392 | + [$this->entityIdParser, "parse"], |
|
393 | + array_keys($value['latestRevisionIds']) |
|
395 | 394 | ); |
396 | 395 | |
397 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
396 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
398 | 397 | return null; |
399 | 398 | } |
400 | 399 | |
401 | 400 | return array_reduce( |
402 | 401 | $dependedEntityIds, |
403 | - static function ( DependencyMetadata $metadata, EntityId $entityId ) { |
|
404 | - return DependencyMetadata::merge( [ |
|
402 | + static function(DependencyMetadata $metadata, EntityId $entityId) { |
|
403 | + return DependencyMetadata::merge([ |
|
405 | 404 | $metadata, |
406 | - DependencyMetadata::ofEntityId( $entityId ), |
|
407 | - ] ); |
|
405 | + DependencyMetadata::ofEntityId($entityId), |
|
406 | + ]); |
|
408 | 407 | }, |
409 | 408 | $futureTimeDependencyMetadata |
410 | 409 | ); |
@@ -424,13 +423,13 @@ discard block |
||
424 | 423 | array $resultSerialization, |
425 | 424 | CachingMetadata $cachingMetadata |
426 | 425 | ) { |
427 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
428 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
426 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
427 | + if ($this->isPossiblyStaleResult($result)) { |
|
429 | 428 | $result->withMetadata( |
430 | - Metadata::merge( [ |
|
429 | + Metadata::merge([ |
|
431 | 430 | $result->getMetadata(), |
432 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
433 | - ] ) |
|
431 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
432 | + ]) |
|
434 | 433 | ); |
435 | 434 | } |
436 | 435 | return $result; |
@@ -440,8 +439,8 @@ discard block |
||
440 | 439 | * @param CheckResult $result |
441 | 440 | * @return bool |
442 | 441 | */ |
443 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
444 | - if ( $result instanceof NullResult ) { |
|
442 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
443 | + if ($result instanceof NullResult) { |
|
445 | 444 | return false; |
446 | 445 | } |
447 | 446 | |
@@ -456,14 +455,14 @@ discard block |
||
456 | 455 | * @return int[]|null array from entity ID serializations to revision ID, |
457 | 456 | * or null to indicate that not all revision IDs could be loaded |
458 | 457 | */ |
459 | - private function getLatestRevisionIds( array $entityIds ) { |
|
460 | - if ( $entityIds === [] ) { |
|
458 | + private function getLatestRevisionIds(array $entityIds) { |
|
459 | + if ($entityIds === []) { |
|
461 | 460 | $this->loggingHelper->logEmptyDependencyMetadata(); |
462 | 461 | return []; |
463 | 462 | } |
464 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
463 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
465 | 464 | // one of those entities will probably be edited soon, so might as well skip caching |
466 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
465 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
467 | 466 | return null; |
468 | 467 | } |
469 | 468 | |
@@ -471,7 +470,7 @@ discard block |
||
471 | 470 | $entityIds, |
472 | 471 | LookupConstants::LATEST_FROM_REPLICA |
473 | 472 | ); |
474 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
473 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
475 | 474 | return null; |
476 | 475 | } |
477 | 476 | return $latestRevisionIds; |
@@ -481,8 +480,8 @@ discard block |
||
481 | 480 | * @param array $array |
482 | 481 | * @return bool |
483 | 482 | */ |
484 | - private function hasFalseElements( array $array ) { |
|
485 | - return in_array( false, $array, true ); |
|
483 | + private function hasFalseElements(array $array) { |
|
484 | + return in_array(false, $array, true); |
|
486 | 485 | } |
487 | 486 | |
488 | 487 | /** |
@@ -490,7 +489,7 @@ discard block |
||
490 | 489 | * |
491 | 490 | * @param callable $microtime |
492 | 491 | */ |
493 | - public function setMicrotimeFunction( callable $microtime ) { |
|
492 | + public function setMicrotimeFunction(callable $microtime) { |
|
494 | 493 | $this->microtime = $microtime; |
495 | 494 | } |
496 | 495 |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | EntityIdLookup $entityIdLookup, |
50 | 50 | RdfVocabulary $rdfVocabulary |
51 | 51 | ) { |
52 | - parent::__construct( $page, $context ); |
|
52 | + parent::__construct($page, $context); |
|
53 | 53 | $this->resultsSource = $resultsSource; |
54 | 54 | $this->entityIdLookup = $entityIdLookup; |
55 | 55 | $this->rdfVocabulary = $rdfVocabulary; |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @param string $guid |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - private function cleanupGuid( $guid ) { |
|
112 | - return preg_replace( '/[^\w-]/', '-', $guid ); |
|
111 | + private function cleanupGuid($guid) { |
|
112 | + return preg_replace('/[^\w-]/', '-', $guid); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -121,63 +121,63 @@ discard block |
||
121 | 121 | $response = $this->getRequest()->response(); |
122 | 122 | $this->getOutput()->disable(); |
123 | 123 | |
124 | - if ( !$this->resultsSource instanceof CachingResultsSource ) { |
|
124 | + if (!$this->resultsSource instanceof CachingResultsSource) { |
|
125 | 125 | // TODO: make configurable whether only cached results are returned |
126 | - $response->statusHeader( 501 ); // Not Implemented |
|
126 | + $response->statusHeader(501); // Not Implemented |
|
127 | 127 | return null; |
128 | 128 | } |
129 | 129 | |
130 | - $entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() ); |
|
131 | - if ( $entityId === null ) { |
|
132 | - $response->statusHeader( 404 ); // Not Found |
|
130 | + $entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle()); |
|
131 | + if ($entityId === null) { |
|
132 | + $response->statusHeader(404); // Not Found |
|
133 | 133 | return null; |
134 | 134 | } |
135 | - $revId = $this->getRequest()->getInt( 'revision' ); |
|
135 | + $revId = $this->getRequest()->getInt('revision'); |
|
136 | 136 | |
137 | - $results = $this->resultsSource->getStoredResults( $entityId, $revId ); |
|
138 | - if ( $results === null ) { |
|
139 | - $response->statusHeader( 204 ); // No Content |
|
137 | + $results = $this->resultsSource->getStoredResults($entityId, $revId); |
|
138 | + if ($results === null) { |
|
139 | + $response->statusHeader(204); // No Content |
|
140 | 140 | return null; |
141 | 141 | } |
142 | 142 | |
143 | 143 | $format = 'ttl'; // TODO: make format an option |
144 | 144 | |
145 | 145 | $writerFactory = new RdfWriterFactory(); |
146 | - $formatName = $writerFactory->getFormatName( $format ); |
|
147 | - $contentType = $writerFactory->getMimeTypes( $formatName )[0]; |
|
146 | + $formatName = $writerFactory->getFormatName($format); |
|
147 | + $contentType = $writerFactory->getMimeTypes($formatName)[0]; |
|
148 | 148 | |
149 | - $propertyRepo = $this->rdfVocabulary->getEntityRepositoryName( new NumericPropertyId( 'P1' ) ); |
|
149 | + $propertyRepo = $this->rdfVocabulary->getEntityRepositoryName(new NumericPropertyId('P1')); |
|
150 | 150 | $wds = $this->rdfVocabulary->statementNamespaceNames[$propertyRepo][RdfVocabulary::NS_STATEMENT]; |
151 | 151 | |
152 | - $writer = $writerFactory->getWriter( $formatName ); |
|
153 | - foreach ( [ $wds, RdfVocabulary::NS_ONTOLOGY ] as $ns ) { |
|
154 | - $writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) ); |
|
152 | + $writer = $writerFactory->getWriter($formatName); |
|
153 | + foreach ([$wds, RdfVocabulary::NS_ONTOLOGY] as $ns) { |
|
154 | + $writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns)); |
|
155 | 155 | } |
156 | 156 | $writer->start(); |
157 | 157 | $writtenAny = false; |
158 | 158 | |
159 | - foreach ( $results->getArray() as $checkResult ) { |
|
160 | - if ( $checkResult instanceof NullResult ) { |
|
159 | + foreach ($results->getArray() as $checkResult) { |
|
160 | + if ($checkResult instanceof NullResult) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | - if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) { |
|
163 | + if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) { |
|
164 | 164 | continue; |
165 | 165 | } |
166 | 166 | $writtenAny = true; |
167 | - $writer->about( $wds, |
|
168 | - $this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) ) |
|
169 | - ->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' ) |
|
170 | - ->is( $wds, |
|
171 | - $this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) ); |
|
167 | + $writer->about($wds, |
|
168 | + $this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid())) |
|
169 | + ->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint') |
|
170 | + ->is($wds, |
|
171 | + $this->cleanupGuid($checkResult->getConstraint()->getConstraintId())); |
|
172 | 172 | } |
173 | 173 | $writer->finish(); |
174 | - if ( $writtenAny ) { |
|
175 | - $response->header( "Content-Type: $contentType; charset=UTF-8" ); |
|
174 | + if ($writtenAny) { |
|
175 | + $response->header("Content-Type: $contentType; charset=UTF-8"); |
|
176 | 176 | echo $writer->drain(); |
177 | 177 | } else { |
178 | 178 | // Do not output RDF if we haven't written any actual statements. Output 204 instead |
179 | 179 | $writer->drain(); |
180 | - $response->statusHeader( 204 ); // No Content |
|
180 | + $response->statusHeader(204); // No Content |
|
181 | 181 | } |
182 | 182 | return null; |
183 | 183 | } |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | use Wikibase\Repo\WikibaseRepo; |
19 | 19 | |
20 | 20 | // @codeCoverageIgnoreStart |
21 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
22 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
21 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
22 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
23 | 23 | |
24 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
24 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
25 | 25 | // @codeCoverageIgnoreEnd |
26 | 26 | |
27 | 27 | /** |
@@ -60,20 +60,20 @@ discard block |
||
60 | 60 | parent::__construct(); |
61 | 61 | |
62 | 62 | $this->addDescription( |
63 | - 'Import entities needed for constraint checks ' . |
|
63 | + 'Import entities needed for constraint checks '. |
|
64 | 64 | 'from Wikidata into the local repository.' |
65 | 65 | ); |
66 | 66 | $this->addOption( |
67 | 67 | 'config-format', |
68 | - 'The format in which the resulting configuration will be omitted: ' . |
|
69 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
68 | + 'The format in which the resulting configuration will be omitted: '. |
|
69 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
70 | 70 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
71 | 71 | ); |
72 | 72 | $this->addOption( |
73 | 73 | 'dry-run', |
74 | 74 | 'Don’t actually import entities, just print which ones would be imported.' |
75 | 75 | ); |
76 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
76 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | */ |
82 | 82 | private function setupServices() { |
83 | 83 | $services = MediaWikiServices::getInstance(); |
84 | - $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer( $services ); |
|
85 | - $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer( $services ); |
|
86 | - $this->entityStore = WikibaseRepo::getEntityStore( $services ); |
|
84 | + $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer($services); |
|
85 | + $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer($services); |
|
86 | + $this->entityStore = WikibaseRepo::getEntityStore($services); |
|
87 | 87 | $this->httpRequestFactory = $services->getHttpRequestFactory(); |
88 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
89 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
88 | + if (!$this->getOption('dry-run', false)) { |
|
89 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -95,21 +95,21 @@ discard block |
||
95 | 95 | |
96 | 96 | $configUpdates = []; |
97 | 97 | |
98 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
99 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
100 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
98 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
99 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
100 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
101 | 101 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
102 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
102 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
103 | 103 | |
104 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
105 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
104 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
105 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
106 | 106 | $configUpdates[$key] = [ |
107 | 107 | 'wikidata' => $wikidataEntityId, |
108 | 108 | 'local' => $localEntityId, |
109 | 109 | ]; |
110 | 110 | } |
111 | 111 | |
112 | - $this->outputConfigUpdates( $configUpdates ); |
|
112 | + $this->outputConfigUpdates($configUpdates); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | * @param Config $wikiConfig |
118 | 118 | * @return string[] |
119 | 119 | */ |
120 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
120 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
121 | 121 | $wikidataEntityIds = []; |
122 | 122 | |
123 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
124 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
123 | + foreach ($extensionJsonConfig as $key => $value) { |
|
124 | + if (!preg_match('/Id$/', $key)) { |
|
125 | 125 | continue; |
126 | 126 | } |
127 | 127 | |
128 | 128 | $wikidataEntityId = $value['value']; |
129 | - $localEntityId = $wikiConfig->get( $key ); |
|
129 | + $localEntityId = $wikiConfig->get($key); |
|
130 | 130 | |
131 | - if ( $localEntityId === $wikidataEntityId ) { |
|
131 | + if ($localEntityId === $wikidataEntityId) { |
|
132 | 132 | $wikidataEntityIds[$key] = $wikidataEntityId; |
133 | 133 | } |
134 | 134 | } |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * @param string $wikidataEntityId |
141 | 141 | * @return string local entity ID |
142 | 142 | */ |
143 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
143 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
144 | 144 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
145 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
146 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
145 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
146 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | * @param string $wikidataEntitiesJson |
152 | 152 | * @return string local entity ID |
153 | 153 | */ |
154 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
154 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
155 | 155 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
156 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
157 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
156 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
157 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
158 | 158 | |
159 | - $wikidataEntity->setId( null ); |
|
159 | + $wikidataEntity->setId(null); |
|
160 | 160 | |
161 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
161 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
162 | 162 | $wikidataEntity->getStatements()->clear(); |
163 | 163 | } |
164 | 164 | |
165 | - if ( $wikidataEntity instanceof Item ) { |
|
166 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
165 | + if ($wikidataEntity instanceof Item) { |
|
166 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
167 | 167 | } |
168 | 168 | |
169 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
170 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
171 | - $this->output( $wikidataEntityJson . "\n" ); |
|
169 | + if ($this->getOption('dry-run', false)) { |
|
170 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
171 | + $this->output($wikidataEntityJson."\n"); |
|
172 | 172 | return "-$wikidataEntityId"; |
173 | 173 | } |
174 | 174 | |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | )->getEntity(); |
182 | 182 | |
183 | 183 | return $localEntity->getId()->getSerialization(); |
184 | - } catch ( StorageException $storageException ) { |
|
185 | - return $this->storageExceptionToEntityId( $storageException ); |
|
184 | + } catch (StorageException $storageException) { |
|
185 | + return $this->storageExceptionToEntityId($storageException); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - private function storageExceptionToEntityId( StorageException $storageException ): string { |
|
189 | + private function storageExceptionToEntityId(StorageException $storageException): string { |
|
190 | 190 | $message = $storageException->getMessage(); |
191 | 191 | // example messages: |
192 | 192 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -196,25 +196,25 @@ discard block |
||
196 | 196 | // * Property [[Property:P694|P694]] already has label "instance of" |
197 | 197 | // associated with language code en. |
198 | 198 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
199 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
199 | + if (preg_match($pattern, $message, $matches)) { |
|
200 | 200 | return $matches[1]; |
201 | 201 | } else { |
202 | 202 | throw $storageException; |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - private function outputConfigUpdates( array $configUpdates ) { |
|
207 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
208 | - switch ( $configFormat ) { |
|
206 | + private function outputConfigUpdates(array $configUpdates) { |
|
207 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
208 | + switch ($configFormat) { |
|
209 | 209 | case 'globals': |
210 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
210 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
211 | 211 | break; |
212 | 212 | case 'wgConf': |
213 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
213 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
214 | 214 | break; |
215 | 215 | default: |
216 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
217 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
216 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
217 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
218 | 218 | break; |
219 | 219 | } |
220 | 220 | } |
@@ -222,22 +222,22 @@ discard block |
||
222 | 222 | /** |
223 | 223 | * @param array[] $configUpdates |
224 | 224 | */ |
225 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
226 | - foreach ( $configUpdates as $key => $value ) { |
|
227 | - $localValueCode = var_export( $value['local'], true ); |
|
228 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
225 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
226 | + foreach ($configUpdates as $key => $value) { |
|
227 | + $localValueCode = var_export($value['local'], true); |
|
228 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
233 | 233 | * @param array[] $configUpdates |
234 | 234 | */ |
235 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
236 | - $wikiIdCode = var_export( WikiMap::getCurrentWikiId(), true ); |
|
237 | - foreach ( $configUpdates as $key => $value ) { |
|
238 | - $keyCode = var_export( "wg$key", true ); |
|
239 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
240 | - $localValueCode = var_export( $value['local'], true ); |
|
235 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
236 | + $wikiIdCode = var_export(WikiMap::getCurrentWikiId(), true); |
|
237 | + foreach ($configUpdates as $key => $value) { |
|
238 | + $keyCode = var_export("wg$key", true); |
|
239 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
240 | + $localValueCode = var_export($value['local'], true); |
|
241 | 241 | $block = <<< EOF |
242 | 242 | $keyCode => [ |
243 | 243 | 'default' => $wikidataValueCode, |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | |
247 | 247 | |
248 | 248 | EOF; |
249 | - $this->output( $block ); |
|
249 | + $this->output($block); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | private const BATCH_SIZE = 50; |
40 | 40 | |
41 | - public static function newFromGlobalState( Title $title, array $params ): self { |
|
42 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
41 | + public static function newFromGlobalState(Title $title, array $params): self { |
|
42 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | return new UpdateConstraintsTableJob( |
45 | 45 | $title, |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | $services->getMainConfig(), |
50 | 50 | ConstraintsServices::getConstraintStore(), |
51 | 51 | $services->getDBLoadBalancerFactory(), |
52 | - WikibaseRepo::getStore()->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
53 | - WikibaseRepo::getBaseDataModelSerializerFactory( $services ) |
|
52 | + WikibaseRepo::getStore()->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
53 | + WikibaseRepo::getBaseDataModelSerializerFactory($services) |
|
54 | 54 | ->newSnakSerializer(), |
55 | 55 | $services->getJobQueueGroup() |
56 | 56 | ); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | Serializer $snakSerializer, |
119 | 119 | JobQueueGroup $jobQueueGroup |
120 | 120 | ) { |
121 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
121 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
122 | 122 | |
123 | 123 | $this->propertyId = $propertyId; |
124 | 124 | $this->revisionId = $revisionId; |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | $this->jobQueueGroup = $jobQueueGroup; |
131 | 131 | } |
132 | 132 | |
133 | - public function extractParametersFromQualifiers( SnakList $qualifiers ): array { |
|
133 | + public function extractParametersFromQualifiers(SnakList $qualifiers): array { |
|
134 | 134 | $parameters = []; |
135 | - foreach ( $qualifiers as $qualifier ) { |
|
135 | + foreach ($qualifiers as $qualifier) { |
|
136 | 136 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
137 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
137 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
138 | 138 | $parameters[$qualifierId][] = $paramSerialization; |
139 | 139 | } |
140 | 140 | return $parameters; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
153 | 153 | $entityId = $dataValue->getEntityId(); |
154 | 154 | $constraintTypeQid = $entityId->getSerialization(); |
155 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
155 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
156 | 156 | return new Constraint( |
157 | 157 | $constraintId, |
158 | 158 | $propertyId, |
@@ -167,25 +167,25 @@ discard block |
||
167 | 167 | NumericPropertyId $propertyConstraintPropertyId |
168 | 168 | ) { |
169 | 169 | $constraintsStatements = $property->getStatements() |
170 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
171 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
170 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
171 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
172 | 172 | $constraints = []; |
173 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
173 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
174 | 174 | // @phan-suppress-next-line PhanTypeMismatchArgumentSuperType |
175 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
176 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
177 | - $constraintStore->insertBatch( $constraints ); |
|
175 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
176 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
177 | + $constraintStore->insertBatch($constraints); |
|
178 | 178 | // interrupt transaction and wait for replication |
179 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
180 | - $connection->endAtomic( __CLASS__ ); |
|
181 | - if ( !$connection->explicitTrxActive() ) { |
|
179 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
180 | + $connection->endAtomic(__CLASS__); |
|
181 | + if (!$connection->explicitTrxActive()) { |
|
182 | 182 | $this->lbFactory->waitForReplication(); |
183 | 183 | } |
184 | - $connection->startAtomic( __CLASS__ ); |
|
184 | + $connection->startAtomic(__CLASS__); |
|
185 | 185 | $constraints = []; |
186 | 186 | } |
187 | 187 | } |
188 | - $constraintStore->insertBatch( $constraints ); |
|
188 | + $constraintStore->insertBatch($constraints); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -196,24 +196,24 @@ discard block |
||
196 | 196 | public function run() { |
197 | 197 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
198 | 198 | |
199 | - $propertyId = new NumericPropertyId( $this->propertyId ); |
|
199 | + $propertyId = new NumericPropertyId($this->propertyId); |
|
200 | 200 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
201 | 201 | $propertyId, |
202 | 202 | 0, // latest |
203 | 203 | LookupConstants::LATEST_FROM_REPLICA |
204 | 204 | ); |
205 | 205 | |
206 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
207 | - $this->jobQueueGroup->push( $this ); |
|
206 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
207 | + $this->jobQueueGroup->push($this); |
|
208 | 208 | return true; |
209 | 209 | } |
210 | 210 | |
211 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
211 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
212 | 212 | // start transaction (if not started yet) – using __CLASS__, not __METHOD__, |
213 | 213 | // because importConstraintsForProperty() can interrupt the transaction |
214 | - $connection->startAtomic( __CLASS__ ); |
|
214 | + $connection->startAtomic(__CLASS__); |
|
215 | 215 | |
216 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
216 | + $this->constraintStore->deleteForProperty($propertyId); |
|
217 | 217 | |
218 | 218 | /** @var Property $property */ |
219 | 219 | $property = $propertyRevision->getEntity(); |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | $this->importConstraintsForProperty( |
222 | 222 | $property, |
223 | 223 | $this->constraintStore, |
224 | - new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
224 | + new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
225 | 225 | ); |
226 | 226 | |
227 | - $connection->endAtomic( __CLASS__ ); |
|
227 | + $connection->endAtomic(__CLASS__); |
|
228 | 228 | |
229 | 229 | return true; |
230 | 230 | } |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class ContextCursorDeserializer { |
13 | 13 | |
14 | - public function deserialize( array $serialization ): ContextCursor { |
|
15 | - switch ( $serialization['t'] ) { |
|
14 | + public function deserialize(array $serialization): ContextCursor { |
|
15 | + switch ($serialization['t']) { |
|
16 | 16 | case Context::TYPE_STATEMENT: |
17 | 17 | return new MainSnakContextCursor( |
18 | 18 | $serialization['i'], |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | ); |
44 | 44 | default: |
45 | 45 | throw new InvalidArgumentException( |
46 | - 'Unknown serialization type ' . $serialization['t'] |
|
46 | + 'Unknown serialization type '.$serialization['t'] |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | } |
@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | $this->dataValueFactory = $dataValueFactory; |
40 | 40 | } |
41 | 41 | |
42 | - public function unabbreviateViolationMessageKey( string $messageKeySuffix ): string { |
|
43 | - return ViolationMessage::MESSAGE_KEY_PREFIX . $messageKeySuffix; |
|
42 | + public function unabbreviateViolationMessageKey(string $messageKeySuffix): string { |
|
43 | + return ViolationMessage::MESSAGE_KEY_PREFIX.$messageKeySuffix; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param array $serialization |
48 | 48 | * @return ViolationMessage |
49 | 49 | */ |
50 | - public function deserialize( $serialization ) { |
|
51 | - Assert::parameterType( 'array', $serialization, '$serialization' ); |
|
50 | + public function deserialize($serialization) { |
|
51 | + Assert::parameterType('array', $serialization, '$serialization'); |
|
52 | 52 | |
53 | 53 | $message = new ViolationMessage( |
54 | - $this->unabbreviateViolationMessageKey( $serialization['k'] ) |
|
54 | + $this->unabbreviateViolationMessageKey($serialization['k']) |
|
55 | 55 | ); |
56 | 56 | |
57 | - foreach ( $serialization['a'] as $serializedArgument ) { |
|
58 | - $message = $this->deserializeArgument( $message, $serializedArgument ); |
|
57 | + foreach ($serialization['a'] as $serializedArgument) { |
|
58 | + $message = $this->deserializeArgument($message, $serializedArgument); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return $message; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param array $serializedArgument [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
67 | 67 | * @return ViolationMessage $message with the deserialized argument appended |
68 | 68 | */ |
69 | - private function deserializeArgument( ViolationMessage $message, array $serializedArgument ) { |
|
69 | + private function deserializeArgument(ViolationMessage $message, array $serializedArgument) { |
|
70 | 70 | $methods = [ |
71 | 71 | ViolationMessage::TYPE_ENTITY_ID => 'deserializeEntityId', |
72 | 72 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'deserializeEntityIdList', |
@@ -88,23 +88,23 @@ discard block |
||
88 | 88 | $serializedValue = $serializedArgument['v']; |
89 | 89 | $role = $serializedArgument['r']; |
90 | 90 | |
91 | - if ( array_key_exists( $type, $methods ) ) { |
|
91 | + if (array_key_exists($type, $methods)) { |
|
92 | 92 | $method = $methods[$type]; |
93 | - $value = $this->$method( $serializedValue ); |
|
93 | + $value = $this->$method($serializedValue); |
|
94 | 94 | } else { |
95 | 95 | throw new InvalidArgumentException( |
96 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
96 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
97 | 97 | ); |
98 | 98 | } |
99 | 99 | |
100 | - return $message->withArgument( $type, $role, $value ); |
|
100 | + return $message->withArgument($type, $role, $value); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * @param string $string any value that shall simply be deserialized into itself |
105 | 105 | * @return string that same value, unchanged |
106 | 106 | */ |
107 | - private function deserializeStringByIdentity( $string ) { |
|
107 | + private function deserializeStringByIdentity($string) { |
|
108 | 108 | return $string; |
109 | 109 | } |
110 | 110 | |
@@ -112,32 +112,32 @@ discard block |
||
112 | 112 | * @param string $entityIdSerialization entity ID serialization |
113 | 113 | * @return EntityId |
114 | 114 | */ |
115 | - private function deserializeEntityId( $entityIdSerialization ) { |
|
116 | - return $this->entityIdParser->parse( $entityIdSerialization ); |
|
115 | + private function deserializeEntityId($entityIdSerialization) { |
|
116 | + return $this->entityIdParser->parse($entityIdSerialization); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * @param string[] $entityIdSerializations entity ID serializations |
121 | 121 | * @return EntityId[] |
122 | 122 | */ |
123 | - private function deserializeEntityIdList( array $entityIdSerializations ) { |
|
124 | - return array_map( [ $this, 'deserializeEntityId' ], $entityIdSerializations ); |
|
123 | + private function deserializeEntityIdList(array $entityIdSerializations) { |
|
124 | + return array_map([$this, 'deserializeEntityId'], $entityIdSerializations); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * @param string $valueSerialization entity ID serialization, '::somevalue' or '::novalue' |
129 | 129 | * @return ItemIdSnakValue |
130 | 130 | */ |
131 | - private function deserializeItemIdSnakValue( $valueSerialization ) { |
|
132 | - switch ( $valueSerialization ) { |
|
131 | + private function deserializeItemIdSnakValue($valueSerialization) { |
|
132 | + switch ($valueSerialization) { |
|
133 | 133 | case '::somevalue': |
134 | 134 | return ItemIdSnakValue::someValue(); |
135 | 135 | case '::novalue': |
136 | 136 | return ItemIdSnakValue::noValue(); |
137 | 137 | default: |
138 | - $itemId = $this->deserializeEntityId( $valueSerialization ); |
|
138 | + $itemId = $this->deserializeEntityId($valueSerialization); |
|
139 | 139 | '@phan-var \Wikibase\DataModel\Entity\ItemId $itemId'; |
140 | - return ItemIdSnakValue::fromItemId( $itemId ); |
|
140 | + return ItemIdSnakValue::fromItemId($itemId); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
@@ -145,24 +145,24 @@ discard block |
||
145 | 145 | * @param string[] $valueSerializations entity ID serializations, '::somevalue's or '::novalue's |
146 | 146 | * @return ItemIdSnakValue[] |
147 | 147 | */ |
148 | - private function deserializeItemIdSnakValueList( $valueSerializations ) { |
|
149 | - return array_map( [ $this, 'deserializeItemIdSnakValue' ], $valueSerializations ); |
|
148 | + private function deserializeItemIdSnakValueList($valueSerializations) { |
|
149 | + return array_map([$this, 'deserializeItemIdSnakValue'], $valueSerializations); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
153 | 153 | * @param array $dataValueSerialization the data value in array form |
154 | 154 | * @return DataValue |
155 | 155 | */ |
156 | - private function deserializeDataValue( array $dataValueSerialization ) { |
|
157 | - return $this->dataValueFactory->newFromArray( $dataValueSerialization ); |
|
156 | + private function deserializeDataValue(array $dataValueSerialization) { |
|
157 | + return $this->dataValueFactory->newFromArray($dataValueSerialization); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
161 | 161 | * @param string $contextTypeAbbreviation |
162 | 162 | * @return string one of the Context::TYPE_* constants |
163 | 163 | */ |
164 | - private function deserializeContextType( $contextTypeAbbreviation ) { |
|
165 | - switch ( $contextTypeAbbreviation ) { |
|
164 | + private function deserializeContextType($contextTypeAbbreviation) { |
|
165 | + switch ($contextTypeAbbreviation) { |
|
166 | 166 | case 's': |
167 | 167 | return Context::TYPE_STATEMENT; |
168 | 168 | case 'q': |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | default: |
173 | 173 | // @codeCoverageIgnoreStart |
174 | 174 | throw new LogicException( |
175 | - 'Unknown context type abbreviation ' . $contextTypeAbbreviation |
|
175 | + 'Unknown context type abbreviation '.$contextTypeAbbreviation |
|
176 | 176 | ); |
177 | 177 | // @codeCoverageIgnoreEnd |
178 | 178 | } |
@@ -182,16 +182,16 @@ discard block |
||
182 | 182 | * @param string[] $contextTypeAbbreviations |
183 | 183 | * @return string[] Context::TYPE_* constants |
184 | 184 | */ |
185 | - private function deserializeContextTypeList( array $contextTypeAbbreviations ) { |
|
186 | - return array_map( [ $this, 'deserializeContextType' ], $contextTypeAbbreviations ); |
|
185 | + private function deserializeContextTypeList(array $contextTypeAbbreviations) { |
|
186 | + return array_map([$this, 'deserializeContextType'], $contextTypeAbbreviations); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
190 | 190 | * @param mixed $textSerialization {@see MultilingualTextValue::getArrayValue} |
191 | 191 | * @return MultilingualTextValue |
192 | 192 | */ |
193 | - private function deserializeMultilingualText( $textSerialization ) { |
|
194 | - return MultilingualTextValue::newFromArray( $textSerialization ); |
|
193 | + private function deserializeMultilingualText($textSerialization) { |
|
194 | + return MultilingualTextValue::newFromArray($textSerialization); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $this->config = $config; |
54 | 54 | $this->timeParser = new IsoTimestampParser(); |
55 | 55 | $this->timeCalculator = new TimeValueCalculator(); |
56 | - $this->timeValueComparer = new TimeValueComparer( $this->timeCalculator ); |
|
56 | + $this->timeValueComparer = new TimeValueComparer($this->timeCalculator); |
|
57 | 57 | $this->unitConverter = $unitConverter; |
58 | 58 | } |
59 | 59 | |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @param UnboundedQuantityValue $value |
62 | 62 | * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value. |
63 | 63 | */ |
64 | - private function standardize( UnboundedQuantityValue $value ) { |
|
65 | - if ( $this->unitConverter !== null ) { |
|
66 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
67 | - if ( $standard !== null ) { |
|
64 | + private function standardize(UnboundedQuantityValue $value) { |
|
65 | + if ($this->unitConverter !== null) { |
|
66 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
67 | + if ($standard !== null) { |
|
68 | 68 | return $standard; |
69 | 69 | } else { |
70 | 70 | return $value; |
@@ -86,33 +86,33 @@ discard block |
||
86 | 86 | * when $lhs is respectively less than, equal to, or greater than $rhs. |
87 | 87 | * (In other words, just like the “spaceship” operator <=>.) |
88 | 88 | */ |
89 | - public function getComparison( ?DataValue $lhs, ?DataValue $rhs ) { |
|
90 | - if ( $lhs === null || $rhs === null ) { |
|
89 | + public function getComparison(?DataValue $lhs, ?DataValue $rhs) { |
|
90 | + if ($lhs === null || $rhs === null) { |
|
91 | 91 | return 0; |
92 | 92 | } |
93 | 93 | |
94 | - if ( $lhs->getType() !== $rhs->getType() ) { |
|
95 | - throw new InvalidArgumentException( 'Different data value types' ); |
|
94 | + if ($lhs->getType() !== $rhs->getType()) { |
|
95 | + throw new InvalidArgumentException('Different data value types'); |
|
96 | 96 | } |
97 | 97 | |
98 | - switch ( $lhs->getType() ) { |
|
98 | + switch ($lhs->getType()) { |
|
99 | 99 | case 'time': |
100 | 100 | /** @var TimeValue $lhs */ |
101 | 101 | /** @var TimeValue $rhs */ |
102 | 102 | '@phan-var TimeValue $lhs'; |
103 | 103 | '@phan-var TimeValue $rhs'; |
104 | - return $this->timeValueComparer->getComparison( $lhs, $rhs ); |
|
104 | + return $this->timeValueComparer->getComparison($lhs, $rhs); |
|
105 | 105 | case 'quantity': |
106 | 106 | /** @var QuantityValue|UnboundedQuantityValue $lhs */ |
107 | 107 | /** @var QuantityValue|UnboundedQuantityValue $rhs */ |
108 | 108 | '@phan-var QuantityValue|UnboundedQuantityValue $lhs'; |
109 | 109 | '@phan-var QuantityValue|UnboundedQuantityValue $rhs'; |
110 | - $lhsStandard = $this->standardize( $lhs ); |
|
111 | - $rhsStandard = $this->standardize( $rhs ); |
|
112 | - return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() ); |
|
110 | + $lhsStandard = $this->standardize($lhs); |
|
111 | + $rhsStandard = $this->standardize($rhs); |
|
112 | + return $lhsStandard->getAmount()->compare($rhsStandard->getAmount()); |
|
113 | 113 | } |
114 | 114 | |
115 | - throw new InvalidArgumentException( 'Unsupported data value type' ); |
|
115 | + throw new InvalidArgumentException('Unsupported data value type'); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -127,71 +127,71 @@ discard block |
||
127 | 127 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
128 | 128 | * @return UnboundedQuantityValue |
129 | 129 | */ |
130 | - public function getDifference( DataValue $minuend, DataValue $subtrahend ) { |
|
131 | - if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) { |
|
132 | - $minuendSeconds = $this->timeCalculator->getTimestamp( $minuend ); |
|
133 | - $subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend ); |
|
130 | + public function getDifference(DataValue $minuend, DataValue $subtrahend) { |
|
131 | + if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') { |
|
132 | + $minuendSeconds = $this->timeCalculator->getTimestamp($minuend); |
|
133 | + $subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend); |
|
134 | 134 | return UnboundedQuantityValue::newFromNumber( |
135 | 135 | $minuendSeconds - $subtrahendSeconds, |
136 | - $this->config->get( 'WBQualityConstraintsSecondUnit' ) |
|
136 | + $this->config->get('WBQualityConstraintsSecondUnit') |
|
137 | 137 | ); |
138 | 138 | } |
139 | - if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) { |
|
140 | - $minuendStandard = $this->standardize( $minuend ); |
|
141 | - $subtrahendStandard = $this->standardize( $subtrahend ); |
|
139 | + if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') { |
|
140 | + $minuendStandard = $this->standardize($minuend); |
|
141 | + $subtrahendStandard = $this->standardize($subtrahend); |
|
142 | 142 | $minuendValue = $minuendStandard->getAmount()->getValueFloat(); |
143 | 143 | $subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat(); |
144 | 144 | $diff = $minuendValue - $subtrahendValue; |
145 | 145 | // we don’t check whether both quantities have the same standard unit – |
146 | 146 | // that’s the job of a different constraint type, Units (T164372) |
147 | - return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() ); |
|
147 | + return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit()); |
|
148 | 148 | } |
149 | 149 | |
150 | - throw new InvalidArgumentException( 'Unsupported or different data value types' ); |
|
150 | + throw new InvalidArgumentException('Unsupported or different data value types'); |
|
151 | 151 | } |
152 | 152 | |
153 | - public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ): DataValue { |
|
154 | - if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) || |
|
155 | - !preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches ) |
|
153 | + public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend): DataValue { |
|
154 | + if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) || |
|
155 | + !preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches) |
|
156 | 156 | ) { |
157 | - throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' ); |
|
157 | + throw new InvalidArgumentException('TimeValue::getTime() did not match expected format'); |
|
158 | 158 | } |
159 | - $minuendYear = (float)$minuendMatches[1]; |
|
160 | - $subtrahendYear = (float)$subtrahendMatches[1]; |
|
159 | + $minuendYear = (float) $minuendMatches[1]; |
|
160 | + $subtrahendYear = (float) $subtrahendMatches[1]; |
|
161 | 161 | $minuendRest = $minuendMatches[2]; |
162 | 162 | $subtrahendRest = $subtrahendMatches[2]; |
163 | 163 | |
164 | 164 | // calculate difference of years |
165 | 165 | $diff = $minuendYear - $subtrahendYear; |
166 | - if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) { |
|
166 | + if ($minuendYear > 0.0 && $subtrahendYear < 0.0) { |
|
167 | 167 | $diff -= 1.0; // there is no year 0, remove it from difference |
168 | - } elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) { |
|
168 | + } elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) { |
|
169 | 169 | $diff -= -1.0; // there is no year 0, remove it from negative difference |
170 | 170 | } |
171 | 171 | |
172 | 172 | // adjust for date within year by parsing the month-day part within the same year |
173 | - $minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest ); |
|
174 | - $subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest ); |
|
175 | - $minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue ); |
|
176 | - $subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue ); |
|
177 | - if ( $minuendDateSeconds < $subtrahendDateSeconds ) { |
|
173 | + $minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest); |
|
174 | + $subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest); |
|
175 | + $minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue); |
|
176 | + $subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue); |
|
177 | + if ($minuendDateSeconds < $subtrahendDateSeconds) { |
|
178 | 178 | // difference in the last year is actually less than one full year |
179 | 179 | // e. g. 1975-03-01 - 1974-09-01 is just six months |
180 | 180 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
181 | 181 | $diff -= 0.5; |
182 | - } elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) { |
|
182 | + } elseif ($minuendDateSeconds > $subtrahendDateSeconds) { |
|
183 | 183 | // difference in the last year is actually more than one full year |
184 | 184 | // e. g. 1975-09-01 - 1974-03-01 is 18 months |
185 | 185 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
186 | 186 | $diff += 0.5; |
187 | 187 | } |
188 | 188 | |
189 | - $unit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
190 | - return UnboundedQuantityValue::newFromNumber( $diff, $unit ); |
|
189 | + $unit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
190 | + return UnboundedQuantityValue::newFromNumber($diff, $unit); |
|
191 | 191 | } |
192 | 192 | |
193 | - public function isFutureTime( TimeValue $timeValue ): bool { |
|
194 | - return $this->timeValueComparer->isFutureTime( $timeValue ); |
|
193 | + public function isFutureTime(TimeValue $timeValue): bool { |
|
194 | + return $this->timeValueComparer->isFutureTime($timeValue); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | } |
@@ -9,8 +9,8 @@ |
||
9 | 9 | */ |
10 | 10 | class SparqlHelperException extends RuntimeException { |
11 | 11 | |
12 | - public function __construct( string $msg = 'The SPARQL query endpoint returned an error.' ) { |
|
13 | - parent::__construct( $msg ); |
|
12 | + public function __construct(string $msg = 'The SPARQL query endpoint returned an error.') { |
|
13 | + parent::__construct($msg); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | } |