Completed
Push — master ( e8870b...f09e1e )
by
unknown
02:51 queued 10s
created
src/ConstraintCheck/Checker/ValueTypeChecker.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -91,37 +91,37 @@  discard block
 block discarded – undo
91 91
 	 * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs
92 92
 	 * @return CheckResult
93 93
 	 */
94
-	public function checkConstraint( Context $context, Constraint $constraint ) {
95
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
96
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
94
+	public function checkConstraint(Context $context, Constraint $constraint) {
95
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
96
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
97 97
 		}
98 98
 
99 99
 		$parameters = [];
100 100
 		$constraintParameters = $constraint->getConstraintParameters();
101 101
 
102
-		$classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
102
+		$classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId());
103 103
 		$parameters['class'] = array_map(
104
-			function( $id ) {
105
-				return new ItemId( $id );
104
+			function($id) {
105
+				return new ItemId($id);
106 106
 			},
107 107
 			$classes
108 108
 		);
109 109
 
110
-		$relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
110
+		$relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId());
111 111
 		$relationIds = [];
112
-		if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) {
113
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
112
+		if ($relation === 'instance' || $relation === 'instanceOrSubclass') {
113
+			$relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId');
114 114
 		}
115
-		if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) {
116
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
115
+		if ($relation === 'subclass' || $relation === 'instanceOrSubclass') {
116
+			$relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId');
117 117
 		}
118
-		$parameters['relation'] = [ $relation ];
118
+		$parameters['relation'] = [$relation];
119 119
 
120 120
 		$snak = $context->getSnak();
121 121
 
122
-		if ( !$snak instanceof PropertyValueSnak ) {
122
+		if (!$snak instanceof PropertyValueSnak) {
123 123
 			// nothing to check
124
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
124
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
125 125
 		}
126 126
 
127 127
 		$dataValue = $snak->getDataValue();
@@ -130,24 +130,24 @@  discard block
 block discarded – undo
130 130
 		 * error handling:
131 131
 		 *   type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid'
132 132
 		 */
133
-		if ( $dataValue->getType() !== 'wikibase-entityid' ) {
134
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
135
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
136
-				->withDataValueType( 'wikibase-entityid' );
137
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
133
+		if ($dataValue->getType() !== 'wikibase-entityid') {
134
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
135
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
136
+				->withDataValueType('wikibase-entityid');
137
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
138 138
 		}
139 139
 		/** @var EntityIdValue $dataValue */
140 140
 
141 141
 		try {
142
-			$item = $this->entityLookup->getEntity( $dataValue->getEntityId() );
143
-		} catch ( UnresolvedEntityRedirectException $e ) {
142
+			$item = $this->entityLookup->getEntity($dataValue->getEntityId());
143
+		} catch (UnresolvedEntityRedirectException $e) {
144 144
 			// Edge case (double redirect): Pretend the entity doesn't exist
145 145
 			$item = null;
146 146
 		}
147 147
 
148
-		if ( !( $item instanceof StatementListProvider ) ) {
149
-			$message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' );
150
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
148
+		if (!($item instanceof StatementListProvider)) {
149
+			$message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist');
150
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
151 151
 		}
152 152
 
153 153
 		$statements = $item->getStatements();
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 			$classes
159 159
 		);
160 160
 
161
-		if ( $result->getBool() ) {
161
+		if ($result->getBool()) {
162 162
 			$message = null;
163 163
 			$status = CheckResult::STATUS_COMPLIANCE;
164 164
 		} else {
@@ -172,21 +172,21 @@  discard block
 block discarded – undo
172 172
 			$status = CheckResult::STATUS_VIOLATION;
173 173
 		}
174 174
 
175
-		return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) )
176
-			->withMetadata( $result->getMetadata() );
175
+		return (new CheckResult($context, $constraint, $parameters, $status, $message))
176
+			->withMetadata($result->getMetadata());
177 177
 	}
178 178
 
179
-	public function checkConstraintParameters( Constraint $constraint ) {
179
+	public function checkConstraintParameters(Constraint $constraint) {
180 180
 		$constraintParameters = $constraint->getConstraintParameters();
181 181
 		$exceptions = [];
182 182
 		try {
183
-			$this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
184
-		} catch ( ConstraintParameterException $e ) {
183
+			$this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId());
184
+		} catch (ConstraintParameterException $e) {
185 185
 			$exceptions[] = $e;
186 186
 		}
187 187
 		try {
188
-			$this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
189
-		} catch ( ConstraintParameterException $e ) {
188
+			$this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId());
189
+		} catch (ConstraintParameterException $e) {
190 190
 			$exceptions[] = $e;
191 191
 		}
192 192
 		return $exceptions;
Please login to merge, or discard this patch.