@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 52 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 53 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 51 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 52 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 53 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | $constraint->getConstraintTypeItemId() |
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | - if ( !in_array( $context->getEntity()->getType(), $entityTypes->getEntityTypes() ) ) { |
|
| 63 | - $message = ( new ViolationMessage( 'wbqc-violation-message-entityType' ) ) |
|
| 64 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
| 65 | - ->withEntityIdList( $entityTypes->getEntityTypeItemIds(), Role::CONSTRAINT_PARAMETER_VALUE ); |
|
| 62 | + if (!in_array($context->getEntity()->getType(), $entityTypes->getEntityTypes())) { |
|
| 63 | + $message = (new ViolationMessage('wbqc-violation-message-entityType')) |
|
| 64 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
| 65 | + ->withEntityIdList($entityTypes->getEntityTypeItemIds(), Role::CONSTRAINT_PARAMETER_VALUE); |
|
| 66 | 66 | |
| 67 | 67 | return new CheckResult( |
| 68 | 68 | $context, |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | ); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 75 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 78 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 79 | 79 | $constraintParameters = $constraint->getConstraintParameters(); |
| 80 | 80 | $exceptions = []; |
| 81 | 81 | try { |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $constraintParameters, |
| 84 | 84 | $constraint->getConstraintTypeItemId() |
| 85 | 85 | ); |
| 86 | - } catch ( ConstraintParameterException $e ) { |
|
| 86 | + } catch (ConstraintParameterException $e) { |
|
| 87 | 87 | $exceptions[] = $e; |
| 88 | 88 | } |
| 89 | 89 | return $exceptions; |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return CheckResult |
| 64 | 64 | */ |
| 65 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 66 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 67 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 65 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 66 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 67 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $separators = $this->constraintParameterParser->parseSeparatorsParameter( |
@@ -73,33 +73,32 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $propertyId = $context->getSnak()->getPropertyId(); |
| 75 | 75 | $propertyCount = $this->valueCountCheckerHelper->getPropertyCount( |
| 76 | - $context->getSnakGroup( Context::GROUP_NON_DEPRECATED, $separators ), |
|
| 76 | + $context->getSnakGroup(Context::GROUP_NON_DEPRECATED, $separators), |
|
| 77 | 77 | $propertyId |
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | - if ( $propertyCount <= 1 ) { |
|
| 81 | - $message = ( new ViolationMessage( |
|
| 80 | + if ($propertyCount <= 1) { |
|
| 81 | + $message = (new ViolationMessage( |
|
| 82 | 82 | $separators === [] ? |
| 83 | - 'wbqc-violation-message-multi-value' : |
|
| 84 | - 'wbqc-violation-message-multi-value-separators' |
|
| 85 | - ) ) |
|
| 86 | - ->withEntityId( $propertyId ) |
|
| 87 | - ->withEntityIdList( $separators ); |
|
| 83 | + 'wbqc-violation-message-multi-value' : 'wbqc-violation-message-multi-value-separators' |
|
| 84 | + )) |
|
| 85 | + ->withEntityId($propertyId) |
|
| 86 | + ->withEntityIdList($separators); |
|
| 88 | 87 | $status = CheckResult::STATUS_VIOLATION; |
| 89 | 88 | } else { |
| 90 | 89 | $message = null; |
| 91 | 90 | $status = CheckResult::STATUS_COMPLIANCE; |
| 92 | 91 | } |
| 93 | 92 | |
| 94 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
| 93 | + return new CheckResult($context, $constraint, $status, $message); |
|
| 95 | 94 | } |
| 96 | 95 | |
| 97 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 96 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 98 | 97 | $constraintParameters = $constraint->getConstraintParameters(); |
| 99 | 98 | $exceptions = []; |
| 100 | 99 | try { |
| 101 | - $this->constraintParameterParser->parseSeparatorsParameter( $constraintParameters ); |
|
| 102 | - } catch ( ConstraintParameterException $e ) { |
|
| 100 | + $this->constraintParameterParser->parseSeparatorsParameter($constraintParameters); |
|
| 101 | + } catch (ConstraintParameterException $e) { |
|
| 103 | 102 | $exceptions[] = $e; |
| 104 | 103 | } |
| 105 | 104 | return $exceptions; |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | * @throws ConstraintParameterException |
| 77 | 77 | * @return CheckResult |
| 78 | 78 | */ |
| 79 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 80 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 81 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 79 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 80 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 81 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -90,50 +90,50 @@ discard block |
||
| 90 | 90 | true |
| 91 | 91 | ); |
| 92 | 92 | |
| 93 | - $message = ( new ViolationMessage( 'wbqc-violation-message-language' ) ) |
|
| 94 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
| 95 | - ->withItemIdSnakValueList( $languages, Role::OBJECT ); |
|
| 93 | + $message = (new ViolationMessage('wbqc-violation-message-language')) |
|
| 94 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
| 95 | + ->withItemIdSnakValueList($languages, Role::OBJECT); |
|
| 96 | 96 | $status = CheckResult::STATUS_VIOLATION; |
| 97 | 97 | |
| 98 | - $lexeme = $this->getLexeme( $context ); |
|
| 99 | - if ( !$lexeme ) { |
|
| 98 | + $lexeme = $this->getLexeme($context); |
|
| 99 | + if (!$lexeme) { |
|
| 100 | 100 | // Lexeme doesn't exist, let's not bother |
| 101 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE ); |
|
| 101 | + return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** @var Lexeme $lexeme */ |
| 105 | 105 | '@phan-var Lexeme $lexeme'; |
| 106 | 106 | |
| 107 | - foreach ( $languages as $language ) { |
|
| 108 | - if ( $language->isNoValue() || $language->isSomeValue() ) { |
|
| 107 | + foreach ($languages as $language) { |
|
| 108 | + if ($language->isNoValue() || $language->isSomeValue()) { |
|
| 109 | 109 | continue; |
| 110 | 110 | } |
| 111 | - if ( $lexeme->getLanguage()->equals( $language->getItemId() ) ) { |
|
| 111 | + if ($lexeme->getLanguage()->equals($language->getItemId())) { |
|
| 112 | 112 | $message = null; |
| 113 | 113 | $status = CheckResult::STATUS_COMPLIANCE; |
| 114 | 114 | break; |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
| 118 | + return new CheckResult($context, $constraint, $status, $message); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - private function getLexeme( Context $context ): ?EntityDocument { |
|
| 121 | + private function getLexeme(Context $context): ?EntityDocument { |
|
| 122 | 122 | $entityType = $context->getEntity()->getType(); |
| 123 | 123 | |
| 124 | - if ( $entityType === Lexeme::ENTITY_TYPE ) { |
|
| 124 | + if ($entityType === Lexeme::ENTITY_TYPE) { |
|
| 125 | 125 | return $context->getEntity(); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if ( in_array( $entityType, [ Form::ENTITY_TYPE, Sense::ENTITY_TYPE ] ) ) { |
|
| 128 | + if (in_array($entityType, [Form::ENTITY_TYPE, Sense::ENTITY_TYPE])) { |
|
| 129 | 129 | /** @var LexemeSubEntityId $id */ |
| 130 | 130 | $id = $context->getEntity()->getId(); |
| 131 | 131 | '@phan-var LexemeSubEntityId $id'; |
| 132 | - return $this->entityLookup->getEntity( $id->getLexemeId() ); |
|
| 132 | + return $this->entityLookup->getEntity($id->getLexemeId()); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
| 136 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
| 137 | 137 | $constraintParameters = $constraint->getConstraintParameters(); |
| 138 | 138 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 139 | 139 | $exceptions = []; |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $constraintTypeItemId, |
| 144 | 144 | true |
| 145 | 145 | ); |
| 146 | - } catch ( ConstraintParameterException $e ) { |
|
| 146 | + } catch (ConstraintParameterException $e) { |
|
| 147 | 147 | $exceptions[] = $e; |
| 148 | 148 | } |
| 149 | 149 | return $exceptions; |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
| 76 | 76 | * @return CheckResult |
| 77 | 77 | */ |
| 78 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 79 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 80 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 78 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 79 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 80 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 81 | 81 | } |
| 82 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
| 83 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE ); |
|
| 82 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
| 83 | + return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | $constraintTypeItemId |
| 97 | 97 | ); |
| 98 | 98 | $relationIds = []; |
| 99 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
| 100 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
| 99 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
| 100 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
| 101 | 101 | } |
| 102 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
| 103 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
| 102 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
| 103 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $result = $this->typeCheckerHelper->hasClassInRelation( |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | $classes |
| 110 | 110 | ); |
| 111 | 111 | |
| 112 | - if ( $result->getBool() ) { |
|
| 112 | + if ($result->getBool()) { |
|
| 113 | 113 | $message = null; |
| 114 | 114 | $status = CheckResult::STATUS_COMPLIANCE; |
| 115 | 115 | } else { |
@@ -123,11 +123,11 @@ discard block |
||
| 123 | 123 | $status = CheckResult::STATUS_VIOLATION; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
| 127 | - ->withMetadata( $result->getMetadata() ); |
|
| 126 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
| 127 | + ->withMetadata($result->getMetadata()); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 130 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 131 | 131 | $constraintParameters = $constraint->getConstraintParameters(); |
| 132 | 132 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 133 | 133 | $exceptions = []; |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $constraintParameters, |
| 137 | 137 | $constraintTypeItemId |
| 138 | 138 | ); |
| 139 | - } catch ( ConstraintParameterException $e ) { |
|
| 139 | + } catch (ConstraintParameterException $e) { |
|
| 140 | 140 | $exceptions[] = $e; |
| 141 | 141 | } |
| 142 | 142 | try { |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $constraintParameters, |
| 145 | 145 | $constraintTypeItemId |
| 146 | 146 | ); |
| 147 | - } catch ( ConstraintParameterException $e ) { |
|
| 147 | + } catch (ConstraintParameterException $e) { |
|
| 148 | 148 | $exceptions[] = $e; |
| 149 | 149 | } |
| 150 | 150 | return $exceptions; |
@@ -33,16 +33,16 @@ |
||
| 33 | 33 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 37 | - if ( $context->getType() === Context::TYPE_STATEMENT ) { |
|
| 38 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 36 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 37 | + if ($context->getType() === Context::TYPE_STATEMENT) { |
|
| 38 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 39 | 39 | } else { |
| 40 | - $message = new ViolationMessage( 'wbqc-violation-message-valueOnly' ); |
|
| 41 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 40 | + $message = new ViolationMessage('wbqc-violation-message-valueOnly'); |
|
| 41 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 45 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 46 | 46 | // no parameters |
| 47 | 47 | return []; |
| 48 | 48 | } |
@@ -79,17 +79,17 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return CheckResult |
| 81 | 81 | */ |
| 82 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 83 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 84 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 82 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 83 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 84 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $snak = $context->getSnak(); |
| 88 | 88 | $propertyId = $context->getSnak()->getPropertyId(); |
| 89 | 89 | |
| 90 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 90 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 91 | 91 | // nothing to check |
| 92 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 92 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $dataValue = $snak->getDataValue(); |
@@ -98,18 +98,18 @@ discard block |
||
| 98 | 98 | * error handling: |
| 99 | 99 | * type of $dataValue for properties with 'Symmetric' constraint has to be 'wikibase-entityid' |
| 100 | 100 | */ |
| 101 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
| 102 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
| 103 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 104 | - ->withDataValueType( 'wikibase-entityid' ); |
|
| 105 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 101 | + if (!$dataValue instanceof EntityIdValue) { |
|
| 102 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
| 103 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
| 104 | + ->withDataValueType('wikibase-entityid'); |
|
| 105 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | $targetEntityId = $dataValue->getEntityId(); |
| 109 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
| 110 | - if ( !$targetEntity instanceof StatementListProvider ) { |
|
| 111 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
| 112 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 109 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
| 110 | + if (!$targetEntity instanceof StatementListProvider) { |
|
| 111 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
| 112 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $symmetricStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -117,23 +117,23 @@ discard block |
||
| 117 | 117 | $propertyId, |
| 118 | 118 | $context->getEntity()->getId() |
| 119 | 119 | ); |
| 120 | - if ( $symmetricStatement !== null ) { |
|
| 120 | + if ($symmetricStatement !== null) { |
|
| 121 | 121 | $message = null; |
| 122 | 122 | $status = CheckResult::STATUS_COMPLIANCE; |
| 123 | 123 | } else { |
| 124 | - $message = ( new ViolationMessage( 'wbqc-violation-message-symmetric' ) ) |
|
| 125 | - ->withEntityId( $targetEntityId, Role::SUBJECT ) |
|
| 126 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
| 127 | - ->withEntityId( $context->getEntity()->getId(), Role::OBJECT ); |
|
| 124 | + $message = (new ViolationMessage('wbqc-violation-message-symmetric')) |
|
| 125 | + ->withEntityId($targetEntityId, Role::SUBJECT) |
|
| 126 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
| 127 | + ->withEntityId($context->getEntity()->getId(), Role::OBJECT); |
|
| 128 | 128 | $status = CheckResult::STATUS_VIOLATION; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
| 132 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
| 133 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
| 131 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
| 132 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
| 133 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 136 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 137 | 137 | // no parameters |
| 138 | 138 | return []; |
| 139 | 139 | } |
@@ -36,17 +36,17 @@ discard block |
||
| 36 | 36 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 39 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 40 | 40 | $snak = $context->getSnak(); |
| 41 | 41 | |
| 42 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 42 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 43 | 43 | // nothing to check |
| 44 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 44 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - if ( $snak->getDataValue() instanceof QuantityValue ) { |
|
| 48 | - $message = ( new ViolationMessage( 'wbqc-violation-message-noBounds' ) ) |
|
| 49 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
| 47 | + if ($snak->getDataValue() instanceof QuantityValue) { |
|
| 48 | + $message = (new ViolationMessage('wbqc-violation-message-noBounds')) |
|
| 49 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
| 50 | 50 | return new CheckResult( |
| 51 | 51 | $context, |
| 52 | 52 | $constraint, |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 58 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 61 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 62 | 62 | // no parameters |
| 63 | 63 | return []; |
| 64 | 64 | } |
@@ -67,9 +67,9 @@ discard block |
||
| 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 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -80,24 +80,24 @@ discard block |
||
| 80 | 80 | $constraintTypeItemId |
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | - $message = ( new ViolationMessage( 'wbqc-violation-message-mandatory-qualifier' ) ) |
|
| 84 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
| 85 | - ->withEntityId( $propertyId, Role::QUALIFIER_PREDICATE ); |
|
| 83 | + $message = (new ViolationMessage('wbqc-violation-message-mandatory-qualifier')) |
|
| 84 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
| 85 | + ->withEntityId($propertyId, Role::QUALIFIER_PREDICATE); |
|
| 86 | 86 | $status = CheckResult::STATUS_VIOLATION; |
| 87 | 87 | |
| 88 | 88 | /** @var Snak $qualifier */ |
| 89 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
| 90 | - if ( $propertyId->equals( $qualifier->getPropertyId() ) ) { |
|
| 89 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
| 90 | + if ($propertyId->equals($qualifier->getPropertyId())) { |
|
| 91 | 91 | $message = null; |
| 92 | 92 | $status = CheckResult::STATUS_COMPLIANCE; |
| 93 | 93 | break; |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
| 97 | + return new CheckResult($context, $constraint, $status, $message); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 100 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 101 | 101 | $constraintParameters = $constraint->getConstraintParameters(); |
| 102 | 102 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 103 | 103 | $exceptions = []; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $constraintParameters, |
| 107 | 107 | $constraintTypeItemId |
| 108 | 108 | ); |
| 109 | - } catch ( ConstraintParameterException $e ) { |
|
| 109 | + } catch (ConstraintParameterException $e) { |
|
| 110 | 110 | $exceptions[] = $e; |
| 111 | 111 | } |
| 112 | 112 | return $exceptions; |
@@ -38,22 +38,21 @@ discard block |
||
| 38 | 38 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 41 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 42 | 42 | $snak = $context->getSnak(); |
| 43 | 43 | |
| 44 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 44 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 45 | 45 | // nothing to check |
| 46 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 46 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - $violationMessage = $this->checkSnak( $snak ); |
|
| 49 | + $violationMessage = $this->checkSnak($snak); |
|
| 50 | 50 | |
| 51 | 51 | return new CheckResult( |
| 52 | 52 | $context, |
| 53 | 53 | $constraint, |
| 54 | 54 | $violationMessage === null ? |
| 55 | - CheckResult::STATUS_COMPLIANCE : |
|
| 56 | - CheckResult::STATUS_VIOLATION, |
|
| 55 | + CheckResult::STATUS_COMPLIANCE : CheckResult::STATUS_VIOLATION, |
|
| 57 | 56 | $violationMessage |
| 58 | 57 | ); |
| 59 | 58 | } |
@@ -62,23 +61,23 @@ discard block |
||
| 62 | 61 | * @param PropertyValueSnak $snak |
| 63 | 62 | * @return ViolationMessage|null |
| 64 | 63 | */ |
| 65 | - public function checkSnak( PropertyValueSnak $snak ) { |
|
| 64 | + public function checkSnak(PropertyValueSnak $snak) { |
|
| 66 | 65 | $dataValue = $snak->getDataValue(); |
| 67 | 66 | |
| 68 | - if ( $dataValue instanceof DecimalValue ) { |
|
| 69 | - if ( !$this->isInteger( $dataValue ) ) { |
|
| 70 | - return $this->getViolationMessage( 'wbqc-violation-message-integer', $snak ); |
|
| 67 | + if ($dataValue instanceof DecimalValue) { |
|
| 68 | + if (!$this->isInteger($dataValue)) { |
|
| 69 | + return $this->getViolationMessage('wbqc-violation-message-integer', $snak); |
|
| 71 | 70 | } |
| 72 | - } elseif ( $dataValue instanceof UnboundedQuantityValue ) { |
|
| 73 | - if ( !$this->isInteger( $dataValue->getAmount() ) ) { |
|
| 74 | - return $this->getViolationMessage( 'wbqc-violation-message-integer', $snak ); |
|
| 71 | + } elseif ($dataValue instanceof UnboundedQuantityValue) { |
|
| 72 | + if (!$this->isInteger($dataValue->getAmount())) { |
|
| 73 | + return $this->getViolationMessage('wbqc-violation-message-integer', $snak); |
|
| 75 | 74 | } elseif ( |
| 76 | 75 | $dataValue instanceof QuantityValue && ( |
| 77 | - !$this->isInteger( $dataValue->getLowerBound() ) || |
|
| 78 | - !$this->isInteger( $dataValue->getUpperBound() ) |
|
| 76 | + !$this->isInteger($dataValue->getLowerBound()) || |
|
| 77 | + !$this->isInteger($dataValue->getUpperBound()) |
|
| 79 | 78 | ) |
| 80 | 79 | ) { |
| 81 | - return $this->getViolationMessage( 'wbqc-violation-message-integer-bounds', $snak ); |
|
| 80 | + return $this->getViolationMessage('wbqc-violation-message-integer-bounds', $snak); |
|
| 82 | 81 | } |
| 83 | 82 | } |
| 84 | 83 | |
@@ -89,7 +88,7 @@ discard block |
||
| 89 | 88 | * @param DecimalValue $decimalValue |
| 90 | 89 | * @return bool |
| 91 | 90 | */ |
| 92 | - private function isInteger( DecimalValue $decimalValue ) { |
|
| 91 | + private function isInteger(DecimalValue $decimalValue) { |
|
| 93 | 92 | return $decimalValue->getTrimmed()->getFractionalPart() === ''; |
| 94 | 93 | } |
| 95 | 94 | |
@@ -98,13 +97,13 @@ discard block |
||
| 98 | 97 | * @param PropertyValueSnak $snak |
| 99 | 98 | * @return ViolationMessage |
| 100 | 99 | */ |
| 101 | - private function getViolationMessage( $messageKey, PropertyValueSnak $snak ) { |
|
| 102 | - return ( new ViolationMessage( $messageKey ) ) |
|
| 103 | - ->withEntityId( $snak->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
| 104 | - ->withDataValue( $snak->getDataValue() ); |
|
| 100 | + private function getViolationMessage($messageKey, PropertyValueSnak $snak) { |
|
| 101 | + return (new ViolationMessage($messageKey)) |
|
| 102 | + ->withEntityId($snak->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
| 103 | + ->withDataValue($snak->getDataValue()); |
|
| 105 | 104 | } |
| 106 | 105 | |
| 107 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 106 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 108 | 107 | // no parameters |
| 109 | 108 | return []; |
| 110 | 109 | } |