@@ -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 | ]; |
@@ -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 | } |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | return []; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
| 194 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
| 193 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
| 194 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
| 195 | 195 | return [ |
| 196 | 196 | Context::TYPE_STATEMENT, |
| 197 | 197 | Context::TYPE_QUALIFIER, |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | ]; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - return array_keys( array_filter( |
|
| 202 | + return array_keys(array_filter( |
|
| 203 | 203 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
| 204 | - function ( $resultStatus ) { |
|
| 204 | + function($resultStatus) { |
|
| 205 | 205 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
| 206 | 206 | } |
| 207 | - ) ); |
|
| 207 | + )); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -215,32 +215,32 @@ discard block |
||
| 215 | 215 | * |
| 216 | 216 | * @return ConstraintParameterException[] |
| 217 | 217 | */ |
| 218 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
| 218 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
| 219 | 219 | $constraintParameters = $constraint->getConstraintParameters(); |
| 220 | 220 | try { |
| 221 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
| 222 | - } catch ( ConstraintParameterException $e ) { |
|
| 223 | - return [ $e ]; |
|
| 221 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
| 222 | + } catch (ConstraintParameterException $e) { |
|
| 223 | + return [$e]; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | $problems = []; |
| 227 | 227 | try { |
| 228 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
| 229 | - } catch ( ConstraintParameterException $e ) { |
|
| 228 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
| 229 | + } catch (ConstraintParameterException $e) { |
|
| 230 | 230 | $problems[] = $e; |
| 231 | 231 | } |
| 232 | 232 | try { |
| 233 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
| 234 | - } catch ( ConstraintParameterException $e ) { |
|
| 233 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
| 234 | + } catch (ConstraintParameterException $e) { |
|
| 235 | 235 | $problems[] = $e; |
| 236 | 236 | } |
| 237 | 237 | try { |
| 238 | 238 | $this->constraintParameterParser->parseConstraintScopeParameter( |
| 239 | 239 | $constraintParameters, |
| 240 | 240 | $constraint->getConstraintTypeItemId(), |
| 241 | - $this->getAllowedContextTypes( $constraint ) |
|
| 241 | + $this->getAllowedContextTypes($constraint) |
|
| 242 | 242 | ); |
| 243 | - } catch ( ConstraintParameterException $e ) { |
|
| 243 | + } catch (ConstraintParameterException $e) { |
|
| 244 | 244 | $problems[] = $e; |
| 245 | 245 | } |
| 246 | 246 | return $problems; |
@@ -253,16 +253,16 @@ discard block |
||
| 253 | 253 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
| 254 | 254 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
| 255 | 255 | */ |
| 256 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
| 257 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
| 256 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
| 257 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
| 258 | 258 | $result = []; |
| 259 | 259 | |
| 260 | - foreach ( $constraints as $constraint ) { |
|
| 261 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
| 260 | + foreach ($constraints as $constraint) { |
|
| 261 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
| 262 | 262 | |
| 263 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
| 263 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
| 264 | 264 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
| 265 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
| 265 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | $result[$constraint->getConstraintId()] = $problems; |
@@ -279,17 +279,17 @@ discard block |
||
| 279 | 279 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
| 280 | 280 | * (empty means all parameters okay), or null if constraint is not found |
| 281 | 281 | */ |
| 282 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
| 283 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 284 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
| 282 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
| 283 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 284 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
| 285 | 285 | |
| 286 | - foreach ( $constraints as $constraint ) { |
|
| 287 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
| 288 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
| 286 | + foreach ($constraints as $constraint) { |
|
| 287 | + if ($constraint->getConstraintId() === $constraintId) { |
|
| 288 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
| 289 | 289 | |
| 290 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
| 290 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
| 291 | 291 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
| 292 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
| 292 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | return $problems; |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | $result = []; |
| 315 | 315 | |
| 316 | 316 | /** @var Statement $statement */ |
| 317 | - foreach ( $entity->getStatements() as $statement ) { |
|
| 318 | - $result = array_merge( $result, |
|
| 317 | + foreach ($entity->getStatements() as $statement) { |
|
| 318 | + $result = array_merge($result, |
|
| 319 | 319 | $this->checkStatement( |
| 320 | 320 | $entity, |
| 321 | 321 | $statement, |
| 322 | 322 | $constraintIds, |
| 323 | 323 | $defaultResults |
| 324 | - ) ); |
|
| 324 | + )); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | return $result; |
@@ -343,32 +343,32 @@ discard block |
||
| 343 | 343 | ) { |
| 344 | 344 | $result = []; |
| 345 | 345 | |
| 346 | - $result = array_merge( $result, |
|
| 346 | + $result = array_merge($result, |
|
| 347 | 347 | $this->checkConstraintsForMainSnak( |
| 348 | 348 | $entity, |
| 349 | 349 | $statement, |
| 350 | 350 | $constraintIds, |
| 351 | 351 | $defaultResults |
| 352 | - ) ); |
|
| 352 | + )); |
|
| 353 | 353 | |
| 354 | - if ( $this->checkQualifiers ) { |
|
| 355 | - $result = array_merge( $result, |
|
| 354 | + if ($this->checkQualifiers) { |
|
| 355 | + $result = array_merge($result, |
|
| 356 | 356 | $this->checkConstraintsForQualifiers( |
| 357 | 357 | $entity, |
| 358 | 358 | $statement, |
| 359 | 359 | $constraintIds, |
| 360 | 360 | $defaultResults |
| 361 | - ) ); |
|
| 361 | + )); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - if ( $this->checkReferences ) { |
|
| 365 | - $result = array_merge( $result, |
|
| 364 | + if ($this->checkReferences) { |
|
| 365 | + $result = array_merge($result, |
|
| 366 | 366 | $this->checkConstraintsForReferences( |
| 367 | 367 | $entity, |
| 368 | 368 | $statement, |
| 369 | 369 | $constraintIds, |
| 370 | 370 | $defaultResults |
| 371 | - ) ); |
|
| 371 | + )); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | return $result; |
@@ -383,12 +383,12 @@ discard block |
||
| 383 | 383 | * @param string[]|null $constraintIds |
| 384 | 384 | * @return Constraint[] |
| 385 | 385 | */ |
| 386 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
| 387 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
| 388 | - if ( $constraintIds !== null ) { |
|
| 386 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
| 387 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
| 388 | + if ($constraintIds !== null) { |
|
| 389 | 389 | $constraintsToUse = []; |
| 390 | - foreach ( $constraints as $constraint ) { |
|
| 391 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
| 390 | + foreach ($constraints as $constraint) { |
|
| 391 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
| 392 | 392 | $constraintsToUse[] = $constraint; |
| 393 | 393 | } |
| 394 | 394 | } |
@@ -412,29 +412,29 @@ discard block |
||
| 412 | 412 | array $constraintIds = null, |
| 413 | 413 | callable $defaultResults = null |
| 414 | 414 | ) { |
| 415 | - $context = new MainSnakContext( $entity, $statement ); |
|
| 415 | + $context = new MainSnakContext($entity, $statement); |
|
| 416 | 416 | $constraints = $this->getConstraintsToUse( |
| 417 | 417 | $statement->getPropertyId(), |
| 418 | 418 | $constraintIds |
| 419 | 419 | ); |
| 420 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
| 420 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
| 421 | 421 | |
| 422 | - foreach ( $constraints as $constraint ) { |
|
| 422 | + foreach ($constraints as $constraint) { |
|
| 423 | 423 | $parameters = $constraint->getConstraintParameters(); |
| 424 | 424 | try { |
| 425 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
| 426 | - } catch ( ConstraintParameterException $e ) { |
|
| 427 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
| 425 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
| 426 | + } catch (ConstraintParameterException $e) { |
|
| 427 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
| 428 | 428 | continue; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
| 432 | - $message = wfMessage( 'wbqc-exception-message' )->escaped(); |
|
| 433 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
| 431 | + if (in_array($entity->getId(), $exceptions)) { |
|
| 432 | + $message = wfMessage('wbqc-exception-message')->escaped(); |
|
| 433 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
| 434 | 434 | continue; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
| 437 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | return $result; |
@@ -456,24 +456,24 @@ discard block |
||
| 456 | 456 | ) { |
| 457 | 457 | $result = []; |
| 458 | 458 | |
| 459 | - if ( in_array( |
|
| 459 | + if (in_array( |
|
| 460 | 460 | $statement->getPropertyId()->getSerialization(), |
| 461 | 461 | $this->propertiesWithViolatingQualifiers |
| 462 | - ) ) { |
|
| 462 | + )) { |
|
| 463 | 463 | return $result; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
| 467 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
| 468 | - if ( $defaultResults !== null ) { |
|
| 469 | - $result = array_merge( $result, $defaultResults( $qualifierContext ) ); |
|
| 466 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
| 467 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
| 468 | + if ($defaultResults !== null) { |
|
| 469 | + $result = array_merge($result, $defaultResults($qualifierContext)); |
|
| 470 | 470 | } |
| 471 | 471 | $qualifierConstraints = $this->getConstraintsToUse( |
| 472 | 472 | $qualifierContext->getSnak()->getPropertyId(), |
| 473 | 473 | $constraintIds |
| 474 | 474 | ); |
| 475 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
| 476 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
| 475 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
| 476 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | |
@@ -497,19 +497,19 @@ discard block |
||
| 497 | 497 | $result = []; |
| 498 | 498 | |
| 499 | 499 | /** @var Reference $reference */ |
| 500 | - foreach ( $statement->getReferences() as $reference ) { |
|
| 501 | - foreach ( $reference->getSnaks() as $snak ) { |
|
| 500 | + foreach ($statement->getReferences() as $reference) { |
|
| 501 | + foreach ($reference->getSnaks() as $snak) { |
|
| 502 | 502 | $referenceContext = new ReferenceContext( |
| 503 | 503 | $entity, $statement, $reference, $snak |
| 504 | 504 | ); |
| 505 | - if ( $defaultResults !== null ) { |
|
| 506 | - $result = array_merge( $result, $defaultResults( $referenceContext ) ); |
|
| 505 | + if ($defaultResults !== null) { |
|
| 506 | + $result = array_merge($result, $defaultResults($referenceContext)); |
|
| 507 | 507 | } |
| 508 | 508 | $referenceConstraints = $this->getConstraintsToUse( |
| 509 | 509 | $referenceContext->getSnak()->getPropertyId(), |
| 510 | 510 | $constraintIds |
| 511 | 511 | ); |
| 512 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
| 512 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
| 513 | 513 | $result[] = $this->getCheckResultFor( |
| 514 | 514 | $referenceContext, |
| 515 | 515 | $referenceConstraint |
@@ -528,65 +528,65 @@ discard block |
||
| 528 | 528 | * @throws InvalidArgumentException |
| 529 | 529 | * @return CheckResult |
| 530 | 530 | */ |
| 531 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
| 532 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
| 531 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
| 532 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
| 533 | 533 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
| 534 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
| 534 | + $result = $this->handleScope($checker, $context, $constraint); |
|
| 535 | 535 | |
| 536 | - if ( $result !== null ) { |
|
| 537 | - $this->addMetadata( $result ); |
|
| 536 | + if ($result !== null) { |
|
| 537 | + $this->addMetadata($result); |
|
| 538 | 538 | return $result; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - $startTime = microtime( true ); |
|
| 541 | + $startTime = microtime(true); |
|
| 542 | 542 | try { |
| 543 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
| 544 | - } catch ( ConstraintParameterException $e ) { |
|
| 545 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
| 546 | - } catch ( SparqlHelperException $e ) { |
|
| 547 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
| 548 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
| 543 | + $result = $checker->checkConstraint($context, $constraint); |
|
| 544 | + } catch (ConstraintParameterException $e) { |
|
| 545 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
| 546 | + } catch (SparqlHelperException $e) { |
|
| 547 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
| 548 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
| 549 | 549 | } |
| 550 | - $endTime = microtime( true ); |
|
| 550 | + $endTime = microtime(true); |
|
| 551 | 551 | |
| 552 | - $this->addMetadata( $result ); |
|
| 552 | + $this->addMetadata($result); |
|
| 553 | 553 | |
| 554 | 554 | try { |
| 555 | 555 | $constraintStatus = $this->constraintParameterParser |
| 556 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
| 557 | - } catch ( ConstraintParameterException $e ) { |
|
| 558 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
| 556 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
| 557 | + } catch (ConstraintParameterException $e) { |
|
| 558 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
| 559 | 559 | $constraintStatus = null; |
| 560 | 560 | } |
| 561 | - if ( $constraintStatus === null ) { |
|
| 561 | + if ($constraintStatus === null) { |
|
| 562 | 562 | // downgrade violation to warning |
| 563 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
| 564 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
| 563 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
| 564 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
| 565 | 565 | } |
| 566 | 566 | } else { |
| 567 | - if ( $constraintStatus !== 'mandatory' ) { |
|
| 567 | + if ($constraintStatus !== 'mandatory') { |
|
| 568 | 568 | // @codeCoverageIgnoreStart |
| 569 | 569 | throw new LogicException( |
| 570 | - "Unknown constraint status '$constraintStatus', " . |
|
| 570 | + "Unknown constraint status '$constraintStatus', ". |
|
| 571 | 571 | "only known status is 'mandatory'" |
| 572 | 572 | ); |
| 573 | 573 | // @codeCoverageIgnoreEnd |
| 574 | 574 | } |
| 575 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
| 575 | + $result->addParameter('constraint_status', $constraintStatus); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | $this->loggingHelper->logConstraintCheck( |
| 579 | 579 | $context, |
| 580 | 580 | $constraint, |
| 581 | 581 | $result, |
| 582 | - get_class( $checker ), |
|
| 582 | + get_class($checker), |
|
| 583 | 583 | $endTime - $startTime, |
| 584 | 584 | __METHOD__ |
| 585 | 585 | ); |
| 586 | 586 | |
| 587 | 587 | return $result; |
| 588 | 588 | } else { |
| 589 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
| 589 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
| 590 | 590 | } |
| 591 | 591 | } |
| 592 | 592 | |
@@ -600,29 +600,29 @@ discard block |
||
| 600 | 600 | $constraint->getConstraintParameters(), |
| 601 | 601 | $constraint->getConstraintTypeItemId() |
| 602 | 602 | ); |
| 603 | - } catch ( ConstraintParameterException $e ) { |
|
| 604 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
| 603 | + } catch (ConstraintParameterException $e) { |
|
| 604 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
| 605 | 605 | } |
| 606 | - if ( $checkedContextTypes === null ) { |
|
| 606 | + if ($checkedContextTypes === null) { |
|
| 607 | 607 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
| 608 | 608 | } |
| 609 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
| 610 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
| 609 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
| 610 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
| 611 | 611 | } |
| 612 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
| 613 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
| 612 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
| 613 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
| 614 | 614 | } |
| 615 | 615 | return null; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - private function addMetadata( CheckResult $result ) { |
|
| 619 | - $result->withMetadata( Metadata::merge( [ |
|
| 618 | + private function addMetadata(CheckResult $result) { |
|
| 619 | + $result->withMetadata(Metadata::merge([ |
|
| 620 | 620 | $result->getMetadata(), |
| 621 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
| 622 | - DependencyMetadata::ofEntityId( $result->getEntityId() ), |
|
| 623 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
| 624 | - ] ) ), |
|
| 625 | - ] ) ); |
|
| 621 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
| 622 | + DependencyMetadata::ofEntityId($result->getEntityId()), |
|
| 623 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
| 624 | + ])), |
|
| 625 | + ])); |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | /** |
@@ -630,12 +630,12 @@ discard block |
||
| 630 | 630 | * |
| 631 | 631 | * @return CheckResult[] |
| 632 | 632 | */ |
| 633 | - private function sortResult( array $result ) { |
|
| 634 | - if ( count( $result ) < 2 ) { |
|
| 633 | + private function sortResult(array $result) { |
|
| 634 | + if (count($result) < 2) { |
|
| 635 | 635 | return $result; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
| 638 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
| 639 | 639 | $orderNum = 0; |
| 640 | 640 | $order = [ |
| 641 | 641 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -651,45 +651,45 @@ discard block |
||
| 651 | 651 | $statusA = $a->getStatus(); |
| 652 | 652 | $statusB = $b->getStatus(); |
| 653 | 653 | |
| 654 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
| 655 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
| 654 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
| 655 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
| 656 | 656 | |
| 657 | - if ( $orderA === $orderB ) { |
|
| 657 | + if ($orderA === $orderB) { |
|
| 658 | 658 | $pidA = $a->getContext()->getSnak()->getPropertyId()->getSerialization(); |
| 659 | 659 | $pidB = $b->getContext()->getSnak()->getPropertyId()->getSerialization(); |
| 660 | 660 | |
| 661 | - if ( $pidA === $pidB ) { |
|
| 661 | + if ($pidA === $pidB) { |
|
| 662 | 662 | $hashA = $a->getContext()->getSnak()->getHash(); |
| 663 | 663 | $hashB = $b->getContext()->getSnak()->getHash(); |
| 664 | 664 | |
| 665 | - if ( $hashA === $hashB ) { |
|
| 666 | - if ( $a instanceof NullResult ) { |
|
| 665 | + if ($hashA === $hashB) { |
|
| 666 | + if ($a instanceof NullResult) { |
|
| 667 | 667 | return $b instanceof NullResult ? 0 : -1; |
| 668 | 668 | } |
| 669 | - if ( $b instanceof NullResult ) { |
|
| 669 | + if ($b instanceof NullResult) { |
|
| 670 | 670 | return $a instanceof NullResult ? 0 : 1; |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
| 674 | 674 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
| 675 | 675 | |
| 676 | - if ( $typeA == $typeB ) { |
|
| 676 | + if ($typeA == $typeB) { |
|
| 677 | 677 | return 0; |
| 678 | 678 | } else { |
| 679 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
| 679 | + return ($typeA > $typeB) ? 1 : -1; |
|
| 680 | 680 | } |
| 681 | 681 | } else { |
| 682 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
| 682 | + return ($hashA > $hashB) ? 1 : -1; |
|
| 683 | 683 | } |
| 684 | 684 | } else { |
| 685 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
| 685 | + return ($pidA > $pidB) ? 1 : -1; |
|
| 686 | 686 | } |
| 687 | 687 | } else { |
| 688 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
| 688 | + return ($orderA > $orderB) ? 1 : -1; |
|
| 689 | 689 | } |
| 690 | 690 | }; |
| 691 | 691 | |
| 692 | - uasort( $result, $sortFunction ); |
|
| 692 | + uasort($result, $sortFunction); |
|
| 693 | 693 | |
| 694 | 694 | return $result; |
| 695 | 695 | } |
@@ -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' ]; |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | Config $config, |
| 134 | 134 | IBufferingStatsdDataFactory $dataFactory |
| 135 | 135 | ) { |
| 136 | - parent::__construct( 'ConstraintReport' ); |
|
| 136 | + parent::__construct('ConstraintReport'); |
|
| 137 | 137 | |
| 138 | 138 | $this->entityLookup = $entityLookup; |
| 139 | 139 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | $language = $this->getLanguage(); |
| 143 | 143 | |
| 144 | 144 | $formatterOptions = new FormatterOptions(); |
| 145 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
| 145 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
| 146 | 146 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
| 147 | 147 | SnakFormatter::FORMAT_HTML, |
| 148 | 148 | $formatterOptions |
| 149 | 149 | ); |
| 150 | 150 | |
| 151 | - $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup( $language ); |
|
| 151 | + $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup($language); |
|
| 152 | 152 | |
| 153 | 153 | $this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( |
| 154 | 154 | $labelLookup |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @return array |
| 178 | 178 | */ |
| 179 | 179 | private function getModules() { |
| 180 | - return [ 'SpecialConstraintReportPage' ]; |
|
| 180 | + return ['SpecialConstraintReportPage']; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | 197 | public function getDescription() { |
| 198 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
| 198 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -207,42 +207,42 @@ discard block |
||
| 207 | 207 | * @throws EntityIdParsingException |
| 208 | 208 | * @throws UnexpectedValueException |
| 209 | 209 | */ |
| 210 | - public function execute( $subPage ) { |
|
| 210 | + public function execute($subPage) { |
|
| 211 | 211 | $out = $this->getOutput(); |
| 212 | 212 | |
| 213 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
| 214 | - if ( $postRequest ) { |
|
| 215 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
| 213 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
| 214 | + if ($postRequest) { |
|
| 215 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - $out->addModules( $this->getModules() ); |
|
| 219 | + $out->addModules($this->getModules()); |
|
| 220 | 220 | |
| 221 | 221 | $this->setHeaders(); |
| 222 | 222 | |
| 223 | - $out->addHTML( $this->getExplanationText() ); |
|
| 223 | + $out->addHTML($this->getExplanationText()); |
|
| 224 | 224 | $this->buildEntityIdForm(); |
| 225 | 225 | |
| 226 | - if ( !$subPage ) { |
|
| 226 | + if (!$subPage) { |
|
| 227 | 227 | return; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( !is_string( $subPage ) ) { |
|
| 231 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
| 230 | + if (!is_string($subPage)) { |
|
| 231 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | try { |
| 235 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
| 236 | - } catch ( EntityIdParsingException $e ) { |
|
| 235 | + $entityId = $this->entityIdParser->parse($subPage); |
|
| 236 | + } catch (EntityIdParsingException $e) { |
|
| 237 | 237 | $out->addHTML( |
| 238 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
| 238 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
| 239 | 239 | ); |
| 240 | 240 | return; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
| 243 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
| 244 | 244 | $out->addHTML( |
| 245 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
| 245 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
| 246 | 246 | ); |
| 247 | 247 | return; |
| 248 | 248 | } |
@@ -250,18 +250,18 @@ discard block |
||
| 250 | 250 | $this->dataFactory->increment( |
| 251 | 251 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
| 252 | 252 | ); |
| 253 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
| 253 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
| 254 | 254 | |
| 255 | - if ( count( $results ) > 0 ) { |
|
| 255 | + if (count($results) > 0) { |
|
| 256 | 256 | $out->addHTML( |
| 257 | - $this->buildResultHeader( $entityId ) |
|
| 258 | - . $this->buildSummary( $results ) |
|
| 259 | - . $this->buildResultTable( $entityId, $results ) |
|
| 257 | + $this->buildResultHeader($entityId) |
|
| 258 | + . $this->buildSummary($results) |
|
| 259 | + . $this->buildResultTable($entityId, $results) |
|
| 260 | 260 | ); |
| 261 | 261 | } else { |
| 262 | 262 | $out->addHTML( |
| 263 | - $this->buildResultHeader( $entityId ) |
|
| 264 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
| 263 | + $this->buildResultHeader($entityId) |
|
| 264 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
| 265 | 265 | ); |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -277,15 +277,15 @@ discard block |
||
| 277 | 277 | 'name' => 'entityid', |
| 278 | 278 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
| 279 | 279 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
| 280 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
| 280 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
| 281 | 281 | ] |
| 282 | 282 | ]; |
| 283 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
| 284 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
| 285 | - $htmlForm->setSubmitCallback( function() { |
|
| 283 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
| 284 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
| 285 | + $htmlForm->setSubmitCallback(function() { |
|
| 286 | 286 | return false; |
| 287 | 287 | } ); |
| 288 | - $htmlForm->setMethod( 'post' ); |
|
| 288 | + $htmlForm->setMethod('post'); |
|
| 289 | 289 | $htmlForm->show(); |
| 290 | 290 | } |
| 291 | 291 | |
@@ -299,16 +299,16 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @return string HTML |
| 301 | 301 | */ |
| 302 | - private function buildNotice( $messageKey, $error = false ) { |
|
| 303 | - if ( !is_string( $messageKey ) ) { |
|
| 304 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
| 302 | + private function buildNotice($messageKey, $error = false) { |
|
| 303 | + if (!is_string($messageKey)) { |
|
| 304 | + throw new InvalidArgumentException('$message must be string.'); |
|
| 305 | 305 | } |
| 306 | - if ( !is_bool( $error ) ) { |
|
| 307 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
| 306 | + if (!is_bool($error)) { |
|
| 307 | + throw new InvalidArgumentException('$error must be bool.'); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | $cssClasses = 'wbqc-constraintreport-notice'; |
| 311 | - if ( $error ) { |
|
| 311 | + if ($error) { |
|
| 312 | 312 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
| 313 | 313 | } |
| 314 | 314 | |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | [ |
| 318 | 318 | 'class' => $cssClasses |
| 319 | 319 | ], |
| 320 | - $this->msg( $messageKey )->escaped() |
|
| 320 | + $this->msg($messageKey)->escaped() |
|
| 321 | 321 | ); |
| 322 | 322 | } |
| 323 | 323 | |
@@ -327,16 +327,16 @@ discard block |
||
| 327 | 327 | private function getExplanationText() { |
| 328 | 328 | return Html::rawElement( |
| 329 | 329 | 'div', |
| 330 | - [ 'class' => 'wbqc-explanation' ], |
|
| 330 | + ['class' => 'wbqc-explanation'], |
|
| 331 | 331 | Html::rawElement( |
| 332 | 332 | 'p', |
| 333 | 333 | [], |
| 334 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
| 334 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
| 335 | 335 | ) |
| 336 | 336 | . Html::rawElement( |
| 337 | 337 | 'p', |
| 338 | 338 | [], |
| 339 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
| 339 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
| 340 | 340 | ) |
| 341 | 341 | ); |
| 342 | 342 | } |
@@ -347,71 +347,70 @@ discard block |
||
| 347 | 347 | * |
| 348 | 348 | * @return string HTML |
| 349 | 349 | */ |
| 350 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
| 350 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
| 351 | 351 | // Set table headers |
| 352 | 352 | $table = new HtmlTableBuilder( |
| 353 | 353 | [ |
| 354 | 354 | new HtmlTableHeaderBuilder( |
| 355 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
| 355 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
| 356 | 356 | true |
| 357 | 357 | ), |
| 358 | 358 | new HtmlTableHeaderBuilder( |
| 359 | - $this->msg( 'wbqc-constraintreport-result-table-header-claim' )->escaped(), |
|
| 359 | + $this->msg('wbqc-constraintreport-result-table-header-claim')->escaped(), |
|
| 360 | 360 | true |
| 361 | 361 | ), |
| 362 | 362 | new HtmlTableHeaderBuilder( |
| 363 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
| 363 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
| 364 | 364 | true |
| 365 | 365 | ) |
| 366 | 366 | ] |
| 367 | 367 | ); |
| 368 | 368 | |
| 369 | - foreach ( $results as $result ) { |
|
| 370 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
| 369 | + foreach ($results as $result) { |
|
| 370 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | return $table->toHtml(); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
| 376 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
| 377 | 377 | // Status column |
| 378 | 378 | $statusColumn = $this->buildTooltipElement( |
| 379 | - $this->formatStatus( $result->getStatus() ), |
|
| 379 | + $this->formatStatus($result->getStatus()), |
|
| 380 | 380 | $result->getMessage() !== null ? |
| 381 | - $this->violationMessageRenderer->render( $result->getMessage() ) : |
|
| 382 | - null, |
|
| 381 | + $this->violationMessageRenderer->render($result->getMessage()) : null, |
|
| 383 | 382 | '[?]' |
| 384 | 383 | ); |
| 385 | 384 | |
| 386 | 385 | // Claim column |
| 387 | - $property = $this->entityIdLabelFormatter->formatEntityId( $result->getContext()->getSnak()->getPropertyId() ); |
|
| 388 | - if ( $result->getSnakType() === 'value' ) { |
|
| 389 | - $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()); |
|
| 390 | 389 | } else { |
| 391 | - $value = htmlspecialchars( $result->getSnakType() ); |
|
| 390 | + $value = htmlspecialchars($result->getSnakType()); |
|
| 392 | 391 | } |
| 393 | 392 | |
| 394 | 393 | $claimColumn = $this->getClaimLink( |
| 395 | 394 | $entityId, |
| 396 | 395 | $result->getContext()->getSnak()->getPropertyId(), |
| 397 | - $property . ': ' . $value |
|
| 396 | + $property.': '.$value |
|
| 398 | 397 | ); |
| 399 | 398 | |
| 400 | 399 | // Constraint column |
| 401 | 400 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
| 402 | 401 | try { |
| 403 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
| 404 | - } catch ( InvalidArgumentException $e ) { |
|
| 405 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
| 402 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
| 403 | + } catch (InvalidArgumentException $e) { |
|
| 404 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
| 406 | 405 | } |
| 407 | 406 | $constraintLink = $this->getClaimLink( |
| 408 | 407 | $result->getContext()->getSnak()->getPropertyId(), |
| 409 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
| 408 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
| 410 | 409 | $constraintTypeLabel |
| 411 | 410 | ); |
| 412 | 411 | $constraintColumn = $this->buildExpandableElement( |
| 413 | 412 | $constraintLink, |
| 414 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
| 413 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
| 415 | 414 | '[...]' |
| 416 | 415 | ); |
| 417 | 416 | |
@@ -446,15 +445,15 @@ discard block |
||
| 446 | 445 | * |
| 447 | 446 | * @return string HTML |
| 448 | 447 | */ |
| 449 | - protected function buildResultHeader( EntityId $entityId ) { |
|
| 450 | - $entityLink = sprintf( '%s (%s)', |
|
| 451 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
| 452 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
| 448 | + protected function buildResultHeader(EntityId $entityId) { |
|
| 449 | + $entityLink = sprintf('%s (%s)', |
|
| 450 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
| 451 | + htmlspecialchars($entityId->getSerialization())); |
|
| 453 | 452 | |
| 454 | 453 | return Html::rawElement( |
| 455 | 454 | 'h3', |
| 456 | 455 | [], |
| 457 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
| 456 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
| 458 | 457 | ); |
| 459 | 458 | } |
| 460 | 459 | |
@@ -465,24 +464,24 @@ discard block |
||
| 465 | 464 | * |
| 466 | 465 | * @return string HTML |
| 467 | 466 | */ |
| 468 | - protected function buildSummary( array $results ) { |
|
| 467 | + protected function buildSummary(array $results) { |
|
| 469 | 468 | $statuses = []; |
| 470 | - foreach ( $results as $result ) { |
|
| 471 | - $status = strtolower( $result->getStatus() ); |
|
| 472 | - $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; |
|
| 473 | 472 | } |
| 474 | 473 | |
| 475 | 474 | $statusElements = []; |
| 476 | - foreach ( $statuses as $status => $count ) { |
|
| 477 | - if ( $count > 0 ) { |
|
| 475 | + foreach ($statuses as $status => $count) { |
|
| 476 | + if ($count > 0) { |
|
| 478 | 477 | $statusElements[] = |
| 479 | - $this->formatStatus( $status ) |
|
| 478 | + $this->formatStatus($status) |
|
| 480 | 479 | . ': ' |
| 481 | 480 | . $count; |
| 482 | 481 | } |
| 483 | 482 | } |
| 484 | 483 | |
| 485 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
| 484 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
| 486 | 485 | } |
| 487 | 486 | |
| 488 | 487 | /** |
@@ -497,15 +496,15 @@ discard block |
||
| 497 | 496 | * |
| 498 | 497 | * @return string HTML |
| 499 | 498 | */ |
| 500 | - protected function buildTooltipElement( $content, $tooltipContent, $indicator ) { |
|
| 501 | - if ( !is_string( $content ) ) { |
|
| 502 | - 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.'); |
|
| 503 | 502 | } |
| 504 | - if ( $tooltipContent && ( !is_string( $tooltipContent ) ) ) { |
|
| 505 | - 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.'); |
|
| 506 | 505 | } |
| 507 | 506 | |
| 508 | - if ( empty( $tooltipContent ) ) { |
|
| 507 | + if (empty($tooltipContent)) { |
|
| 509 | 508 | return $content; |
| 510 | 509 | } |
| 511 | 510 | |
@@ -522,13 +521,13 @@ discard block |
||
| 522 | 521 | [ |
| 523 | 522 | 'class' => 'wbqc-indicator' |
| 524 | 523 | ], |
| 525 | - htmlspecialchars( $indicator ) . $tooltip |
|
| 524 | + htmlspecialchars($indicator).$tooltip |
|
| 526 | 525 | ); |
| 527 | 526 | |
| 528 | 527 | return Html::rawElement( |
| 529 | 528 | 'span', |
| 530 | 529 | [], |
| 531 | - sprintf( '%s %s', $content, $tooltipIndicator ) |
|
| 530 | + sprintf('%s %s', $content, $tooltipIndicator) |
|
| 532 | 531 | ); |
| 533 | 532 | } |
| 534 | 533 | |
@@ -544,15 +543,15 @@ discard block |
||
| 544 | 543 | * |
| 545 | 544 | * @return string HTML |
| 546 | 545 | */ |
| 547 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
| 548 | - if ( !is_string( $content ) ) { |
|
| 549 | - 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.'); |
|
| 550 | 549 | } |
| 551 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
| 552 | - 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.'); |
|
| 553 | 552 | } |
| 554 | 553 | |
| 555 | - if ( empty( $expandableContent ) ) { |
|
| 554 | + if (empty($expandableContent)) { |
|
| 556 | 555 | return $content; |
| 557 | 556 | } |
| 558 | 557 | |
@@ -573,7 +572,7 @@ discard block |
||
| 573 | 572 | ); |
| 574 | 573 | |
| 575 | 574 | return |
| 576 | - sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent ); |
|
| 575 | + sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent); |
|
| 577 | 576 | } |
| 578 | 577 | |
| 579 | 578 | /** |
@@ -585,16 +584,16 @@ discard block |
||
| 585 | 584 | * |
| 586 | 585 | * @return string HTML |
| 587 | 586 | */ |
| 588 | - private function formatStatus( $status ) { |
|
| 589 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
| 587 | + private function formatStatus($status) { |
|
| 588 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
| 590 | 589 | |
| 591 | 590 | $formattedStatus = |
| 592 | 591 | Html::element( |
| 593 | 592 | 'span', |
| 594 | 593 | [ |
| 595 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
| 594 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
| 596 | 595 | ], |
| 597 | - $this->msg( $messageName )->text() |
|
| 596 | + $this->msg($messageName)->text() |
|
| 598 | 597 | ); |
| 599 | 598 | |
| 600 | 599 | return $formattedStatus; |
@@ -610,26 +609,26 @@ discard block |
||
| 610 | 609 | * |
| 611 | 610 | * @return string HTML |
| 612 | 611 | */ |
| 613 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
| 614 | - if ( $dataValues instanceof DataValue ) { |
|
| 615 | - $dataValues = [ $dataValues ]; |
|
| 616 | - } elseif ( !is_array( $dataValues ) ) { |
|
| 617 | - 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.'); |
|
| 618 | 617 | } |
| 619 | 618 | |
| 620 | 619 | $formattedDataValues = []; |
| 621 | - foreach ( $dataValues as $dataValue ) { |
|
| 622 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
| 623 | - 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.'); |
|
| 624 | 623 | } |
| 625 | - if ( $dataValue instanceof EntityIdValue ) { |
|
| 626 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
| 624 | + if ($dataValue instanceof EntityIdValue) { |
|
| 625 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
| 627 | 626 | } else { |
| 628 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
| 627 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
| 629 | 628 | } |
| 630 | 629 | } |
| 631 | 630 | |
| 632 | - return implode( $separator, $formattedDataValues ); |
|
| 631 | + return implode($separator, $formattedDataValues); |
|
| 633 | 632 | } |
| 634 | 633 | |
| 635 | 634 | /** |
@@ -641,12 +640,12 @@ discard block |
||
| 641 | 640 | * |
| 642 | 641 | * @return string HTML |
| 643 | 642 | */ |
| 644 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
| 643 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
| 645 | 644 | return |
| 646 | 645 | Html::rawElement( |
| 647 | 646 | 'a', |
| 648 | 647 | [ |
| 649 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
| 648 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
| 650 | 649 | 'target' => '_blank' |
| 651 | 650 | ], |
| 652 | 651 | $text |
@@ -661,9 +660,9 @@ discard block |
||
| 661 | 660 | * |
| 662 | 661 | * @return string |
| 663 | 662 | */ |
| 664 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
| 665 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
| 666 | - $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()); |
|
| 667 | 666 | |
| 668 | 667 | return $entityUrl; |
| 669 | 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,7 +26,7 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * @var ConstraintLookup $lookup The lookup to which all queries are delegated. |
| 28 | 28 | */ |
| 29 | - public function __construct( ConstraintLookup $lookup ) { |
|
| 29 | + public function __construct(ConstraintLookup $lookup) { |
|
| 30 | 30 | $this->lookup = $lookup; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return Constraint[] |
| 37 | 37 | */ |
| 38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
| 38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
| 39 | 39 | $id = $propertyId->getSerialization(); |
| 40 | - if ( !array_key_exists( $id, $this->cache ) ) { |
|
| 41 | - $this->cache[$id] = $this->lookup->queryConstraintsForProperty( $propertyId ); |
|
| 40 | + if (!array_key_exists($id, $this->cache)) { |
|
| 41 | + $this->cache[$id] = $this->lookup->queryConstraintsForProperty($propertyId); |
|
| 42 | 42 | } |
| 43 | 43 | return $this->cache[$id]; |
| 44 | 44 | } |
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | * @codeCoverageIgnore |
| 73 | 73 | */ |
| 74 | 74 | private function __construct() { |
| 75 | - throw new LogicException( 'This class should never be instantiated.' ); |
|
| 75 | + throw new LogicException('This class should never be instantiated.'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | } |
@@ -25,22 +25,22 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | const NULL_PROPERTY_ID = 'P2147483647'; |
| 27 | 27 | |
| 28 | - public function __construct( Context $context ) { |
|
| 28 | + public function __construct(Context $context) { |
|
| 29 | 29 | $constraint = new Constraint( |
| 30 | 30 | 'null', |
| 31 | - new PropertyId( self::NULL_PROPERTY_ID ), |
|
| 31 | + new PropertyId(self::NULL_PROPERTY_ID), |
|
| 32 | 32 | 'none', |
| 33 | 33 | [] |
| 34 | 34 | ); |
| 35 | - parent::__construct( $context, $constraint ); |
|
| 35 | + parent::__construct($context, $constraint); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function getConstraint() { |
| 39 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
| 39 | + throw new DomainException('NullResult holds no constraint'); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function getConstraintId() { |
| 43 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
| 43 | + throw new DomainException('NullResult holds no constraint'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | } |