@@ -67,43 +67,43 @@ |
||
| 67 | 67 | * @throws ConstraintParameterException |
| 68 | 68 | * @return CheckResult |
| 69 | 69 | */ |
| 70 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 71 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 72 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
| 70 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 71 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 72 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $parameters = []; |
| 76 | 76 | $constraintParameters = $constraint->getConstraintParameters(); |
| 77 | 77 | |
| 78 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), true ); |
|
| 78 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), true); |
|
| 79 | 79 | $parameters['item'] = $items; |
| 80 | 80 | |
| 81 | 81 | $snak = $context->getSnak(); |
| 82 | 82 | |
| 83 | - $message = wfMessage( 'wbqc-violation-message-one-of' ); |
|
| 84 | - $message->rawParams( $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) ); |
|
| 85 | - $message->numParams( count( $items ) ); |
|
| 86 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdSnakValueList( $items, Role::OBJECT ) ); |
|
| 83 | + $message = wfMessage('wbqc-violation-message-one-of'); |
|
| 84 | + $message->rawParams($this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)); |
|
| 85 | + $message->numParams(count($items)); |
|
| 86 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdSnakValueList($items, Role::OBJECT)); |
|
| 87 | 87 | $message = $message->escaped(); |
| 88 | 88 | $status = CheckResult::STATUS_VIOLATION; |
| 89 | 89 | |
| 90 | - foreach ( $items as $item ) { |
|
| 91 | - if ( $item->matchesSnak( $snak ) ) { |
|
| 90 | + foreach ($items as $item) { |
|
| 91 | + if ($item->matchesSnak($snak)) { |
|
| 92 | 92 | $message = null; |
| 93 | 93 | $status = CheckResult::STATUS_COMPLIANCE; |
| 94 | 94 | break; |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
| 98 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 101 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 102 | 102 | $constraintParameters = $constraint->getConstraintParameters(); |
| 103 | 103 | $exceptions = []; |
| 104 | 104 | try { |
| 105 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), true ); |
|
| 106 | - } catch ( ConstraintParameterException $e ) { |
|
| 105 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), true); |
|
| 106 | + } catch (ConstraintParameterException $e) { |
|
| 107 | 107 | $exceptions[] = $e; |
| 108 | 108 | } |
| 109 | 109 | return $exceptions; |
@@ -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 | } |
@@ -98,37 +98,37 @@ discard block |
||
| 98 | 98 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
| 99 | 99 | * @return CheckResult |
| 100 | 100 | */ |
| 101 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 102 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 103 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
| 101 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 102 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 103 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $parameters = []; |
| 107 | 107 | $constraintParameters = $constraint->getConstraintParameters(); |
| 108 | 108 | |
| 109 | - $classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
| 109 | + $classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
| 110 | 110 | $parameters['class'] = array_map( |
| 111 | - function( $id ) { |
|
| 112 | - return new ItemId( $id ); |
|
| 111 | + function($id) { |
|
| 112 | + return new ItemId($id); |
|
| 113 | 113 | }, |
| 114 | 114 | $classes |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - $relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
| 117 | + $relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
| 118 | 118 | $relationIds = []; |
| 119 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
| 120 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
| 119 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
| 120 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
| 121 | 121 | } |
| 122 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
| 123 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
| 122 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
| 123 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
| 124 | 124 | } |
| 125 | - $parameters['relation'] = [ $relation ]; |
|
| 125 | + $parameters['relation'] = [$relation]; |
|
| 126 | 126 | |
| 127 | 127 | $snak = $context->getSnak(); |
| 128 | 128 | |
| 129 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 129 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 130 | 130 | // nothing to check |
| 131 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
| 131 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | $dataValue = $snak->getDataValue(); |
@@ -137,22 +137,22 @@ discard block |
||
| 137 | 137 | * error handling: |
| 138 | 138 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
| 139 | 139 | */ |
| 140 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
| 141 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
| 140 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
| 141 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
| 142 | 142 | ->rawParams( |
| 143 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
| 143 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
| 144 | 144 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
| 145 | 145 | ) |
| 146 | 146 | ->escaped(); |
| 147 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
| 147 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
| 148 | 148 | } |
| 149 | 149 | /** @var EntityIdValue $dataValue */ |
| 150 | 150 | |
| 151 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
| 151 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
| 152 | 152 | |
| 153 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
| 154 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
| 155 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
| 153 | + if (!($item instanceof StatementListProvider)) { |
|
| 154 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
| 155 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | $statements = $item->getStatements(); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $classes |
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | - if ( $result->getBool() ) { |
|
| 166 | + if ($result->getBool()) { |
|
| 167 | 167 | $message = null; |
| 168 | 168 | $status = CheckResult::STATUS_COMPLIANCE; |
| 169 | 169 | } else { |
@@ -177,21 +177,21 @@ discard block |
||
| 177 | 177 | $status = CheckResult::STATUS_VIOLATION; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
| 181 | - ->withMetadata( $result->getMetadata() ); |
|
| 180 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
| 181 | + ->withMetadata($result->getMetadata()); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 184 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 185 | 185 | $constraintParameters = $constraint->getConstraintParameters(); |
| 186 | 186 | $exceptions = []; |
| 187 | 187 | try { |
| 188 | - $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
| 189 | - } catch ( ConstraintParameterException $e ) { |
|
| 188 | + $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
| 189 | + } catch (ConstraintParameterException $e) { |
|
| 190 | 190 | $exceptions[] = $e; |
| 191 | 191 | } |
| 192 | 192 | try { |
| 193 | - $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
| 194 | - } catch ( ConstraintParameterException $e ) { |
|
| 193 | + $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
| 194 | + } catch (ConstraintParameterException $e) { |
|
| 195 | 195 | $exceptions[] = $e; |
| 196 | 196 | } |
| 197 | 197 | return $exceptions; |
@@ -47,16 +47,16 @@ |
||
| 47 | 47 | * |
| 48 | 48 | * @return CheckResult |
| 49 | 49 | */ |
| 50 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 51 | - if ( $context->getType() === Context::TYPE_QUALIFIER ) { |
|
| 52 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
| 50 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 51 | + if ($context->getType() === Context::TYPE_QUALIFIER) { |
|
| 52 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
| 53 | 53 | } else { |
| 54 | - $message = new ViolationMessage( 'wbqc-violation-message-qualifier' ); |
|
| 55 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
| 54 | + $message = new ViolationMessage('wbqc-violation-message-qualifier'); |
|
| 55 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 59 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 60 | 60 | // no parameters |
| 61 | 61 | return []; |
| 62 | 62 | } |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return CheckResult |
| 57 | 57 | */ |
| 58 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 59 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 60 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
| 58 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 59 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 60 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $propertyId = $context->getSnak()->getPropertyId(); |
@@ -69,18 +69,18 @@ discard block |
||
| 69 | 69 | $propertyId |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - if ( $propertyCount <= 1 ) { |
|
| 73 | - $message = new ViolationMessage( 'wbqc-violation-message-multi-value' ); |
|
| 72 | + if ($propertyCount <= 1) { |
|
| 73 | + $message = new ViolationMessage('wbqc-violation-message-multi-value'); |
|
| 74 | 74 | $status = CheckResult::STATUS_VIOLATION; |
| 75 | 75 | } else { |
| 76 | 76 | $message = null; |
| 77 | 77 | $status = CheckResult::STATUS_COMPLIANCE; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
| 80 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 83 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 84 | 84 | // no parameters |
| 85 | 85 | return []; |
| 86 | 86 | } |
@@ -36,16 +36,16 @@ |
||
| 36 | 36 | ]; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 40 | - if ( $context->getType() === Context::TYPE_STATEMENT ) { |
|
| 41 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
| 39 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 40 | + if ($context->getType() === Context::TYPE_STATEMENT) { |
|
| 41 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
| 42 | 42 | } else { |
| 43 | - $message = new ViolationMessage( 'wbqc-violation-message-valueOnly' ); |
|
| 44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
| 43 | + $message = new ViolationMessage('wbqc-violation-message-valueOnly'); |
|
| 44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 48 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 49 | 49 | // no parameters |
| 50 | 50 | return []; |
| 51 | 51 | } |
@@ -88,25 +88,25 @@ discard block |
||
| 88 | 88 | * @throws ConstraintParameterException |
| 89 | 89 | * @return CheckResult |
| 90 | 90 | */ |
| 91 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 92 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 93 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
| 91 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 92 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 93 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $parameters = []; |
| 97 | 97 | $constraintParameters = $constraint->getConstraintParameters(); |
| 98 | 98 | |
| 99 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
| 100 | - $parameters['property'] = [ $propertyId ]; |
|
| 99 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
| 100 | + $parameters['property'] = [$propertyId]; |
|
| 101 | 101 | |
| 102 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
| 102 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
| 103 | 103 | $parameters['items'] = $items; |
| 104 | 104 | |
| 105 | 105 | $snak = $context->getSnak(); |
| 106 | 106 | |
| 107 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 107 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 108 | 108 | // nothing to check |
| 109 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
| 109 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $dataValue = $snak->getDataValue(); |
@@ -115,22 +115,22 @@ discard block |
||
| 115 | 115 | * error handling: |
| 116 | 116 | * type of $dataValue for properties with 'Target required claim' constraint has to be 'wikibase-entityid' |
| 117 | 117 | */ |
| 118 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
| 119 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
| 118 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
| 119 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
| 120 | 120 | ->rawParams( |
| 121 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
| 121 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
| 122 | 122 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
| 123 | 123 | ) |
| 124 | 124 | ->escaped(); |
| 125 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
| 125 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
| 126 | 126 | } |
| 127 | 127 | /** @var EntityIdValue $dataValue */ |
| 128 | 128 | |
| 129 | 129 | $targetEntityId = $dataValue->getEntityId(); |
| 130 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
| 131 | - if ( $targetEntity === null ) { |
|
| 132 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
| 133 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
| 130 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
| 131 | + if ($targetEntity === null) { |
|
| 132 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
| 133 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /* |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * a) a property only |
| 139 | 139 | * b) a property and a number of items (each combination forming an individual claim) |
| 140 | 140 | */ |
| 141 | - if ( $items === [] ) { |
|
| 141 | + if ($items === []) { |
|
| 142 | 142 | $requiredStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
| 143 | 143 | $targetEntity->getStatements(), |
| 144 | 144 | $propertyId |
@@ -151,37 +151,37 @@ discard block |
||
| 151 | 151 | ); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if ( $requiredStatement !== null ) { |
|
| 154 | + if ($requiredStatement !== null) { |
|
| 155 | 155 | $status = CheckResult::STATUS_COMPLIANCE; |
| 156 | 156 | $message = null; |
| 157 | 157 | } else { |
| 158 | 158 | $status = CheckResult::STATUS_VIOLATION; |
| 159 | - $message = wfMessage( 'wbqc-violation-message-target-required-claim' ); |
|
| 159 | + $message = wfMessage('wbqc-violation-message-target-required-claim'); |
|
| 160 | 160 | $message->rawParams( |
| 161 | - $this->constraintParameterRenderer->formatEntityId( $targetEntityId, Role::SUBJECT ), |
|
| 162 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ) |
|
| 161 | + $this->constraintParameterRenderer->formatEntityId($targetEntityId, Role::SUBJECT), |
|
| 162 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE) |
|
| 163 | 163 | ); |
| 164 | - $message->numParams( count( $items ) ); |
|
| 165 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdSnakValueList( $items, Role::OBJECT ) ); |
|
| 164 | + $message->numParams(count($items)); |
|
| 165 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdSnakValueList($items, Role::OBJECT)); |
|
| 166 | 166 | $message = $message->escaped(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
| 170 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
| 171 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
| 169 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
| 170 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
| 171 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 174 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 175 | 175 | $constraintParameters = $constraint->getConstraintParameters(); |
| 176 | 176 | $exceptions = []; |
| 177 | 177 | try { |
| 178 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
| 179 | - } catch ( ConstraintParameterException $e ) { |
|
| 178 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
| 179 | + } catch (ConstraintParameterException $e) { |
|
| 180 | 180 | $exceptions[] = $e; |
| 181 | 181 | } |
| 182 | 182 | try { |
| 183 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
| 184 | - } catch ( ConstraintParameterException $e ) { |
|
| 183 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
| 184 | + } catch (ConstraintParameterException $e) { |
|
| 185 | 185 | $exceptions[] = $e; |
| 186 | 186 | } |
| 187 | 187 | return $exceptions; |
@@ -36,16 +36,16 @@ |
||
| 36 | 36 | ]; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 40 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
| 41 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
| 39 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 40 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
| 41 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
| 42 | 42 | } else { |
| 43 | - $message = new ViolationMessage( 'wbqc-violation-message-reference' ); |
|
| 44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
| 43 | + $message = new ViolationMessage('wbqc-violation-message-reference'); |
|
| 44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 48 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 49 | 49 | // no parameters |
| 50 | 50 | return []; |
| 51 | 51 | } |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | * @throws ConstraintParameterException |
| 85 | 85 | * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ] |
| 86 | 86 | */ |
| 87 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
| 88 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
| 87 | + private function parseConstraintParameters(Constraint $constraint) { |
|
| 88 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
| 89 | 89 | $constraint->getConstraintParameters(), |
| 90 | 90 | $constraint->getConstraintTypeItemId(), |
| 91 | 91 | 'quantity' |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | $constraint->getConstraintTypeItemId() |
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | - if ( $min !== null ) { |
|
| 99 | - $parameters['minimum_quantity'] = [ $min ]; |
|
| 98 | + if ($min !== null) { |
|
| 99 | + $parameters['minimum_quantity'] = [$min]; |
|
| 100 | 100 | } |
| 101 | - if ( $max !== null ) { |
|
| 102 | - $parameters['maximum_quantity'] = [ $max ]; |
|
| 101 | + if ($max !== null) { |
|
| 102 | + $parameters['maximum_quantity'] = [$max]; |
|
| 103 | 103 | } |
| 104 | - $parameters['property'] = [ $property ]; |
|
| 104 | + $parameters['property'] = [$property]; |
|
| 105 | 105 | |
| 106 | - return [ $min, $max, $property, $parameters ]; |
|
| 106 | + return [$min, $max, $property, $parameters]; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return bool |
| 115 | 115 | */ |
| 116 | - private function rangeInYears( $min, $max ) { |
|
| 117 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
| 116 | + private function rangeInYears($min, $max) { |
|
| 117 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
| 118 | 118 | |
| 119 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
| 119 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
| 120 | 120 | return true; |
| 121 | 121 | } |
| 122 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
| 122 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
| 123 | 123 | return true; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -135,57 +135,56 @@ discard block |
||
| 135 | 135 | * @throws ConstraintParameterException |
| 136 | 136 | * @return CheckResult |
| 137 | 137 | */ |
| 138 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 139 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 140 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
| 138 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 139 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 140 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | $parameters = []; |
| 144 | 144 | |
| 145 | 145 | $snak = $context->getSnak(); |
| 146 | 146 | |
| 147 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 147 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 148 | 148 | // nothing to check |
| 149 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
| 149 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | $minuend = $snak->getDataValue(); |
| 153 | 153 | |
| 154 | 154 | /** @var PropertyId $property */ |
| 155 | - list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
| 155 | + list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
| 156 | 156 | |
| 157 | 157 | // checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property) |
| 158 | - foreach ( $context->getSnakGroup() as $otherSnak ) { |
|
| 158 | + foreach ($context->getSnakGroup() as $otherSnak) { |
|
| 159 | 159 | if ( |
| 160 | - !$property->equals( $otherSnak->getPropertyId() ) || |
|
| 160 | + !$property->equals($otherSnak->getPropertyId()) || |
|
| 161 | 161 | !$otherSnak instanceof PropertyValueSnak |
| 162 | 162 | ) { |
| 163 | 163 | continue; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $subtrahend = $otherSnak->getDataValue(); |
| 167 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
| 168 | - $diff = $this->rangeInYears( $min, $max ) ? |
|
| 169 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
| 170 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
| 167 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
| 168 | + $diff = $this->rangeInYears($min, $max) ? |
|
| 169 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
| 171 | 170 | |
| 172 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
| 173 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
| 171 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
| 172 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
| 174 | 173 | ) { |
| 175 | 174 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
| 176 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
| 177 | - $message = wfMessage( "wbqc-violation-message-diff-within-range$openness" ); |
|
| 175 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
| 176 | + $message = wfMessage("wbqc-violation-message-diff-within-range$openness"); |
|
| 178 | 177 | $message->rawParams( |
| 179 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
| 180 | - $this->constraintParameterRenderer->formatDataValue( $minuend, Role::OBJECT ), |
|
| 181 | - $this->constraintParameterRenderer->formatEntityId( $otherSnak->getPropertyId(), Role::PREDICATE ), |
|
| 182 | - $this->constraintParameterRenderer->formatDataValue( $subtrahend, Role::OBJECT ) |
|
| 178 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE), |
|
| 179 | + $this->constraintParameterRenderer->formatDataValue($minuend, Role::OBJECT), |
|
| 180 | + $this->constraintParameterRenderer->formatEntityId($otherSnak->getPropertyId(), Role::PREDICATE), |
|
| 181 | + $this->constraintParameterRenderer->formatDataValue($subtrahend, Role::OBJECT) |
|
| 183 | 182 | ); |
| 184 | - if ( $min !== null ) { |
|
| 185 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
| 183 | + if ($min !== null) { |
|
| 184 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
| 186 | 185 | } |
| 187 | - if ( $max !== null ) { |
|
| 188 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
| 186 | + if ($max !== null) { |
|
| 187 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
| 189 | 188 | } |
| 190 | 189 | $message = $message->escaped(); |
| 191 | 190 | $status = CheckResult::STATUS_VIOLATION; |
@@ -194,19 +193,19 @@ discard block |
||
| 194 | 193 | $status = CheckResult::STATUS_COMPLIANCE; |
| 195 | 194 | } |
| 196 | 195 | } else { |
| 197 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' ); |
|
| 196 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types'); |
|
| 198 | 197 | $status = CheckResult::STATUS_VIOLATION; |
| 199 | 198 | } |
| 200 | 199 | |
| 201 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
| 200 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
| 202 | 201 | } |
| 203 | 202 | |
| 204 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-property-must-exist' ); |
|
| 203 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-property-must-exist'); |
|
| 205 | 204 | $status = CheckResult::STATUS_VIOLATION; |
| 206 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
| 205 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
| 207 | 206 | } |
| 208 | 207 | |
| 209 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 208 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 210 | 209 | $constraintParameters = $constraint->getConstraintParameters(); |
| 211 | 210 | $exceptions = []; |
| 212 | 211 | try { |
@@ -215,12 +214,12 @@ discard block |
||
| 215 | 214 | $constraint->getConstraintTypeItemId(), |
| 216 | 215 | 'quantity' |
| 217 | 216 | ); |
| 218 | - } catch ( ConstraintParameterException $e ) { |
|
| 217 | + } catch (ConstraintParameterException $e) { |
|
| 219 | 218 | $exceptions[] = $e; |
| 220 | 219 | } |
| 221 | 220 | try { |
| 222 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
| 223 | - } catch ( ConstraintParameterException $e ) { |
|
| 221 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
| 222 | + } catch (ConstraintParameterException $e) { |
|
| 224 | 223 | $exceptions[] = $e; |
| 225 | 224 | } |
| 226 | 225 | return $exceptions; |