@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result; |
| 6 | 6 | |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | string $status = self::STATUS_TODO, |
| 111 | 111 | ViolationMessage $message = null |
| 112 | 112 | ) { |
| 113 | - if ( $contextCursor instanceof Context ) { |
|
| 113 | + if ($contextCursor instanceof Context) { |
|
| 114 | 114 | $context = $contextCursor; |
| 115 | 115 | $this->contextCursor = $context->getCursor(); |
| 116 | 116 | $this->snakType = $context->getSnak()->getType(); |
| 117 | 117 | $mainSnak = $context->getSnak(); |
| 118 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
| 118 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
| 119 | 119 | $this->dataValue = $mainSnak->getDataValue(); |
| 120 | 120 | } else { |
| 121 | 121 | $this->dataValue = null; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $this->status = $status; |
| 130 | 130 | $this->message = $message; |
| 131 | 131 | $this->metadata = Metadata::blank(); |
| 132 | - $this->constraintClarification = new MultilingualTextValue( [] ); |
|
| 132 | + $this->constraintClarification = new MultilingualTextValue([]); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | public function getContextCursor(): ContextCursor { |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | return $this->status; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - public function setStatus( string $status ): void { |
|
| 168 | + public function setStatus(string $status): void { |
|
| 169 | 169 | $this->status = $status; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -173,11 +173,11 @@ discard block |
||
| 173 | 173 | return $this->message; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - public function setMessage( ?ViolationMessage $message ) { |
|
| 176 | + public function setMessage(?ViolationMessage $message) { |
|
| 177 | 177 | $this->message = $message; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - public function withMetadata( Metadata $metadata ): self { |
|
| 180 | + public function withMetadata(Metadata $metadata): self { |
|
| 181 | 181 | $this->metadata = $metadata; |
| 182 | 182 | return $this; |
| 183 | 183 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | return $this->constraintClarification; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - public function setConstraintClarification( MultilingualTextValue $constraintClarification ) { |
|
| 193 | + public function setConstraintClarification(MultilingualTextValue $constraintClarification) { |
|
| 194 | 194 | $this->constraintClarification = $constraintClarification; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | * @throws ConstraintParameterException |
| 90 | 90 | * @return CheckResult |
| 91 | 91 | */ |
| 92 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 93 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 94 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 92 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 93 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 94 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -104,9 +104,9 @@ discard block |
||
| 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, CheckResult::STATUS_COMPLIANCE ); |
|
| 109 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $dataValue = $snak->getDataValue(); |
@@ -115,18 +115,18 @@ discard block |
||
| 115 | 115 | * error handling: |
| 116 | 116 | * type of $dataValue for properties with 'Inverse' constraint has to be 'wikibase-entityid' |
| 117 | 117 | */ |
| 118 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
| 119 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
| 120 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 121 | - ->withDataValueType( 'wikibase-entityid' ); |
|
| 122 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 118 | + if (!$dataValue instanceof EntityIdValue) { |
|
| 119 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
| 120 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 121 | + ->withDataValueType('wikibase-entityid'); |
|
| 122 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $targetEntityId = $dataValue->getEntityId(); |
| 126 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
| 127 | - if ( !$targetEntity instanceof StatementListProvider ) { |
|
| 128 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
| 129 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 126 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
| 127 | + if (!$targetEntity instanceof StatementListProvider) { |
|
| 128 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
| 129 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $inverseStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -134,23 +134,23 @@ discard block |
||
| 134 | 134 | $propertyId, |
| 135 | 135 | $context->getEntity()->getId() |
| 136 | 136 | ); |
| 137 | - if ( $inverseStatement !== null ) { |
|
| 137 | + if ($inverseStatement !== null) { |
|
| 138 | 138 | $message = null; |
| 139 | 139 | $status = CheckResult::STATUS_COMPLIANCE; |
| 140 | 140 | } else { |
| 141 | - $message = ( new ViolationMessage( 'wbqc-violation-message-inverse' ) ) |
|
| 142 | - ->withEntityId( $targetEntityId, Role::SUBJECT ) |
|
| 143 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
| 144 | - ->withEntityId( $context->getEntity()->getId(), Role::OBJECT ); |
|
| 141 | + $message = (new ViolationMessage('wbqc-violation-message-inverse')) |
|
| 142 | + ->withEntityId($targetEntityId, Role::SUBJECT) |
|
| 143 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
| 144 | + ->withEntityId($context->getEntity()->getId(), Role::OBJECT); |
|
| 145 | 145 | $status = CheckResult::STATUS_VIOLATION; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
| 149 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
| 150 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
| 148 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
| 149 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
| 150 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 153 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 154 | 154 | $constraintParameters = $constraint->getConstraintParameters(); |
| 155 | 155 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 156 | 156 | $exceptions = []; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $constraintParameters, |
| 160 | 160 | $constraintTypeItemId |
| 161 | 161 | ); |
| 162 | - } catch ( ConstraintParameterException $e ) { |
|
| 162 | + } catch (ConstraintParameterException $e) { |
|
| 163 | 163 | $exceptions[] = $e; |
| 164 | 164 | } |
| 165 | 165 | return $exceptions; |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | * @throws ConstraintParameterException |
| 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 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | $snak = $context->getSnak(); |
| 102 | 102 | |
| 103 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 103 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 104 | 104 | // nothing to check |
| 105 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 105 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | $dataValue = $snak->getDataValue(); |
@@ -111,18 +111,18 @@ discard block |
||
| 111 | 111 | * error handling: |
| 112 | 112 | * type of $dataValue for properties with 'Target required claim' constraint has to be 'wikibase-entityid' |
| 113 | 113 | */ |
| 114 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
| 115 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
| 116 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 117 | - ->withDataValueType( 'wikibase-entityid' ); |
|
| 118 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 114 | + if (!$dataValue instanceof EntityIdValue) { |
|
| 115 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
| 116 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 117 | + ->withDataValueType('wikibase-entityid'); |
|
| 118 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $targetEntityId = $dataValue->getEntityId(); |
| 122 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
| 123 | - if ( !$targetEntity instanceof StatementListProvider ) { |
|
| 124 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
| 125 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 122 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
| 123 | + if (!$targetEntity instanceof StatementListProvider) { |
|
| 124 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
| 125 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /* |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * a) a property only |
| 131 | 131 | * b) a property and a number of items (each combination forming an individual claim) |
| 132 | 132 | */ |
| 133 | - if ( $items === [] ) { |
|
| 133 | + if ($items === []) { |
|
| 134 | 134 | $requiredStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
| 135 | 135 | $targetEntity->getStatements(), |
| 136 | 136 | $propertyId |
@@ -143,23 +143,23 @@ discard block |
||
| 143 | 143 | ); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if ( $requiredStatement !== null ) { |
|
| 146 | + if ($requiredStatement !== null) { |
|
| 147 | 147 | $status = CheckResult::STATUS_COMPLIANCE; |
| 148 | 148 | $message = null; |
| 149 | 149 | } else { |
| 150 | 150 | $status = CheckResult::STATUS_VIOLATION; |
| 151 | - $message = ( new ViolationMessage( 'wbqc-violation-message-target-required-claim' ) ) |
|
| 152 | - ->withEntityId( $targetEntityId, Role::SUBJECT ) |
|
| 153 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
| 154 | - ->withItemIdSnakValueList( $items, Role::OBJECT ); |
|
| 151 | + $message = (new ViolationMessage('wbqc-violation-message-target-required-claim')) |
|
| 152 | + ->withEntityId($targetEntityId, Role::SUBJECT) |
|
| 153 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
| 154 | + ->withItemIdSnakValueList($items, Role::OBJECT); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
| 158 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
| 159 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
| 157 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
| 158 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
| 159 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 162 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 163 | 163 | $constraintParameters = $constraint->getConstraintParameters(); |
| 164 | 164 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 165 | 165 | $exceptions = []; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | $constraintParameters, |
| 169 | 169 | $constraintTypeItemId |
| 170 | 170 | ); |
| 171 | - } catch ( ConstraintParameterException $e ) { |
|
| 171 | + } catch (ConstraintParameterException $e) { |
|
| 172 | 172 | $exceptions[] = $e; |
| 173 | 173 | } |
| 174 | 174 | try { |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $constraintTypeItemId, |
| 178 | 178 | false |
| 179 | 179 | ); |
| 180 | - } catch ( ConstraintParameterException $e ) { |
|
| 180 | + } catch (ConstraintParameterException $e) { |
|
| 181 | 181 | $exceptions[] = $e; |
| 182 | 182 | } |
| 183 | 183 | return $exceptions; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @codeCoverageIgnore This method is purely declarative. |
| 31 | 31 | */ |
| 32 | 32 | public function getDefaultContextTypes() { |
| 33 | - return [ Context::TYPE_STATEMENT ]; |
|
| 33 | + return [Context::TYPE_STATEMENT]; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -38,12 +38,12 @@ 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 | $referenceList = $context->getSnakStatement()->getReferences(); |
| 43 | 43 | |
| 44 | - if ( $referenceList->isEmpty() ) { |
|
| 45 | - $message = ( new ViolationMessage( 'wbqc-violation-message-citationNeeded' ) ) |
|
| 46 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
| 44 | + if ($referenceList->isEmpty()) { |
|
| 45 | + $message = (new ViolationMessage('wbqc-violation-message-citationNeeded')) |
|
| 46 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
| 47 | 47 | return new CheckResult( |
| 48 | 48 | $context, |
| 49 | 49 | $constraint, |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 55 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 58 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 59 | 59 | // no parameters |
| 60 | 60 | return []; |
| 61 | 61 | } |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | * @throws ConstraintParameterException |
| 58 | 58 | * @return CheckResult |
| 59 | 59 | */ |
| 60 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 61 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 62 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 60 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 61 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 62 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -76,20 +76,20 @@ discard block |
||
| 76 | 76 | $message = null; |
| 77 | 77 | $status = CheckResult::STATUS_COMPLIANCE; |
| 78 | 78 | |
| 79 | - foreach ( $items as $item ) { |
|
| 80 | - if ( $item->matchesSnak( $snak ) ) { |
|
| 81 | - $message = ( new ViolationMessage( 'wbqc-violation-message-none-of' ) ) |
|
| 82 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
| 83 | - ->withItemIdSnakValueList( $items, Role::OBJECT ); |
|
| 79 | + foreach ($items as $item) { |
|
| 80 | + if ($item->matchesSnak($snak)) { |
|
| 81 | + $message = (new ViolationMessage('wbqc-violation-message-none-of')) |
|
| 82 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
| 83 | + ->withItemIdSnakValueList($items, Role::OBJECT); |
|
| 84 | 84 | $status = CheckResult::STATUS_VIOLATION; |
| 85 | 85 | break; |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
| 89 | + return new CheckResult($context, $constraint, $status, $message); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 92 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 93 | 93 | $constraintParameters = $constraint->getConstraintParameters(); |
| 94 | 94 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 95 | 95 | $exceptions = []; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | $constraintTypeItemId, |
| 100 | 100 | true |
| 101 | 101 | ); |
| 102 | - } catch ( ConstraintParameterException $e ) { |
|
| 102 | + } catch (ConstraintParameterException $e) { |
|
| 103 | 103 | $exceptions[] = $e; |
| 104 | 104 | } |
| 105 | 105 | return $exceptions; |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | * @throws ConstraintParameterException |
| 58 | 58 | * @return CheckResult |
| 59 | 59 | */ |
| 60 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 61 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 62 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 60 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 61 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 62 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -73,23 +73,23 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $snak = $context->getSnak(); |
| 75 | 75 | |
| 76 | - $message = ( new ViolationMessage( 'wbqc-violation-message-one-of' ) ) |
|
| 77 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
| 78 | - ->withItemIdSnakValueList( $items, Role::OBJECT ); |
|
| 76 | + $message = (new ViolationMessage('wbqc-violation-message-one-of')) |
|
| 77 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
| 78 | + ->withItemIdSnakValueList($items, Role::OBJECT); |
|
| 79 | 79 | $status = CheckResult::STATUS_VIOLATION; |
| 80 | 80 | |
| 81 | - foreach ( $items as $item ) { |
|
| 82 | - if ( $item->matchesSnak( $snak ) ) { |
|
| 81 | + foreach ($items as $item) { |
|
| 82 | + if ($item->matchesSnak($snak)) { |
|
| 83 | 83 | $message = null; |
| 84 | 84 | $status = CheckResult::STATUS_COMPLIANCE; |
| 85 | 85 | break; |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
| 89 | + return new CheckResult($context, $constraint, $status, $message); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 92 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 93 | 93 | $constraintParameters = $constraint->getConstraintParameters(); |
| 94 | 94 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 95 | 95 | $exceptions = []; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | $constraintTypeItemId, |
| 100 | 100 | true |
| 101 | 101 | ); |
| 102 | - } catch ( ConstraintParameterException $e ) { |
|
| 102 | + } catch (ConstraintParameterException $e) { |
|
| 103 | 103 | $exceptions[] = $e; |
| 104 | 104 | } |
| 105 | 105 | return $exceptions; |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return CheckResult |
| 65 | 65 | */ |
| 66 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 67 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 68 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 66 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 67 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 68 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $separators = $this->constraintParameterParser->parseSeparatorsParameter( |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | $propertyId = $context->getSnak()->getPropertyId(); |
| 76 | 76 | $bestRankCount = $this->valueCountCheckerHelper->getPropertyCount( |
| 77 | - $context->getSnakGroup( Context::GROUP_BEST_RANK, $separators ), |
|
| 77 | + $context->getSnakGroup(Context::GROUP_BEST_RANK, $separators), |
|
| 78 | 78 | $propertyId |
| 79 | 79 | ); |
| 80 | 80 | |
| 81 | - if ( $bestRankCount > 1 ) { |
|
| 81 | + if ($bestRankCount > 1) { |
|
| 82 | 82 | $nonDeprecatedCount = $this->valueCountCheckerHelper->getPropertyCount( |
| 83 | - $context->getSnakGroup( Context::GROUP_NON_DEPRECATED ), |
|
| 83 | + $context->getSnakGroup(Context::GROUP_NON_DEPRECATED), |
|
| 84 | 84 | $propertyId |
| 85 | 85 | ); |
| 86 | 86 | $message = $this->getViolationMessage( |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | $status = CheckResult::STATUS_COMPLIANCE; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
| 98 | + return new CheckResult($context, $constraint, $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->parseSeparatorsParameter( $constraintParameters ); |
|
| 106 | - } catch ( ConstraintParameterException $e ) { |
|
| 105 | + $this->constraintParameterParser->parseSeparatorsParameter($constraintParameters); |
|
| 106 | + } catch (ConstraintParameterException $e) { |
|
| 107 | 107 | $exceptions[] = $e; |
| 108 | 108 | } |
| 109 | 109 | return $exceptions; |
@@ -122,23 +122,23 @@ discard block |
||
| 122 | 122 | $separators, |
| 123 | 123 | $propertyId |
| 124 | 124 | ) { |
| 125 | - if ( $bestRankCount === $nonDeprecatedCount ) { |
|
| 126 | - if ( $separators === [] ) { |
|
| 125 | + if ($bestRankCount === $nonDeprecatedCount) { |
|
| 126 | + if ($separators === []) { |
|
| 127 | 127 | $messageKey = 'wbqc-violation-message-single-best-value-no-preferred'; |
| 128 | 128 | } else { |
| 129 | 129 | $messageKey = 'wbqc-violation-message-single-best-value-no-preferred-separators'; |
| 130 | 130 | } |
| 131 | 131 | } else { |
| 132 | - if ( $separators === [] ) { |
|
| 132 | + if ($separators === []) { |
|
| 133 | 133 | $messageKey = 'wbqc-violation-message-single-best-value-multi-preferred'; |
| 134 | 134 | } else { |
| 135 | 135 | $messageKey = 'wbqc-violation-message-single-best-value-multi-preferred-separators'; |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - return ( new ViolationMessage( $messageKey ) ) |
|
| 140 | - ->withEntityId( $propertyId ) |
|
| 141 | - ->withEntityIdList( $separators ); |
|
| 139 | + return (new ViolationMessage($messageKey)) |
|
| 140 | + ->withEntityId($propertyId) |
|
| 141 | + ->withEntityIdList($separators); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | } |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
| 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 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -106,18 +106,18 @@ discard block |
||
| 106 | 106 | $constraintTypeItemId |
| 107 | 107 | ); |
| 108 | 108 | $relationIds = []; |
| 109 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
| 110 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
| 109 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
| 110 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
| 111 | 111 | } |
| 112 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
| 113 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
| 112 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
| 113 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | $snak = $context->getSnak(); |
| 117 | 117 | |
| 118 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 118 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 119 | 119 | // nothing to check |
| 120 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 120 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $dataValue = $snak->getDataValue(); |
@@ -126,23 +126,23 @@ discard block |
||
| 126 | 126 | * error handling: |
| 127 | 127 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
| 128 | 128 | */ |
| 129 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
| 130 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
| 131 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 132 | - ->withDataValueType( 'wikibase-entityid' ); |
|
| 133 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 129 | + if (!$dataValue instanceof EntityIdValue) { |
|
| 130 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
| 131 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 132 | + ->withDataValueType('wikibase-entityid'); |
|
| 133 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | try { |
| 137 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
| 138 | - } catch ( UnresolvedEntityRedirectException $e ) { |
|
| 137 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
| 138 | + } catch (UnresolvedEntityRedirectException $e) { |
|
| 139 | 139 | // Edge case (double redirect): Pretend the entity doesn't exist |
| 140 | 140 | $item = null; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if ( !( $item instanceof StatementListProvidingEntity ) ) { |
|
| 144 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
| 145 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 143 | + if (!($item instanceof StatementListProvidingEntity)) { |
|
| 144 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
| 145 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $statements = $item->getStatements(); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $classes |
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | - if ( $result->getBool() ) { |
|
| 156 | + if ($result->getBool()) { |
|
| 157 | 157 | $message = null; |
| 158 | 158 | $status = CheckResult::STATUS_COMPLIANCE; |
| 159 | 159 | } else { |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | $status = CheckResult::STATUS_VIOLATION; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
| 171 | - ->withMetadata( $result->getMetadata() ); |
|
| 170 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
| 171 | + ->withMetadata($result->getMetadata()); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 174 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 175 | 175 | $constraintParameters = $constraint->getConstraintParameters(); |
| 176 | 176 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 177 | 177 | $exceptions = []; |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $constraintParameters, |
| 181 | 181 | $constraintTypeItemId |
| 182 | 182 | ); |
| 183 | - } catch ( ConstraintParameterException $e ) { |
|
| 183 | + } catch (ConstraintParameterException $e) { |
|
| 184 | 184 | $exceptions[] = $e; |
| 185 | 185 | } |
| 186 | 186 | try { |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $constraintParameters, |
| 189 | 189 | $constraintTypeItemId |
| 190 | 190 | ); |
| 191 | - } catch ( ConstraintParameterException $e ) { |
|
| 191 | + } catch (ConstraintParameterException $e) { |
|
| 192 | 192 | $exceptions[] = $e; |
| 193 | 193 | } |
| 194 | 194 | return $exceptions; |
@@ -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; |