@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
4 | - wfLoadExtension( 'WikibaseQualityConstraints', __DIR__ . '/extension.json' ); |
|
3 | +if (function_exists('wfLoadExtension')) { |
|
4 | + wfLoadExtension('WikibaseQualityConstraints', __DIR__.'/extension.json'); |
|
5 | 5 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
6 | - $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__ . '/i18n'; |
|
7 | - $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__ . '/WikibaseQualityConstraints.alias.php'; |
|
6 | + $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__.'/i18n'; |
|
7 | + $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__.'/WikibaseQualityConstraints.alias.php'; |
|
8 | 8 | /* wfWarn( |
9 | 9 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
10 | 10 | 'Please use wfLoadExtension instead, ' . |
@@ -12,5 +12,5 @@ discard block |
||
12 | 12 | ); */ |
13 | 13 | return; |
14 | 14 | } else { |
15 | - die( 'This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+' ); |
|
15 | + die('This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+'); |
|
16 | 16 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | |
11 | 11 | /** English (English) */ |
12 | 12 | $specialPageAliases['en'] = [ |
13 | - 'ConstraintReport' => [ 'ConstraintReport', 'Constraint Report' ], |
|
13 | + 'ConstraintReport' => ['ConstraintReport', 'Constraint Report'], |
|
14 | 14 | ]; |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | use WikibaseQuality\ConstraintReport\UpdateConstraintsTableJob; |
9 | 9 | use Wikibase\Repo\WikibaseRepo; |
10 | 10 | |
11 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
12 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
11 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
12 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
13 | 13 | |
14 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
14 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Runs {@link UpdateConstraintsTableJob} once for every property. |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | public function __construct() { |
24 | 24 | parent::__construct(); |
25 | 25 | |
26 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
26 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function execute() { |
30 | - if ( !MediaWikiServices::getInstance()->getMainConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
31 | - $this->error( 'Constraint statements are not enabled. Aborting.', 1 ); |
|
30 | + if (!MediaWikiServices::getInstance()->getMainConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
31 | + $this->error('Constraint statements are not enabled. Aborting.', 1); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $propertyInfoLookup = WikibaseRepo::getDefaultInstance()->getStore()->getPropertyInfoLookup(); |
35 | - foreach ( $propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
36 | - $this->output( sprintf( 'Importing constraint statements for % 6s... ', $propertyIdSerialization ), $propertyIdSerialization ); |
|
37 | - $startTime = microtime( true ); |
|
38 | - $job = UpdateConstraintsTableJob::newFromGlobalState( Title::newMainPage(), [ 'propertyId' => $propertyIdSerialization ] ); |
|
35 | + foreach ($propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
36 | + $this->output(sprintf('Importing constraint statements for % 6s... ', $propertyIdSerialization), $propertyIdSerialization); |
|
37 | + $startTime = microtime(true); |
|
38 | + $job = UpdateConstraintsTableJob::newFromGlobalState(Title::newMainPage(), ['propertyId' => $propertyIdSerialization]); |
|
39 | 39 | $job->run(); |
40 | - $endTime = microtime( true ); |
|
41 | - $millis = ( $endTime - $startTime ) * 1000; |
|
42 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
40 | + $endTime = microtime(true); |
|
41 | + $millis = ($endTime - $startTime) * 1000; |
|
42 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | - * @param EntityDocument|StatementListProvider $entity |
|
273 | + * @param EntityDocument $entity |
|
274 | 274 | * @param string[]|null $constraintIds list of constraints to check (if null: all constraints) |
275 | 275 | * @param callable|null $defaultResults optional function to pre-populate the check results |
276 | 276 | * |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
301 | - * @param EntityDocument|StatementListProvider $entity |
|
301 | + * @param EntityDocument $entity |
|
302 | 302 | * @param Statement $statement |
303 | 303 | * @param string[]|null $constraintIds list of constraints to check (if null: all constraints) |
304 | 304 | * @param callable|null $defaultResults optional function to pre-populate the check results |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | callable $defaultResults = null |
138 | 138 | ) { |
139 | 139 | |
140 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
141 | - if ( $entity instanceof StatementListProvider ) { |
|
140 | + $entity = $this->entityLookup->getEntity($entityId); |
|
141 | + if ($entity instanceof StatementListProvider) { |
|
142 | 142 | $result = $this->checkEveryStatement( |
143 | - $this->entityLookup->getEntity( $entityId ), |
|
143 | + $this->entityLookup->getEntity($entityId), |
|
144 | 144 | $constraintIds, |
145 | 145 | $defaultResults |
146 | 146 | ); |
147 | - $output = $this->sortResult( $result ); |
|
147 | + $output = $this->sortResult($result); |
|
148 | 148 | return $output; |
149 | 149 | } |
150 | 150 | |
@@ -170,19 +170,19 @@ discard block |
||
170 | 170 | callable $defaultResults = null |
171 | 171 | ) { |
172 | 172 | |
173 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
173 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
174 | 174 | $entityId = $parsedGuid->getEntityId(); |
175 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
176 | - if ( $entity instanceof StatementListProvider ) { |
|
177 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
178 | - if ( $statement ) { |
|
175 | + $entity = $this->entityLookup->getEntity($entityId); |
|
176 | + if ($entity instanceof StatementListProvider) { |
|
177 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
178 | + if ($statement) { |
|
179 | 179 | $result = $this->checkStatement( |
180 | 180 | $entity, |
181 | 181 | $statement, |
182 | 182 | $constraintIds, |
183 | 183 | $defaultResults |
184 | 184 | ); |
185 | - $output = $this->sortResult( $result ); |
|
185 | + $output = $this->sortResult($result); |
|
186 | 186 | return $output; |
187 | 187 | } |
188 | 188 | } |
@@ -198,23 +198,23 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @return ConstraintParameterException[] |
200 | 200 | */ |
201 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
201 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
202 | 202 | $constraintParameters = $constraint->getConstraintParameters(); |
203 | 203 | try { |
204 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
205 | - } catch ( ConstraintParameterException $e ) { |
|
206 | - return [ $e ]; |
|
204 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
205 | + } catch (ConstraintParameterException $e) { |
|
206 | + return [$e]; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | $problems = []; |
210 | 210 | try { |
211 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
212 | - } catch ( ConstraintParameterException $e ) { |
|
211 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
212 | + } catch (ConstraintParameterException $e) { |
|
213 | 213 | $problems[] = $e; |
214 | 214 | } |
215 | 215 | try { |
216 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
217 | - } catch ( ConstraintParameterException $e ) { |
|
216 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
217 | + } catch (ConstraintParameterException $e) { |
|
218 | 218 | $problems[] = $e; |
219 | 219 | } |
220 | 220 | return $problems; |
@@ -227,16 +227,16 @@ discard block |
||
227 | 227 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
228 | 228 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
229 | 229 | */ |
230 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
231 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
230 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
231 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
232 | 232 | $result = []; |
233 | 233 | |
234 | - foreach ( $constraints as $constraint ) { |
|
235 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
234 | + foreach ($constraints as $constraint) { |
|
235 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
236 | 236 | |
237 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
237 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
238 | 238 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
239 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
239 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | $result[$constraint->getConstraintId()] = $problems; |
@@ -253,17 +253,17 @@ discard block |
||
253 | 253 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
254 | 254 | * (empty means all parameters okay), or null if constraint is not found |
255 | 255 | */ |
256 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
257 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
258 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
256 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
257 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
258 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
259 | 259 | |
260 | - foreach ( $constraints as $constraint ) { |
|
261 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
262 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
260 | + foreach ($constraints as $constraint) { |
|
261 | + if ($constraint->getConstraintId() === $constraintId) { |
|
262 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
263 | 263 | |
264 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
264 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
265 | 265 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
266 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
266 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | return $problems; |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | $result = []; |
289 | 289 | |
290 | 290 | /** @var Statement $statement */ |
291 | - foreach ( $entity->getStatements() as $statement ) { |
|
292 | - $result = array_merge( $result, |
|
291 | + foreach ($entity->getStatements() as $statement) { |
|
292 | + $result = array_merge($result, |
|
293 | 293 | $this->checkStatement( |
294 | 294 | $entity, |
295 | 295 | $statement, |
296 | 296 | $constraintIds, |
297 | 297 | $defaultResults |
298 | - ) ); |
|
298 | + )); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | return $result; |
@@ -317,32 +317,32 @@ discard block |
||
317 | 317 | ) { |
318 | 318 | $result = []; |
319 | 319 | |
320 | - $result = array_merge( $result, |
|
320 | + $result = array_merge($result, |
|
321 | 321 | $this->checkConstraintsForMainSnak( |
322 | 322 | $entity, |
323 | 323 | $statement, |
324 | 324 | $constraintIds, |
325 | 325 | $defaultResults |
326 | - ) ); |
|
326 | + )); |
|
327 | 327 | |
328 | - if ( $this->checkQualifiers ) { |
|
329 | - $result = array_merge( $result, |
|
328 | + if ($this->checkQualifiers) { |
|
329 | + $result = array_merge($result, |
|
330 | 330 | $this->checkConstraintsForQualifiers( |
331 | 331 | $entity, |
332 | 332 | $statement, |
333 | 333 | $constraintIds, |
334 | 334 | $defaultResults |
335 | - ) ); |
|
335 | + )); |
|
336 | 336 | } |
337 | 337 | |
338 | - if ( $this->checkReferences ) { |
|
339 | - $result = array_merge( $result, |
|
338 | + if ($this->checkReferences) { |
|
339 | + $result = array_merge($result, |
|
340 | 340 | $this->checkConstraintsForReferences( |
341 | 341 | $entity, |
342 | 342 | $statement, |
343 | 343 | $constraintIds, |
344 | 344 | $defaultResults |
345 | - ) ); |
|
345 | + )); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | return $result; |
@@ -357,12 +357,12 @@ discard block |
||
357 | 357 | * @param string[]|null $constraintIds |
358 | 358 | * @return Constraint[] |
359 | 359 | */ |
360 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
361 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
362 | - if ( $constraintIds !== null ) { |
|
360 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
361 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
362 | + if ($constraintIds !== null) { |
|
363 | 363 | $constraintsToUse = []; |
364 | - foreach ( $constraints as $constraint ) { |
|
365 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
364 | + foreach ($constraints as $constraint) { |
|
365 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
366 | 366 | $constraintsToUse[] = $constraint; |
367 | 367 | } |
368 | 368 | } |
@@ -386,29 +386,29 @@ discard block |
||
386 | 386 | array $constraintIds = null, |
387 | 387 | callable $defaultResults = null |
388 | 388 | ) { |
389 | - $context = new MainSnakContext( $entity, $statement ); |
|
389 | + $context = new MainSnakContext($entity, $statement); |
|
390 | 390 | $constraints = $this->getConstraintsToUse( |
391 | 391 | $statement->getPropertyId(), |
392 | 392 | $constraintIds |
393 | 393 | ); |
394 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
394 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
395 | 395 | |
396 | - foreach ( $constraints as $constraint ) { |
|
396 | + foreach ($constraints as $constraint) { |
|
397 | 397 | $parameters = $constraint->getConstraintParameters(); |
398 | 398 | try { |
399 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
400 | - } catch ( ConstraintParameterException $e ) { |
|
401 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
399 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
400 | + } catch (ConstraintParameterException $e) { |
|
401 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
402 | 402 | continue; |
403 | 403 | } |
404 | 404 | |
405 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
406 | - $message = wfMessage( 'wbqc-exception-message' )->escaped(); |
|
407 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
405 | + if (in_array($entity->getId(), $exceptions)) { |
|
406 | + $message = wfMessage('wbqc-exception-message')->escaped(); |
|
407 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
408 | 408 | continue; |
409 | 409 | } |
410 | 410 | |
411 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
411 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | return $result; |
@@ -430,24 +430,24 @@ discard block |
||
430 | 430 | ) { |
431 | 431 | $result = []; |
432 | 432 | |
433 | - if ( in_array( |
|
433 | + if (in_array( |
|
434 | 434 | $statement->getPropertyId()->getSerialization(), |
435 | 435 | $this->propertiesWithViolatingQualifiers |
436 | - ) ) { |
|
436 | + )) { |
|
437 | 437 | return $result; |
438 | 438 | } |
439 | 439 | |
440 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
441 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
442 | - if ( $defaultResults !== null ) { |
|
443 | - $result = array_merge( $result, $defaultResults( $qualifierContext ) ); |
|
440 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
441 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
442 | + if ($defaultResults !== null) { |
|
443 | + $result = array_merge($result, $defaultResults($qualifierContext)); |
|
444 | 444 | } |
445 | 445 | $qualifierConstraints = $this->getConstraintsToUse( |
446 | 446 | $qualifierContext->getSnak()->getPropertyId(), |
447 | 447 | $constraintIds |
448 | 448 | ); |
449 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
450 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
449 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
450 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 | |
@@ -471,19 +471,19 @@ discard block |
||
471 | 471 | $result = []; |
472 | 472 | |
473 | 473 | /** @var Reference $reference */ |
474 | - foreach ( $statement->getReferences() as $reference ) { |
|
475 | - foreach ( $reference->getSnaks() as $snak ) { |
|
474 | + foreach ($statement->getReferences() as $reference) { |
|
475 | + foreach ($reference->getSnaks() as $snak) { |
|
476 | 476 | $referenceContext = new ReferenceContext( |
477 | 477 | $entity, $statement, $reference, $snak |
478 | 478 | ); |
479 | - if ( $defaultResults !== null ) { |
|
480 | - $result = array_merge( $result, $defaultResults( $referenceContext ) ); |
|
479 | + if ($defaultResults !== null) { |
|
480 | + $result = array_merge($result, $defaultResults($referenceContext)); |
|
481 | 481 | } |
482 | 482 | $referenceConstraints = $this->getConstraintsToUse( |
483 | 483 | $referenceContext->getSnak()->getPropertyId(), |
484 | 484 | $constraintIds |
485 | 485 | ); |
486 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
486 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
487 | 487 | $result[] = $this->getCheckResultFor( |
488 | 488 | $referenceContext, |
489 | 489 | $referenceConstraint |
@@ -502,70 +502,70 @@ discard block |
||
502 | 502 | * @throws InvalidArgumentException |
503 | 503 | * @return CheckResult |
504 | 504 | */ |
505 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
506 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
505 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
506 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
507 | 507 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
508 | 508 | |
509 | - $startTime = microtime( true ); |
|
509 | + $startTime = microtime(true); |
|
510 | 510 | try { |
511 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
512 | - } catch ( ConstraintParameterException $e ) { |
|
513 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
514 | - } catch ( SparqlHelperException $e ) { |
|
515 | - $message = wfMessage( 'wbqc-violation-message-sparql-error' )->escaped(); |
|
516 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
511 | + $result = $checker->checkConstraint($context, $constraint); |
|
512 | + } catch (ConstraintParameterException $e) { |
|
513 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
514 | + } catch (SparqlHelperException $e) { |
|
515 | + $message = wfMessage('wbqc-violation-message-sparql-error')->escaped(); |
|
516 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
517 | 517 | } |
518 | - $endTime = microtime( true ); |
|
518 | + $endTime = microtime(true); |
|
519 | 519 | |
520 | - $this->addMetadata( $result ); |
|
520 | + $this->addMetadata($result); |
|
521 | 521 | |
522 | 522 | try { |
523 | 523 | $constraintStatus = $this->constraintParameterParser |
524 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
525 | - } catch ( ConstraintParameterException $e ) { |
|
526 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
524 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
525 | + } catch (ConstraintParameterException $e) { |
|
526 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
527 | 527 | $constraintStatus = null; |
528 | 528 | } |
529 | - if ( $constraintStatus === null ) { |
|
529 | + if ($constraintStatus === null) { |
|
530 | 530 | // downgrade violation to warning |
531 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
532 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
531 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
532 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
533 | 533 | } |
534 | 534 | } else { |
535 | - if ( $constraintStatus !== 'mandatory' ) { |
|
535 | + if ($constraintStatus !== 'mandatory') { |
|
536 | 536 | // @codeCoverageIgnoreStart |
537 | 537 | throw new LogicException( |
538 | - "Unknown constraint status '$constraintStatus', " . |
|
538 | + "Unknown constraint status '$constraintStatus', ". |
|
539 | 539 | "only known status is 'mandatory'" |
540 | 540 | ); |
541 | 541 | // @codeCoverageIgnoreEnd |
542 | 542 | } |
543 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
543 | + $result->addParameter('constraint_status', $constraintStatus); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | $this->loggingHelper->logConstraintCheck( |
547 | 547 | $context, |
548 | 548 | $constraint, |
549 | 549 | $result, |
550 | - get_class( $checker ), |
|
550 | + get_class($checker), |
|
551 | 551 | $endTime - $startTime, |
552 | 552 | __METHOD__ |
553 | 553 | ); |
554 | 554 | |
555 | 555 | return $result; |
556 | 556 | } else { |
557 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
557 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | - private function addMetadata( CheckResult $result ) { |
|
562 | - $result->withMetadata( Metadata::merge( [ |
|
561 | + private function addMetadata(CheckResult $result) { |
|
562 | + $result->withMetadata(Metadata::merge([ |
|
563 | 563 | $result->getMetadata(), |
564 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
565 | - DependencyMetadata::ofEntityId( $result->getEntityId() ), |
|
566 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
567 | - ] ) ), |
|
568 | - ] ) ); |
|
564 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
565 | + DependencyMetadata::ofEntityId($result->getEntityId()), |
|
566 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
567 | + ])), |
|
568 | + ])); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -573,12 +573,12 @@ discard block |
||
573 | 573 | * |
574 | 574 | * @return CheckResult[] |
575 | 575 | */ |
576 | - private function sortResult( array $result ) { |
|
577 | - if ( count( $result ) < 2 ) { |
|
576 | + private function sortResult(array $result) { |
|
577 | + if (count($result) < 2) { |
|
578 | 578 | return $result; |
579 | 579 | } |
580 | 580 | |
581 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
581 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
582 | 582 | $orderNum = 0; |
583 | 583 | $order = [ |
584 | 584 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -594,45 +594,45 @@ discard block |
||
594 | 594 | $statusA = $a->getStatus(); |
595 | 595 | $statusB = $b->getStatus(); |
596 | 596 | |
597 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
598 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
597 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
598 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
599 | 599 | |
600 | - if ( $orderA === $orderB ) { |
|
600 | + if ($orderA === $orderB) { |
|
601 | 601 | $pidA = $a->getContext()->getSnak()->getPropertyId()->getSerialization(); |
602 | 602 | $pidB = $b->getContext()->getSnak()->getPropertyId()->getSerialization(); |
603 | 603 | |
604 | - if ( $pidA === $pidB ) { |
|
604 | + if ($pidA === $pidB) { |
|
605 | 605 | $hashA = $a->getContext()->getSnak()->getHash(); |
606 | 606 | $hashB = $b->getContext()->getSnak()->getHash(); |
607 | 607 | |
608 | - if ( $hashA === $hashB ) { |
|
609 | - if ( $a instanceof NullResult ) { |
|
608 | + if ($hashA === $hashB) { |
|
609 | + if ($a instanceof NullResult) { |
|
610 | 610 | return $b instanceof NullResult ? 0 : -1; |
611 | 611 | } |
612 | - if ( $b instanceof NullResult ) { |
|
612 | + if ($b instanceof NullResult) { |
|
613 | 613 | return $a instanceof NullResult ? 0 : 1; |
614 | 614 | } |
615 | 615 | |
616 | 616 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
617 | 617 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
618 | 618 | |
619 | - if ( $typeA == $typeB ) { |
|
619 | + if ($typeA == $typeB) { |
|
620 | 620 | return 0; |
621 | 621 | } else { |
622 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
622 | + return ($typeA > $typeB) ? 1 : -1; |
|
623 | 623 | } |
624 | 624 | } else { |
625 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
625 | + return ($hashA > $hashB) ? 1 : -1; |
|
626 | 626 | } |
627 | 627 | } else { |
628 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
628 | + return ($pidA > $pidB) ? 1 : -1; |
|
629 | 629 | } |
630 | 630 | } else { |
631 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
631 | + return ($orderA > $orderB) ? 1 : -1; |
|
632 | 632 | } |
633 | 633 | }; |
634 | 634 | |
635 | - uasort( $result, $sortFunction ); |
|
635 | + uasort($result, $sortFunction); |
|
636 | 636 | |
637 | 637 | return $result; |
638 | 638 | } |
@@ -119,8 +119,8 @@ |
||
119 | 119 | * for quantity values, the difference is the numerical difference between the quantities, |
120 | 120 | * after attempting normalization of each side. |
121 | 121 | * |
122 | - * @param TimeValue|QuantityValue|UnboundedQuantityValue $minuend |
|
123 | - * @param TimeValue|QuantityValue|UnboundedQuantityValue $subtrahend |
|
122 | + * @param DataValue $minuend |
|
123 | + * @param DataValue $subtrahend |
|
124 | 124 | * |
125 | 125 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
126 | 126 | * @return UnboundedQuantityValue |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | UnitConverter $unitConverter = null |
48 | 48 | ) { |
49 | 49 | $this->config = $config; |
50 | - $this->timeParser = ( new TimeParserFactory() )->getTimeParser(); |
|
50 | + $this->timeParser = (new TimeParserFactory())->getTimeParser(); |
|
51 | 51 | $this->timeCalculator = new TimeValueCalculator(); |
52 | 52 | $this->unitConverter = $unitConverter; |
53 | 53 | } |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | * @param UnboundedQuantityValue $value |
57 | 57 | * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value. |
58 | 58 | */ |
59 | - private function standardize( UnboundedQuantityValue $value ) { |
|
60 | - if ( $this->unitConverter !== null ) { |
|
61 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
62 | - if ( $standard !== null ) { |
|
59 | + private function standardize(UnboundedQuantityValue $value) { |
|
60 | + if ($this->unitConverter !== null) { |
|
61 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
62 | + if ($standard !== null) { |
|
63 | 63 | return $standard; |
64 | 64 | } else { |
65 | 65 | return $value; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | * when $lhs is respectively less than, equal to, or greater than $rhs. |
82 | 82 | * (In other words, just like the “spaceship” operator <=>.) |
83 | 83 | */ |
84 | - public function getComparison( DataValue $lhs = null, DataValue $rhs = null ) { |
|
85 | - if ( $lhs === null || $rhs === null ) { |
|
84 | + public function getComparison(DataValue $lhs = null, DataValue $rhs = null) { |
|
85 | + if ($lhs === null || $rhs === null) { |
|
86 | 86 | return 0; |
87 | 87 | } |
88 | 88 | |
89 | - if ( $lhs->getType() !== $rhs->getType() ) { |
|
90 | - throw new InvalidArgumentException( 'Different data value types' ); |
|
89 | + if ($lhs->getType() !== $rhs->getType()) { |
|
90 | + throw new InvalidArgumentException('Different data value types'); |
|
91 | 91 | } |
92 | 92 | |
93 | - switch ( $lhs->getType() ) { |
|
93 | + switch ($lhs->getType()) { |
|
94 | 94 | case 'time': |
95 | 95 | /** @var TimeValue $lhs */ |
96 | 96 | /** @var TimeValue $rhs */ |
97 | - $lhsTimestamp = $this->timeCalculator->getTimestamp( $lhs ); |
|
98 | - $rhsTimestamp = $this->timeCalculator->getTimestamp( $rhs ); |
|
97 | + $lhsTimestamp = $this->timeCalculator->getTimestamp($lhs); |
|
98 | + $rhsTimestamp = $this->timeCalculator->getTimestamp($rhs); |
|
99 | 99 | |
100 | - if ( $lhsTimestamp === $rhsTimestamp ) { |
|
100 | + if ($lhsTimestamp === $rhsTimestamp) { |
|
101 | 101 | return 0; |
102 | 102 | } |
103 | 103 | |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | case 'quantity': |
106 | 106 | /** @var QuantityValue|UnboundedQuantityValue $lhs */ |
107 | 107 | /** @var QuantityValue|UnboundedQuantityValue $rhs */ |
108 | - $lhsStandard = $this->standardize( $lhs ); |
|
109 | - $rhsStandard = $this->standardize( $rhs ); |
|
110 | - return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() ); |
|
108 | + $lhsStandard = $this->standardize($lhs); |
|
109 | + $rhsStandard = $this->standardize($rhs); |
|
110 | + return $lhsStandard->getAmount()->compare($rhsStandard->getAmount()); |
|
111 | 111 | } |
112 | 112 | |
113 | - throw new InvalidArgumentException( 'Unsupported data value type' ); |
|
113 | + throw new InvalidArgumentException('Unsupported data value type'); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -125,83 +125,83 @@ discard block |
||
125 | 125 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
126 | 126 | * @return UnboundedQuantityValue |
127 | 127 | */ |
128 | - public function getDifference( DataValue $minuend, DataValue $subtrahend ) { |
|
129 | - if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) { |
|
130 | - $minuendSeconds = $this->timeCalculator->getTimestamp( $minuend ); |
|
131 | - $subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend ); |
|
128 | + public function getDifference(DataValue $minuend, DataValue $subtrahend) { |
|
129 | + if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') { |
|
130 | + $minuendSeconds = $this->timeCalculator->getTimestamp($minuend); |
|
131 | + $subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend); |
|
132 | 132 | return UnboundedQuantityValue::newFromNumber( |
133 | 133 | $minuendSeconds - $subtrahendSeconds, |
134 | - $this->config->get( 'WBQualityConstraintsSecondUnit' ) |
|
134 | + $this->config->get('WBQualityConstraintsSecondUnit') |
|
135 | 135 | ); |
136 | 136 | } |
137 | - if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) { |
|
138 | - $minuendStandard = $this->standardize( $minuend ); |
|
139 | - $subtrahendStandard = $this->standardize( $subtrahend ); |
|
137 | + if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') { |
|
138 | + $minuendStandard = $this->standardize($minuend); |
|
139 | + $subtrahendStandard = $this->standardize($subtrahend); |
|
140 | 140 | $minuendValue = $minuendStandard->getAmount()->getValueFloat(); |
141 | 141 | $subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat(); |
142 | 142 | $diff = $minuendValue - $subtrahendValue; |
143 | 143 | // we don’t check whether both quantities have the same standard unit – |
144 | 144 | // that’s the job of a different constraint type, Units (T164372) |
145 | - return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() ); |
|
145 | + return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit()); |
|
146 | 146 | } |
147 | 147 | |
148 | - throw new InvalidArgumentException( 'Unsupported or different data value types' ); |
|
148 | + throw new InvalidArgumentException('Unsupported or different data value types'); |
|
149 | 149 | } |
150 | 150 | |
151 | - public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ) { |
|
152 | - if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) || |
|
153 | - !preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches ) |
|
151 | + public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend) { |
|
152 | + if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) || |
|
153 | + !preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches) |
|
154 | 154 | ) { |
155 | - throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' ); |
|
155 | + throw new InvalidArgumentException('TimeValue::getTime() did not match expected format'); |
|
156 | 156 | } |
157 | - $minuendYear = (float)$minuendMatches[1]; |
|
158 | - $subtrahendYear = (float)$subtrahendMatches[1]; |
|
157 | + $minuendYear = (float) $minuendMatches[1]; |
|
158 | + $subtrahendYear = (float) $subtrahendMatches[1]; |
|
159 | 159 | $minuendRest = $minuendMatches[2]; |
160 | 160 | $subtrahendRest = $subtrahendMatches[2]; |
161 | 161 | |
162 | 162 | // calculate difference of years |
163 | 163 | $diff = $minuendYear - $subtrahendYear; |
164 | - if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) { |
|
164 | + if ($minuendYear > 0.0 && $subtrahendYear < 0.0) { |
|
165 | 165 | $diff -= 1.0; // there is no year 0, remove it from difference |
166 | - } elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) { |
|
166 | + } elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) { |
|
167 | 167 | $diff -= -1.0; // there is no year 0, remove it from negative difference |
168 | 168 | } |
169 | 169 | |
170 | 170 | // adjust for date within year by parsing the month-day part within the same year |
171 | - $minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest ); |
|
172 | - $subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest ); |
|
173 | - $minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue ); |
|
174 | - $subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue ); |
|
175 | - if ( $minuendDateSeconds < $subtrahendDateSeconds ) { |
|
171 | + $minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest); |
|
172 | + $subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest); |
|
173 | + $minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue); |
|
174 | + $subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue); |
|
175 | + if ($minuendDateSeconds < $subtrahendDateSeconds) { |
|
176 | 176 | // difference in the last year is actually less than one full year |
177 | 177 | // e. g. 1975-03-01 - 1974-09-01 is just six months |
178 | 178 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
179 | 179 | $diff -= 0.5; |
180 | - } elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) { |
|
180 | + } elseif ($minuendDateSeconds > $subtrahendDateSeconds) { |
|
181 | 181 | // difference in the last year is actually more than one full year |
182 | 182 | // e. g. 1975-09-01 - 1974-03-01 is 18 months |
183 | 183 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
184 | 184 | $diff += 0.5; |
185 | 185 | } |
186 | 186 | |
187 | - $unit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
188 | - return UnboundedQuantityValue::newFromNumber( $diff, $unit ); |
|
187 | + $unit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
188 | + return UnboundedQuantityValue::newFromNumber($diff, $unit); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param string $timeString |
193 | 193 | * @return TimeValue |
194 | 194 | */ |
195 | - public function parseTime( $timeString ) { |
|
196 | - return $this->timeParser->parse( $timeString ); |
|
195 | + public function parseTime($timeString) { |
|
196 | + return $this->timeParser->parse($timeString); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
200 | 200 | * @param string $quantityString |
201 | 201 | * @return QuantityValue|UnboundedQuantityValue |
202 | 202 | */ |
203 | - public function parseQuantity( $quantityString ) { |
|
204 | - return UnboundedQuantityValue::newFromNumber( $quantityString ); |
|
203 | + public function parseQuantity($quantityString) { |
|
204 | + return UnboundedQuantityValue::newFromNumber($quantityString); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | } |
@@ -162,7 +162,7 @@ |
||
162 | 162 | /** |
163 | 163 | * Returns array of modules that should be added |
164 | 164 | * |
165 | - * @return array |
|
165 | + * @return string[] |
|
166 | 166 | */ |
167 | 167 | private function getModules() { |
168 | 168 | return [ 'SpecialConstraintReportPage' ]; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | Config $config, |
140 | 140 | IBufferingStatsdDataFactory $dataFactory |
141 | 141 | ) { |
142 | - parent::__construct( 'ConstraintReport' ); |
|
142 | + parent::__construct('ConstraintReport'); |
|
143 | 143 | |
144 | 144 | $this->entityLookup = $entityLookup; |
145 | 145 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | $language = $this->getLanguage(); |
149 | 149 | |
150 | 150 | $formatterOptions = new FormatterOptions(); |
151 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
151 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
152 | 152 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
153 | 153 | SnakFormatter::FORMAT_HTML, |
154 | 154 | $formatterOptions |
155 | 155 | ); |
156 | 156 | |
157 | - $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup( $language ); |
|
157 | + $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup($language); |
|
158 | 158 | |
159 | 159 | $this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( |
160 | 160 | $labelLookup |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | $this->constraintChecker = $constraintChecker; |
168 | 168 | |
169 | - $this->constraintParameterRenderer = new ConstraintParameterRenderer( $this->entityIdLabelFormatter, $this->dataValueFormatter ); |
|
169 | + $this->constraintParameterRenderer = new ConstraintParameterRenderer($this->entityIdLabelFormatter, $this->dataValueFormatter); |
|
170 | 170 | |
171 | 171 | $this->config = $config; |
172 | 172 | $this->dataFactory = $dataFactory; |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @return array |
179 | 179 | */ |
180 | 180 | private function getModules() { |
181 | - return [ 'SpecialConstraintReportPage' ]; |
|
181 | + return ['SpecialConstraintReportPage']; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @return string |
197 | 197 | */ |
198 | 198 | public function getDescription() { |
199 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
199 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -208,42 +208,42 @@ discard block |
||
208 | 208 | * @throws EntityIdParsingException |
209 | 209 | * @throws UnexpectedValueException |
210 | 210 | */ |
211 | - public function execute( $subPage ) { |
|
211 | + public function execute($subPage) { |
|
212 | 212 | $out = $this->getOutput(); |
213 | 213 | |
214 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
215 | - if ( $postRequest ) { |
|
216 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
214 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
215 | + if ($postRequest) { |
|
216 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
217 | 217 | return; |
218 | 218 | } |
219 | 219 | |
220 | - $out->addModules( $this->getModules() ); |
|
220 | + $out->addModules($this->getModules()); |
|
221 | 221 | |
222 | 222 | $this->setHeaders(); |
223 | 223 | |
224 | - $out->addHTML( $this->getExplanationText() ); |
|
224 | + $out->addHTML($this->getExplanationText()); |
|
225 | 225 | $this->buildEntityIdForm(); |
226 | 226 | |
227 | - if ( !$subPage ) { |
|
227 | + if (!$subPage) { |
|
228 | 228 | return; |
229 | 229 | } |
230 | 230 | |
231 | - if ( !is_string( $subPage ) ) { |
|
232 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
231 | + if (!is_string($subPage)) { |
|
232 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | try { |
236 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
237 | - } catch ( EntityIdParsingException $e ) { |
|
236 | + $entityId = $this->entityIdParser->parse($subPage); |
|
237 | + } catch (EntityIdParsingException $e) { |
|
238 | 238 | $out->addHTML( |
239 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
239 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
240 | 240 | ); |
241 | 241 | return; |
242 | 242 | } |
243 | 243 | |
244 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
244 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
245 | 245 | $out->addHTML( |
246 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
246 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
247 | 247 | ); |
248 | 248 | return; |
249 | 249 | } |
@@ -251,18 +251,18 @@ discard block |
||
251 | 251 | $this->dataFactory->increment( |
252 | 252 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
253 | 253 | ); |
254 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
254 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
255 | 255 | |
256 | - if ( count( $results ) > 0 ) { |
|
256 | + if (count($results) > 0) { |
|
257 | 257 | $out->addHTML( |
258 | - $this->buildResultHeader( $entityId ) |
|
259 | - . $this->buildSummary( $results ) |
|
260 | - . $this->buildResultTable( $entityId, $results ) |
|
258 | + $this->buildResultHeader($entityId) |
|
259 | + . $this->buildSummary($results) |
|
260 | + . $this->buildResultTable($entityId, $results) |
|
261 | 261 | ); |
262 | 262 | } else { |
263 | 263 | $out->addHTML( |
264 | - $this->buildResultHeader( $entityId ) |
|
265 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
264 | + $this->buildResultHeader($entityId) |
|
265 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
266 | 266 | ); |
267 | 267 | } |
268 | 268 | } |
@@ -278,15 +278,15 @@ discard block |
||
278 | 278 | 'name' => 'entityid', |
279 | 279 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
280 | 280 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
281 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
281 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
282 | 282 | ] |
283 | 283 | ]; |
284 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
285 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
286 | - $htmlForm->setSubmitCallback( function() { |
|
284 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
285 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
286 | + $htmlForm->setSubmitCallback(function() { |
|
287 | 287 | return false; |
288 | 288 | } ); |
289 | - $htmlForm->setMethod( 'post' ); |
|
289 | + $htmlForm->setMethod('post'); |
|
290 | 290 | $htmlForm->show(); |
291 | 291 | } |
292 | 292 | |
@@ -300,16 +300,16 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return string HTML |
302 | 302 | */ |
303 | - private function buildNotice( $messageKey, $error = false ) { |
|
304 | - if ( !is_string( $messageKey ) ) { |
|
305 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
303 | + private function buildNotice($messageKey, $error = false) { |
|
304 | + if (!is_string($messageKey)) { |
|
305 | + throw new InvalidArgumentException('$message must be string.'); |
|
306 | 306 | } |
307 | - if ( !is_bool( $error ) ) { |
|
308 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
307 | + if (!is_bool($error)) { |
|
308 | + throw new InvalidArgumentException('$error must be bool.'); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | $cssClasses = 'wbqc-constraintreport-notice'; |
312 | - if ( $error ) { |
|
312 | + if ($error) { |
|
313 | 313 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
314 | 314 | } |
315 | 315 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | [ |
319 | 319 | 'class' => $cssClasses |
320 | 320 | ], |
321 | - $this->msg( $messageKey )->escaped() |
|
321 | + $this->msg($messageKey)->escaped() |
|
322 | 322 | ); |
323 | 323 | } |
324 | 324 | |
@@ -328,16 +328,16 @@ discard block |
||
328 | 328 | private function getExplanationText() { |
329 | 329 | return Html::rawElement( |
330 | 330 | 'div', |
331 | - [ 'class' => 'wbqc-explanation' ], |
|
331 | + ['class' => 'wbqc-explanation'], |
|
332 | 332 | Html::rawElement( |
333 | 333 | 'p', |
334 | 334 | [], |
335 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
335 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
336 | 336 | ) |
337 | 337 | . Html::rawElement( |
338 | 338 | 'p', |
339 | 339 | [], |
340 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
340 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
341 | 341 | ) |
342 | 342 | ); |
343 | 343 | } |
@@ -348,69 +348,69 @@ discard block |
||
348 | 348 | * |
349 | 349 | * @return string HTML |
350 | 350 | */ |
351 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
351 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
352 | 352 | // Set table headers |
353 | 353 | $table = new HtmlTableBuilder( |
354 | 354 | [ |
355 | 355 | new HtmlTableHeaderBuilder( |
356 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
356 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
357 | 357 | true |
358 | 358 | ), |
359 | 359 | new HtmlTableHeaderBuilder( |
360 | - $this->msg( 'wbqc-constraintreport-result-table-header-claim' )->escaped(), |
|
360 | + $this->msg('wbqc-constraintreport-result-table-header-claim')->escaped(), |
|
361 | 361 | true |
362 | 362 | ), |
363 | 363 | new HtmlTableHeaderBuilder( |
364 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
364 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
365 | 365 | true |
366 | 366 | ) |
367 | 367 | ] |
368 | 368 | ); |
369 | 369 | |
370 | - foreach ( $results as $result ) { |
|
371 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
370 | + foreach ($results as $result) { |
|
371 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | return $table->toHtml(); |
375 | 375 | } |
376 | 376 | |
377 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
377 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
378 | 378 | // Status column |
379 | 379 | $statusColumn = $this->buildTooltipElement( |
380 | - $this->formatStatus( $result->getStatus() ), |
|
380 | + $this->formatStatus($result->getStatus()), |
|
381 | 381 | $result->getMessage(), |
382 | 382 | '[?]' |
383 | 383 | ); |
384 | 384 | |
385 | 385 | // Claim column |
386 | - $property = $this->entityIdLabelFormatter->formatEntityId( $result->getContext()->getSnak()->getPropertyId() ); |
|
387 | - if ( $result->getSnakType() === 'value' ) { |
|
388 | - $value = $this->constraintParameterRenderer->formatValue( $result->getDataValue() ); |
|
386 | + $property = $this->entityIdLabelFormatter->formatEntityId($result->getContext()->getSnak()->getPropertyId()); |
|
387 | + if ($result->getSnakType() === 'value') { |
|
388 | + $value = $this->constraintParameterRenderer->formatValue($result->getDataValue()); |
|
389 | 389 | } else { |
390 | - $value = htmlspecialchars( $result->getSnakType() ); |
|
390 | + $value = htmlspecialchars($result->getSnakType()); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | $claimColumn = $this->getClaimLink( |
394 | 394 | $entityId, |
395 | 395 | $result->getContext()->getSnak()->getPropertyId(), |
396 | - $property . ': ' . $value |
|
396 | + $property.': '.$value |
|
397 | 397 | ); |
398 | 398 | |
399 | 399 | // Constraint column |
400 | 400 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
401 | 401 | try { |
402 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
403 | - } catch ( InvalidArgumentException $e ) { |
|
404 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
402 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
403 | + } catch (InvalidArgumentException $e) { |
|
404 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
405 | 405 | } |
406 | 406 | $constraintLink = $this->getClaimLink( |
407 | 407 | $result->getContext()->getSnak()->getPropertyId(), |
408 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
408 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
409 | 409 | $constraintTypeLabel |
410 | 410 | ); |
411 | 411 | $constraintColumn = $this->buildExpandableElement( |
412 | 412 | $constraintLink, |
413 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
413 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
414 | 414 | '[...]' |
415 | 415 | ); |
416 | 416 | |
@@ -445,15 +445,15 @@ discard block |
||
445 | 445 | * |
446 | 446 | * @return string HTML |
447 | 447 | */ |
448 | - protected function buildResultHeader( EntityId $entityId ) { |
|
449 | - $entityLink = sprintf( '%s (%s)', |
|
450 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
451 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
448 | + protected function buildResultHeader(EntityId $entityId) { |
|
449 | + $entityLink = sprintf('%s (%s)', |
|
450 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
451 | + htmlspecialchars($entityId->getSerialization())); |
|
452 | 452 | |
453 | 453 | return Html::rawElement( |
454 | 454 | 'h3', |
455 | 455 | [], |
456 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
456 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
457 | 457 | ); |
458 | 458 | } |
459 | 459 | |
@@ -464,24 +464,24 @@ discard block |
||
464 | 464 | * |
465 | 465 | * @return string HTML |
466 | 466 | */ |
467 | - protected function buildSummary( array $results ) { |
|
467 | + protected function buildSummary(array $results) { |
|
468 | 468 | $statuses = []; |
469 | - foreach ( $results as $result ) { |
|
470 | - $status = strtolower( $result->getStatus() ); |
|
471 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
469 | + foreach ($results as $result) { |
|
470 | + $status = strtolower($result->getStatus()); |
|
471 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | $statusElements = []; |
475 | - foreach ( $statuses as $status => $count ) { |
|
476 | - if ( $count > 0 ) { |
|
475 | + foreach ($statuses as $status => $count) { |
|
476 | + if ($count > 0) { |
|
477 | 477 | $statusElements[] = |
478 | - $this->formatStatus( $status ) |
|
478 | + $this->formatStatus($status) |
|
479 | 479 | . ': ' |
480 | 480 | . $count; |
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
484 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
484 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -496,15 +496,15 @@ discard block |
||
496 | 496 | * |
497 | 497 | * @return string HTML |
498 | 498 | */ |
499 | - protected function buildTooltipElement( $content, $tooltipContent, $indicator ) { |
|
500 | - if ( !is_string( $content ) ) { |
|
501 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
499 | + protected function buildTooltipElement($content, $tooltipContent, $indicator) { |
|
500 | + if (!is_string($content)) { |
|
501 | + throw new InvalidArgumentException('$content has to be string.'); |
|
502 | 502 | } |
503 | - if ( $tooltipContent && ( !is_string( $tooltipContent ) ) ) { |
|
504 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
503 | + if ($tooltipContent && (!is_string($tooltipContent))) { |
|
504 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
505 | 505 | } |
506 | 506 | |
507 | - if ( empty( $tooltipContent ) ) { |
|
507 | + if (empty($tooltipContent)) { |
|
508 | 508 | return $content; |
509 | 509 | } |
510 | 510 | |
@@ -521,13 +521,13 @@ discard block |
||
521 | 521 | [ |
522 | 522 | 'class' => 'wbqc-indicator' |
523 | 523 | ], |
524 | - htmlspecialchars( $indicator ) . $tooltip |
|
524 | + htmlspecialchars($indicator).$tooltip |
|
525 | 525 | ); |
526 | 526 | |
527 | 527 | return Html::rawElement( |
528 | 528 | 'span', |
529 | 529 | [], |
530 | - sprintf( '%s %s', $content, $tooltipIndicator ) |
|
530 | + sprintf('%s %s', $content, $tooltipIndicator) |
|
531 | 531 | ); |
532 | 532 | } |
533 | 533 | |
@@ -543,15 +543,15 @@ discard block |
||
543 | 543 | * |
544 | 544 | * @return string HTML |
545 | 545 | */ |
546 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
547 | - if ( !is_string( $content ) ) { |
|
548 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
546 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
547 | + if (!is_string($content)) { |
|
548 | + throw new InvalidArgumentException('$content has to be string.'); |
|
549 | 549 | } |
550 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
551 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
550 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
551 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
552 | 552 | } |
553 | 553 | |
554 | - if ( empty( $expandableContent ) ) { |
|
554 | + if (empty($expandableContent)) { |
|
555 | 555 | return $content; |
556 | 556 | } |
557 | 557 | |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | ); |
573 | 573 | |
574 | 574 | return |
575 | - sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent ); |
|
575 | + sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | /** |
@@ -584,16 +584,16 @@ discard block |
||
584 | 584 | * |
585 | 585 | * @return string HTML |
586 | 586 | */ |
587 | - private function formatStatus( $status ) { |
|
588 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
587 | + private function formatStatus($status) { |
|
588 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
589 | 589 | |
590 | 590 | $formattedStatus = |
591 | 591 | Html::element( |
592 | 592 | 'span', |
593 | 593 | [ |
594 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
594 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
595 | 595 | ], |
596 | - $this->msg( $messageName )->text() |
|
596 | + $this->msg($messageName)->text() |
|
597 | 597 | ); |
598 | 598 | |
599 | 599 | return $formattedStatus; |
@@ -609,26 +609,26 @@ discard block |
||
609 | 609 | * |
610 | 610 | * @return string HTML |
611 | 611 | */ |
612 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
613 | - if ( $dataValues instanceof DataValue ) { |
|
614 | - $dataValues = [ $dataValues ]; |
|
615 | - } elseif ( !is_array( $dataValues ) ) { |
|
616 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
612 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
613 | + if ($dataValues instanceof DataValue) { |
|
614 | + $dataValues = [$dataValues]; |
|
615 | + } elseif (!is_array($dataValues)) { |
|
616 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | $formattedDataValues = []; |
620 | - foreach ( $dataValues as $dataValue ) { |
|
621 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
622 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
620 | + foreach ($dataValues as $dataValue) { |
|
621 | + if (!($dataValue instanceof DataValue)) { |
|
622 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
623 | 623 | } |
624 | - if ( $dataValue instanceof EntityIdValue ) { |
|
625 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
624 | + if ($dataValue instanceof EntityIdValue) { |
|
625 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
626 | 626 | } else { |
627 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
627 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
628 | 628 | } |
629 | 629 | } |
630 | 630 | |
631 | - return implode( $separator, $formattedDataValues ); |
|
631 | + return implode($separator, $formattedDataValues); |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | /** |
@@ -640,12 +640,12 @@ discard block |
||
640 | 640 | * |
641 | 641 | * @return string HTML |
642 | 642 | */ |
643 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
643 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
644 | 644 | return |
645 | 645 | Html::rawElement( |
646 | 646 | 'a', |
647 | 647 | [ |
648 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
648 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
649 | 649 | 'target' => '_blank' |
650 | 650 | ], |
651 | 651 | $text |
@@ -660,9 +660,9 @@ discard block |
||
660 | 660 | * |
661 | 661 | * @return string |
662 | 662 | */ |
663 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
664 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
665 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
663 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
664 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
665 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
666 | 666 | |
667 | 667 | return $entityUrl; |
668 | 668 | } |
@@ -14,6 +14,6 @@ |
||
14 | 14 | * |
15 | 15 | * @return Constraint[] |
16 | 16 | */ |
17 | - public function queryConstraintsForProperty( PropertyId $propertyId ); |
|
17 | + public function queryConstraintsForProperty(PropertyId $propertyId); |
|
18 | 18 | |
19 | 19 | } |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | |
27 | 27 | const BATCH_SIZE = 10; |
28 | 28 | |
29 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
30 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
29 | + public static function newFromGlobalState(Title $title, array $params) { |
|
30 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
31 | 31 | $repo = WikibaseRepo::getDefaultInstance(); |
32 | 32 | return new UpdateConstraintsTableJob( |
33 | 33 | $title, |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | EntityLookup $entityLookup, |
84 | 84 | Serializer $snakSerializer |
85 | 85 | ) { |
86 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
86 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
87 | 87 | |
88 | 88 | $this->propertyId = $propertyId; |
89 | 89 | $this->config = $config; |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | $this->snakSerializer = $snakSerializer; |
93 | 93 | } |
94 | 94 | |
95 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
95 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
96 | 96 | $parameters = []; |
97 | - foreach ( $qualifiers as $qualifier ) { |
|
97 | + foreach ($qualifiers as $qualifier) { |
|
98 | 98 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
99 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
99 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
100 | 100 | $parameters[$qualifierId][] = $paramSerialization; |
101 | 101 | } |
102 | 102 | return $parameters; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | ) { |
109 | 109 | $constraintId = $constraintStatement->getGuid(); |
110 | 110 | $constraintTypeQid = $constraintStatement->getMainSnak()->getDataValue()->getEntityId()->getSerialization(); |
111 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
111 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
112 | 112 | return new Constraint( |
113 | 113 | $constraintId, |
114 | 114 | $propertyId, |
@@ -122,16 +122,16 @@ discard block |
||
122 | 122 | ConstraintRepository $constraintRepo, |
123 | 123 | PropertyId $propertyConstraintPropertyId |
124 | 124 | ) { |
125 | - $constraintsStatements = $property->getStatements()->getByPropertyId( $propertyConstraintPropertyId ); |
|
125 | + $constraintsStatements = $property->getStatements()->getByPropertyId($propertyConstraintPropertyId); |
|
126 | 126 | $constraints = []; |
127 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
128 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
129 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
130 | - $constraintRepo->insertBatch( $constraints ); |
|
127 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
128 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
129 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
130 | + $constraintRepo->insertBatch($constraints); |
|
131 | 131 | $constraints = []; |
132 | 132 | } |
133 | 133 | } |
134 | - $constraintRepo->insertBatch( $constraints ); |
|
134 | + $constraintRepo->insertBatch($constraints); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | public function run() { |
143 | 143 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
144 | 144 | |
145 | - $propertyId = new PropertyId( $this->propertyId ); |
|
146 | - $this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId( $propertyId ); |
|
145 | + $propertyId = new PropertyId($this->propertyId); |
|
146 | + $this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId($propertyId); |
|
147 | 147 | |
148 | - $property = $this->entityLookup->getEntity( $propertyId ); |
|
148 | + $property = $this->entityLookup->getEntity($propertyId); |
|
149 | 149 | $this->importConstraintsForProperty( |
150 | 150 | $property, |
151 | 151 | $this->constraintRepo, |
152 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
152 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
153 | 153 | ); |
154 | 154 | |
155 | 155 | return true; |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return Constraint[] |
22 | 22 | */ |
23 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
24 | - $db = wfGetDB( DB_REPLICA ); |
|
23 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
24 | + $db = wfGetDB(DB_REPLICA); |
|
25 | 25 | |
26 | 26 | $results = $db->select( |
27 | 27 | 'wbqc_constraints', |
28 | 28 | '*', |
29 | - [ 'pid' => $propertyId->getNumericId() ] |
|
29 | + ['pid' => $propertyId->getNumericId()] |
|
30 | 30 | ); |
31 | 31 | |
32 | - return $this->convertToConstraints( $results ); |
|
32 | + return $this->convertToConstraints($results); |
|
33 | 33 | } |
34 | 34 | |
35 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
36 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
35 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
36 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
37 | 37 | |
38 | - if ( strlen( $json ) > 50000 ) { |
|
39 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
38 | + if (strlen($json) > 50000) { |
|
39 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | return $json; |
@@ -48,21 +48,21 @@ discard block |
||
48 | 48 | * @throws DBUnexpectedError |
49 | 49 | * @return bool |
50 | 50 | */ |
51 | - public function insertBatch( array $constraints ) { |
|
51 | + public function insertBatch(array $constraints) { |
|
52 | 52 | $accumulator = array_map( |
53 | - function ( Constraint $constraint ) { |
|
53 | + function(Constraint $constraint) { |
|
54 | 54 | return [ |
55 | 55 | 'constraint_guid' => $constraint->getConstraintId(), |
56 | 56 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
57 | 57 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
58 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
58 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
59 | 59 | ]; |
60 | 60 | }, |
61 | 61 | $constraints |
62 | 62 | ); |
63 | 63 | |
64 | - $db = wfGetDB( DB_MASTER ); |
|
65 | - return $db->insert( 'wbqc_constraints', $accumulator ); |
|
64 | + $db = wfGetDB(DB_MASTER); |
|
65 | + return $db->insert('wbqc_constraints', $accumulator); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return array |
72 | 72 | */ |
73 | - private function uuidPattern( LikeMatch $any ) { |
|
73 | + private function uuidPattern(LikeMatch $any) { |
|
74 | 74 | return array_merge( |
75 | - array_fill( 0, 8, $any ), [ '-' ], |
|
76 | - array_fill( 0, 4, $any ), [ '-' ], |
|
77 | - array_fill( 0, 4, $any ), [ '-' ], |
|
78 | - array_fill( 0, 4, $any ), [ '-' ], |
|
79 | - array_fill( 0, 12, $any ) |
|
75 | + array_fill(0, 8, $any), ['-'], |
|
76 | + array_fill(0, 4, $any), ['-'], |
|
77 | + array_fill(0, 4, $any), ['-'], |
|
78 | + array_fill(0, 4, $any), ['-'], |
|
79 | + array_fill(0, 12, $any) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | * @throws DBUnexpectedError |
88 | 88 | */ |
89 | 89 | public function deleteWhereConstraintIdIsUuid() { |
90 | - $db = wfGetDB( DB_MASTER ); |
|
90 | + $db = wfGetDB(DB_MASTER); |
|
91 | 91 | $db->delete( |
92 | 92 | 'wbqc_constraints', |
93 | 93 | // WHERE constraint_guid LIKE ________-____-____-____-____________ |
94 | - 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) |
|
94 | + 'constraint_guid '.$db->buildLike($this->uuidPattern($db->anyChar())) |
|
95 | 95 | ); |
96 | 96 | } |
97 | 97 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @throws DBUnexpectedError |
103 | 103 | */ |
104 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
105 | - $db = wfGetDB( DB_MASTER ); |
|
104 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
105 | + $db = wfGetDB(DB_MASTER); |
|
106 | 106 | $db->delete( |
107 | 107 | 'wbqc_constraints', |
108 | 108 | [ |
109 | 109 | 'pid' => $propertyId->getNumericId(), |
110 | 110 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
111 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
111 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
112 | 112 | ] |
113 | 113 | ); |
114 | 114 | } |
@@ -119,20 +119,20 @@ discard block |
||
119 | 119 | * @throws InvalidArgumentException |
120 | 120 | * @throws DBUnexpectedError |
121 | 121 | */ |
122 | - public function deleteAll( $batchSize = 1000 ) { |
|
123 | - if ( !is_int( $batchSize ) ) { |
|
122 | + public function deleteAll($batchSize = 1000) { |
|
123 | + if (!is_int($batchSize)) { |
|
124 | 124 | throw new InvalidArgumentException(); |
125 | 125 | } |
126 | - $db = wfGetDB( DB_MASTER ); |
|
127 | - if ( $db->getType() === 'sqlite' ) { |
|
128 | - $db->delete( 'wbqc_constraints', '*' ); |
|
126 | + $db = wfGetDB(DB_MASTER); |
|
127 | + if ($db->getType() === 'sqlite') { |
|
128 | + $db->delete('wbqc_constraints', '*'); |
|
129 | 129 | } else { |
130 | 130 | do { |
131 | - $db->commit( __METHOD__, 'flush' ); |
|
131 | + $db->commit(__METHOD__, 'flush'); |
|
132 | 132 | wfGetLBFactory()->waitForReplication(); |
133 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
134 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
135 | - } while ( $db->affectedRows() > 0 ); |
|
133 | + $table = $db->tableName('wbqc_constraints'); |
|
134 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
135 | + } while ($db->affectedRows() > 0); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -141,26 +141,26 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return Constraint[] |
143 | 143 | */ |
144 | - private function convertToConstraints( ResultWrapper $results ) { |
|
144 | + private function convertToConstraints(ResultWrapper $results) { |
|
145 | 145 | $constraints = []; |
146 | - foreach ( $results as $result ) { |
|
146 | + foreach ($results as $result) { |
|
147 | 147 | $constraintTypeItemId = $result->constraint_type_qid; |
148 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
148 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
149 | 149 | |
150 | - if ( $constraintParameters === null ) { |
|
150 | + if ($constraintParameters === null) { |
|
151 | 151 | // T171295 |
152 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
153 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
152 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
153 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
154 | 154 | 'method' => __METHOD__, |
155 | 155 | 'constraintId' => $result->constraint_guid, |
156 | 156 | 'constraintParameters' => $result->constraint_parameters, |
157 | - ] ); |
|
158 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
157 | + ]); |
|
158 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | $constraints[] = new Constraint( |
162 | 162 | $result->constraint_guid, |
163 | - PropertyId::newFromNumber( $result->pid ), |
|
163 | + PropertyId::newFromNumber($result->pid), |
|
164 | 164 | $constraintTypeItemId, |
165 | 165 | $constraintParameters |
166 | 166 | ); |