Completed
Push — master ( 368b39...82a3c0 )
by
unknown
11:54
created
src/ConstraintCheck/Helper/ConstraintParameterParser.php 1 patch
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -88,15 +88,15 @@  discard block
 block discarded – undo
88 88
 	 * @param array $parameters
89 89
 	 * @throws ConstraintParameterException
90 90
 	 */
91
-	public function checkError( array $parameters ) {
92
-		if ( array_key_exists( '@error', $parameters ) ) {
91
+	public function checkError(array $parameters) {
92
+		if (array_key_exists('@error', $parameters)) {
93 93
 			$error = $parameters['@error'];
94
-			if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) {
94
+			if (array_key_exists('toolong', $error) && $error['toolong']) {
95 95
 				$msg = 'wbqc-violation-message-parameters-error-toolong';
96 96
 			} else {
97 97
 				$msg = 'wbqc-violation-message-parameters-error-unknown';
98 98
 			}
99
-			throw new ConstraintParameterException( new ViolationMessage( $msg ) );
99
+			throw new ConstraintParameterException(new ViolationMessage($msg));
100 100
 		}
101 101
 	}
102 102
 
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 	 * @param string $parameterId
107 107
 	 * @throws ConstraintParameterException
108 108
 	 */
109
-	private function requireSingleParameter( array $parameters, $parameterId ) {
110
-		if ( count( $parameters[$parameterId] ) !== 1 ) {
109
+	private function requireSingleParameter(array $parameters, $parameterId) {
110
+		if (count($parameters[$parameterId]) !== 1) {
111 111
 			throw new ConstraintParameterException(
112
-				( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) )
113
-					->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
112
+				(new ViolationMessage('wbqc-violation-message-parameter-single'))
113
+					->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
114 114
 			);
115 115
 		}
116 116
 	}
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
 	 * @return void
123 123
 	 * @throws ConstraintParameterException
124 124
 	 */
125
-	private function requireValueParameter( Snak $snak, $parameterId ) {
126
-		if ( !( $snak instanceof PropertyValueSnak ) ) {
125
+	private function requireValueParameter(Snak $snak, $parameterId) {
126
+		if (!($snak instanceof PropertyValueSnak)) {
127 127
 			throw new ConstraintParameterException(
128
-				( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) )
129
-					->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
128
+				(new ViolationMessage('wbqc-violation-message-parameter-value'))
129
+					->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
130 130
 			);
131 131
 		}
132 132
 	}
@@ -138,17 +138,17 @@  discard block
 block discarded – undo
138 138
 	 * @throws ConstraintParameterException
139 139
 	 * @return EntityId
140 140
 	 */
141
-	private function parseEntityIdParameter( array $snakSerialization, $parameterId ) {
142
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
143
-		$this->requireValueParameter( $snak, $parameterId );
141
+	private function parseEntityIdParameter(array $snakSerialization, $parameterId) {
142
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
143
+		$this->requireValueParameter($snak, $parameterId);
144 144
 		$value = $snak->getDataValue();
145
-		if ( $value instanceof EntityIdValue ) {
145
+		if ($value instanceof EntityIdValue) {
146 146
 			return $value->getEntityId();
147 147
 		} else {
148 148
 			throw new ConstraintParameterException(
149
-				( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) )
150
-					->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
151
-					->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
149
+				(new ViolationMessage('wbqc-violation-message-parameter-entity'))
150
+					->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
151
+					->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
152 152
 			);
153 153
 		}
154 154
 	}
@@ -159,20 +159,20 @@  discard block
 block discarded – undo
159 159
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
160 160
 	 * @return string[] class entity ID serializations
161 161
 	 */
162
-	public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) {
163
-		$this->checkError( $constraintParameters );
164
-		$classId = $this->config->get( 'WBQualityConstraintsClassId' );
165
-		if ( !array_key_exists( $classId, $constraintParameters ) ) {
162
+	public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) {
163
+		$this->checkError($constraintParameters);
164
+		$classId = $this->config->get('WBQualityConstraintsClassId');
165
+		if (!array_key_exists($classId, $constraintParameters)) {
166 166
 			throw new ConstraintParameterException(
167
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
168
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
169
-					->withEntityId( new PropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
167
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
168
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
169
+					->withEntityId(new PropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY)
170 170
 			);
171 171
 		}
172 172
 
173 173
 		$classes = [];
174
-		foreach ( $constraintParameters[$classId] as $class ) {
175
-			$classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization();
174
+		foreach ($constraintParameters[$classId] as $class) {
175
+			$classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization();
176 176
 		}
177 177
 		return $classes;
178 178
 	}
@@ -183,23 +183,23 @@  discard block
 block discarded – undo
183 183
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
184 184
 	 * @return string 'instance', 'subclass', or 'instanceOrSubclass'
185 185
 	 */
186
-	public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) {
187
-		$this->checkError( $constraintParameters );
188
-		$relationId = $this->config->get( 'WBQualityConstraintsRelationId' );
189
-		if ( !array_key_exists( $relationId, $constraintParameters ) ) {
186
+	public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) {
187
+		$this->checkError($constraintParameters);
188
+		$relationId = $this->config->get('WBQualityConstraintsRelationId');
189
+		if (!array_key_exists($relationId, $constraintParameters)) {
190 190
 			throw new ConstraintParameterException(
191
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
192
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
193
-					->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
191
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
192
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
193
+					->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY)
194 194
 			);
195 195
 		}
196 196
 
197
-		$this->requireSingleParameter( $constraintParameters, $relationId );
198
-		$relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId );
199
-		$instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' );
200
-		$subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' );
201
-		$instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' );
202
-		switch ( $relationEntityId ) {
197
+		$this->requireSingleParameter($constraintParameters, $relationId);
198
+		$relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId);
199
+		$instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId');
200
+		$subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId');
201
+		$instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId');
202
+		switch ($relationEntityId) {
203 203
 			case $instanceId:
204 204
 				return 'instance';
205 205
 			case $subclassId:
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
 				return 'instanceOrSubclass';
209 209
 			default:
210 210
 				throw new ConstraintParameterException(
211
-					( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
212
-						->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
211
+					(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
212
+						->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY)
213 213
 						->withEntityIdList(
214 214
 							[
215
-								new ItemId( $instanceId ),
216
-								new ItemId( $subclassId ),
217
-								new ItemId( $instanceOrSubclassId ),
215
+								new ItemId($instanceId),
216
+								new ItemId($subclassId),
217
+								new ItemId($instanceOrSubclassId),
218 218
 							],
219 219
 							Role::CONSTRAINT_PARAMETER_VALUE
220 220
 						)
@@ -229,20 +229,20 @@  discard block
 block discarded – undo
229 229
 	 * @throws ConstraintParameterException
230 230
 	 * @return PropertyId
231 231
 	 */
232
-	private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) {
233
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
234
-		$this->requireValueParameter( $snak, $parameterId );
232
+	private function parsePropertyIdParameter(array $snakSerialization, $parameterId) {
233
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
234
+		$this->requireValueParameter($snak, $parameterId);
235 235
 		$value = $snak->getDataValue();
236
-		if ( $value instanceof EntityIdValue ) {
236
+		if ($value instanceof EntityIdValue) {
237 237
 			$id = $value->getEntityId();
238
-			if ( $id instanceof PropertyId ) {
238
+			if ($id instanceof PropertyId) {
239 239
 				return $id;
240 240
 			}
241 241
 		}
242 242
 		throw new ConstraintParameterException(
243
-			( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) )
244
-				->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
245
-				->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
243
+			(new ViolationMessage('wbqc-violation-message-parameter-property'))
244
+				->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
245
+				->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
246 246
 		);
247 247
 	}
248 248
 
@@ -253,32 +253,32 @@  discard block
 block discarded – undo
253 253
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
254 254
 	 * @return PropertyId
255 255
 	 */
256
-	public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) {
257
-		$this->checkError( $constraintParameters );
258
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
259
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
256
+	public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) {
257
+		$this->checkError($constraintParameters);
258
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
259
+		if (!array_key_exists($propertyId, $constraintParameters)) {
260 260
 			throw new ConstraintParameterException(
261
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
262
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
263
-					->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
261
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
262
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
263
+					->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
264 264
 			);
265 265
 		}
266 266
 
267
-		$this->requireSingleParameter( $constraintParameters, $propertyId );
268
-		return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId );
267
+		$this->requireSingleParameter($constraintParameters, $propertyId);
268
+		return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId);
269 269
 	}
270 270
 
271
-	private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) {
271
+	private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) {
272 272
 		$dataValue = $snak->getDataValue();
273
-		if ( $dataValue instanceof EntityIdValue &&
273
+		if ($dataValue instanceof EntityIdValue &&
274 274
 			$dataValue->getEntityId() instanceof ItemId
275 275
 		) {
276
-			return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() );
276
+			return ItemIdSnakValue::fromItemId($dataValue->getEntityId());
277 277
 		} else {
278 278
 			throw new ConstraintParameterException(
279
-				( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) )
280
-					->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
281
-					->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
279
+				(new ViolationMessage('wbqc-violation-message-parameter-item'))
280
+					->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
281
+					->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
282 282
 			);
283 283
 		}
284 284
 	}
@@ -290,15 +290,15 @@  discard block
 block discarded – undo
290 290
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
291 291
 	 * @return ItemIdSnakValue[] array of values
292 292
 	 */
293
-	public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) {
294
-		$this->checkError( $constraintParameters );
295
-		$qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
296
-		if ( !array_key_exists( $qualifierId, $constraintParameters ) ) {
297
-			if ( $required ) {
293
+	public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) {
294
+		$this->checkError($constraintParameters);
295
+		$qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
296
+		if (!array_key_exists($qualifierId, $constraintParameters)) {
297
+			if ($required) {
298 298
 				throw new ConstraintParameterException(
299
-					( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
300
-						->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
301
-						->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
299
+					(new ViolationMessage('wbqc-violation-message-parameter-needed'))
300
+						->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
301
+						->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY)
302 302
 				);
303 303
 			} else {
304 304
 				return [];
@@ -306,11 +306,11 @@  discard block
 block discarded – undo
306 306
 		}
307 307
 
308 308
 		$values = [];
309
-		foreach ( $constraintParameters[$qualifierId] as $parameter ) {
310
-			$snak = $this->snakDeserializer->deserialize( $parameter );
311
-			switch ( true ) {
309
+		foreach ($constraintParameters[$qualifierId] as $parameter) {
310
+			$snak = $this->snakDeserializer->deserialize($parameter);
311
+			switch (true) {
312 312
 				case $snak instanceof PropertyValueSnak:
313
-					$values[] = $this->parseItemIdParameter( $snak, $qualifierId );
313
+					$values[] = $this->parseItemIdParameter($snak, $qualifierId);
314 314
 					break;
315 315
 				case $snak instanceof PropertySomeValueSnak:
316 316
 					$values[] = ItemIdSnakValue::someValue();
@@ -329,27 +329,27 @@  discard block
 block discarded – undo
329 329
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
330 330
 	 * @return PropertyId[]
331 331
 	 */
332
-	public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) {
333
-		$this->checkError( $constraintParameters );
334
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
335
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
332
+	public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) {
333
+		$this->checkError($constraintParameters);
334
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
335
+		if (!array_key_exists($propertyId, $constraintParameters)) {
336 336
 			throw new ConstraintParameterException(
337
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
338
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
339
-					->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
337
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
338
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
339
+					->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
340 340
 			);
341 341
 		}
342 342
 
343 343
 		$parameters = $constraintParameters[$propertyId];
344
-		if ( count( $parameters ) === 1 &&
345
-			$this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak
344
+		if (count($parameters) === 1 &&
345
+			$this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak
346 346
 		) {
347 347
 			return [];
348 348
 		}
349 349
 
350 350
 		$properties = [];
351
-		foreach ( $parameters as $parameter ) {
352
-			$properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId );
351
+		foreach ($parameters as $parameter) {
352
+			$properties[] = $this->parsePropertyIdParameter($parameter, $propertyId);
353 353
 		}
354 354
 		return $properties;
355 355
 	}
@@ -360,16 +360,16 @@  discard block
 block discarded – undo
360 360
 	 * @throws ConstraintParameterException
361 361
 	 * @return DataValue|null
362 362
 	 */
363
-	private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) {
364
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
365
-		if ( $snak instanceof PropertyValueSnak ) {
363
+	private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) {
364
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
365
+		if ($snak instanceof PropertyValueSnak) {
366 366
 			return $snak->getDataValue();
367
-		} elseif ( $snak instanceof PropertyNoValueSnak ) {
367
+		} elseif ($snak instanceof PropertyNoValueSnak) {
368 368
 			return null;
369 369
 		} else {
370 370
 			throw new ConstraintParameterException(
371
-				( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) )
372
-					->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
371
+				(new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue'))
372
+					->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
373 373
 			);
374 374
 		}
375 375
 	}
@@ -379,10 +379,10 @@  discard block
 block discarded – undo
379 379
 	 * @param string $parameterId
380 380
 	 * @return DataValue|null
381 381
 	 */
382
-	private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) {
382
+	private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) {
383 383
 		try {
384
-			return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId );
385
-		} catch ( ConstraintParameterException $e ) {
384
+			return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId);
385
+		} catch (ConstraintParameterException $e) {
386 386
 			// unknown value means “now”
387 387
 			return new NowValue();
388 388
 		}
@@ -395,14 +395,14 @@  discard block
 block discarded – undo
395 395
 	 * @param string $unit
396 396
 	 * @return bool
397 397
 	 */
398
-	private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) {
399
-		if ( !( $min instanceof UnboundedQuantityValue ) ||
400
-			!( $max instanceof UnboundedQuantityValue )
398
+	private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) {
399
+		if (!($min instanceof UnboundedQuantityValue) ||
400
+			!($max instanceof UnboundedQuantityValue)
401 401
 		) {
402 402
 			return false;
403 403
 		}
404 404
 
405
-		return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit );
405
+		return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit);
406 406
 	}
407 407
 
408 408
 	/**
@@ -415,42 +415,42 @@  discard block
 block discarded – undo
415 415
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
416 416
 	 * @return DataValue[] if the parameter is invalid or missing
417 417
 	 */
418
-	private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) {
419
-		$this->checkError( $constraintParameters );
420
-		if ( !array_key_exists( $minimumId, $constraintParameters ) ||
421
-			!array_key_exists( $maximumId, $constraintParameters )
418
+	private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) {
419
+		$this->checkError($constraintParameters);
420
+		if (!array_key_exists($minimumId, $constraintParameters) ||
421
+			!array_key_exists($maximumId, $constraintParameters)
422 422
 		) {
423 423
 			throw new ConstraintParameterException(
424
-				( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) )
425
-					->withDataValueType( $type )
426
-					->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
427
-					->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
428
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
424
+				(new ViolationMessage('wbqc-violation-message-range-parameters-needed'))
425
+					->withDataValueType($type)
426
+					->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
427
+					->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
428
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
429 429
 			);
430 430
 		}
431 431
 
432
-		$this->requireSingleParameter( $constraintParameters, $minimumId );
433
-		$this->requireSingleParameter( $constraintParameters, $maximumId );
432
+		$this->requireSingleParameter($constraintParameters, $minimumId);
433
+		$this->requireSingleParameter($constraintParameters, $maximumId);
434 434
 		$parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter';
435
-		$min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId );
436
-		$max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId );
435
+		$min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId);
436
+		$max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId);
437 437
 
438
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
439
-		if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) {
438
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
439
+		if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) {
440 440
 			throw new ConstraintParameterException(
441
-				new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' )
441
+				new ViolationMessage('wbqc-violation-message-range-parameters-one-year')
442 442
 			);
443 443
 		}
444
-		if ( $min === null && $max === null ||
445
-			$min !== null && $max !== null && $min->equals( $max ) ) {
444
+		if ($min === null && $max === null ||
445
+			$min !== null && $max !== null && $min->equals($max)) {
446 446
 			throw new ConstraintParameterException(
447
-				( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) )
448
-					->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
449
-					->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
447
+				(new ViolationMessage('wbqc-violation-message-range-parameters-same'))
448
+					->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
449
+					->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
450 450
 			);
451 451
 		}
452 452
 
453
-		return [ $min, $max ];
453
+		return [$min, $max];
454 454
 	}
455 455
 
456 456
 	/**
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
461 461
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
462 462
 	 */
463
-	public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) {
463
+	public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) {
464 464
 		return $this->parseRangeParameter(
465 465
 			$constraintParameters,
466
-			$this->config->get( 'WBQualityConstraintsMinimumQuantityId' ),
467
-			$this->config->get( 'WBQualityConstraintsMaximumQuantityId' ),
466
+			$this->config->get('WBQualityConstraintsMinimumQuantityId'),
467
+			$this->config->get('WBQualityConstraintsMaximumQuantityId'),
468 468
 			$constraintTypeItemId,
469 469
 			'quantity'
470 470
 		);
@@ -477,11 +477,11 @@  discard block
 block discarded – undo
477 477
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
478 478
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
479 479
 	 */
480
-	public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) {
480
+	public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) {
481 481
 		return $this->parseRangeParameter(
482 482
 			$constraintParameters,
483
-			$this->config->get( 'WBQualityConstraintsMinimumDateId' ),
484
-			$this->config->get( 'WBQualityConstraintsMaximumDateId' ),
483
+			$this->config->get('WBQualityConstraintsMinimumDateId'),
484
+			$this->config->get('WBQualityConstraintsMaximumDateId'),
485 485
 			$constraintTypeItemId,
486 486
 			'time'
487 487
 		);
@@ -494,17 +494,17 @@  discard block
 block discarded – undo
494 494
 	 * @throws ConstraintParameterException
495 495
 	 * @return string
496 496
 	 */
497
-	private function parseStringParameter( array $snakSerialization, $parameterId ) {
498
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
499
-		$this->requireValueParameter( $snak, $parameterId );
497
+	private function parseStringParameter(array $snakSerialization, $parameterId) {
498
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
499
+		$this->requireValueParameter($snak, $parameterId);
500 500
 		$value = $snak->getDataValue();
501
-		if ( $value instanceof StringValue ) {
501
+		if ($value instanceof StringValue) {
502 502
 			return $value->getValue();
503 503
 		} else {
504 504
 			throw new ConstraintParameterException(
505
-				( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) )
506
-					->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
507
-					->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
505
+				(new ViolationMessage('wbqc-violation-message-parameter-string'))
506
+					->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
507
+					->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
508 508
 			);
509 509
 		}
510 510
 	}
@@ -515,15 +515,15 @@  discard block
 block discarded – undo
515 515
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
516 516
 	 * @return string
517 517
 	 */
518
-	public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) {
519
-		$this->checkError( $constraintParameters );
520
-		$namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' );
521
-		if ( !array_key_exists( $namespaceId, $constraintParameters ) ) {
518
+	public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) {
519
+		$this->checkError($constraintParameters);
520
+		$namespaceId = $this->config->get('WBQualityConstraintsNamespaceId');
521
+		if (!array_key_exists($namespaceId, $constraintParameters)) {
522 522
 			return '';
523 523
 		}
524 524
 
525
-		$this->requireSingleParameter( $constraintParameters, $namespaceId );
526
-		return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId );
525
+		$this->requireSingleParameter($constraintParameters, $namespaceId);
526
+		return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId);
527 527
 	}
528 528
 
529 529
 	/**
@@ -532,19 +532,19 @@  discard block
 block discarded – undo
532 532
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
533 533
 	 * @return string
534 534
 	 */
535
-	public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) {
536
-		$this->checkError( $constraintParameters );
537
-		$formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' );
538
-		if ( !array_key_exists( $formatId, $constraintParameters ) ) {
535
+	public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) {
536
+		$this->checkError($constraintParameters);
537
+		$formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId');
538
+		if (!array_key_exists($formatId, $constraintParameters)) {
539 539
 			throw new ConstraintParameterException(
540
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
541
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
542
-					->withEntityId( new PropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
540
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
541
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
542
+					->withEntityId(new PropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY)
543 543
 			);
544 544
 		}
545 545
 
546
-		$this->requireSingleParameter( $constraintParameters, $formatId );
547
-		return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId );
546
+		$this->requireSingleParameter($constraintParameters, $formatId);
547
+		return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId);
548 548
 	}
549 549
 
550 550
 	/**
@@ -552,16 +552,16 @@  discard block
 block discarded – undo
552 552
 	 * @throws ConstraintParameterException if the parameter is invalid
553 553
 	 * @return EntityId[]
554 554
 	 */
555
-	public function parseExceptionParameter( array $constraintParameters ) {
556
-		$this->checkError( $constraintParameters );
557
-		$exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' );
558
-		if ( !array_key_exists( $exceptionId, $constraintParameters ) ) {
555
+	public function parseExceptionParameter(array $constraintParameters) {
556
+		$this->checkError($constraintParameters);
557
+		$exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId');
558
+		if (!array_key_exists($exceptionId, $constraintParameters)) {
559 559
 			return [];
560 560
 		}
561 561
 
562 562
 		return array_map(
563
-			function( $snakSerialization ) use ( $exceptionId ) {
564
-				return $this->parseEntityIdParameter( $snakSerialization, $exceptionId );
563
+			function($snakSerialization) use ($exceptionId) {
564
+				return $this->parseEntityIdParameter($snakSerialization, $exceptionId);
565 565
 			},
566 566
 			$constraintParameters[$exceptionId]
567 567
 		);
@@ -572,26 +572,26 @@  discard block
 block discarded – undo
572 572
 	 * @throws ConstraintParameterException if the parameter is invalid
573 573
 	 * @return string|null 'mandatory' or null
574 574
 	 */
575
-	public function parseConstraintStatusParameter( array $constraintParameters ) {
576
-		$this->checkError( $constraintParameters );
577
-		$constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' );
578
-		if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) {
575
+	public function parseConstraintStatusParameter(array $constraintParameters) {
576
+		$this->checkError($constraintParameters);
577
+		$constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId');
578
+		if (!array_key_exists($constraintStatusId, $constraintParameters)) {
579 579
 			return null;
580 580
 		}
581 581
 
582
-		$mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' );
583
-		$this->requireSingleParameter( $constraintParameters, $constraintStatusId );
584
-		$snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] );
585
-		$this->requireValueParameter( $snak, $constraintStatusId );
582
+		$mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId');
583
+		$this->requireSingleParameter($constraintParameters, $constraintStatusId);
584
+		$snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]);
585
+		$this->requireValueParameter($snak, $constraintStatusId);
586 586
 		$statusId = $snak->getDataValue()->getEntityId()->getSerialization();
587 587
 
588
-		if ( $statusId === $mandatoryId ) {
588
+		if ($statusId === $mandatoryId) {
589 589
 			return 'mandatory';
590 590
 		} else {
591 591
 			throw new ConstraintParameterException(
592
-				( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
593
-					->withEntityId( new PropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
594
-					->withEntityIdList( [ new ItemId( $mandatoryId ) ], Role::CONSTRAINT_PARAMETER_VALUE )
592
+				(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
593
+					->withEntityId(new PropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY)
594
+					->withEntityIdList([new ItemId($mandatoryId)], Role::CONSTRAINT_PARAMETER_VALUE)
595 595
 			);
596 596
 		}
597 597
 	}
@@ -603,12 +603,12 @@  discard block
 block discarded – undo
603 603
 	 * @return void
604 604
 	 * @throws ConstraintParameterException
605 605
 	 */
606
-	private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) {
607
-		if ( !( $dataValue instanceof MonolingualTextValue ) ) {
606
+	private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) {
607
+		if (!($dataValue instanceof MonolingualTextValue)) {
608 608
 			throw new ConstraintParameterException(
609
-				( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) )
610
-					->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
611
-					->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
609
+				(new ViolationMessage('wbqc-violation-message-parameter-monolingualtext'))
610
+					->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
611
+					->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
612 612
 			);
613 613
 		}
614 614
 	}
@@ -621,30 +621,30 @@  discard block
 block discarded – undo
621 621
 	 * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts
622 622
 	 * @return MultilingualTextValue
623 623
 	 */
624
-	private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) {
624
+	private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) {
625 625
 		$result = [];
626 626
 
627
-		foreach ( $snakSerializations as $snakSerialization ) {
628
-			$snak = $this->snakDeserializer->deserialize( $snakSerialization );
629
-			$this->requireValueParameter( $snak, $parameterId );
627
+		foreach ($snakSerializations as $snakSerialization) {
628
+			$snak = $this->snakDeserializer->deserialize($snakSerialization);
629
+			$this->requireValueParameter($snak, $parameterId);
630 630
 
631 631
 			$value = $snak->getDataValue();
632
-			$this->requireMonolingualTextParameter( $value, $parameterId );
632
+			$this->requireMonolingualTextParameter($value, $parameterId);
633 633
 			/** @var MonolingualTextValue $value */
634 634
 
635 635
 			$code = $value->getLanguageCode();
636
-			if ( array_key_exists( $code, $result ) ) {
636
+			if (array_key_exists($code, $result)) {
637 637
 				throw new ConstraintParameterException(
638
-					( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) )
639
-						->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
640
-						->withLanguage( $code )
638
+					(new ViolationMessage('wbqc-violation-message-parameter-single-per-language'))
639
+						->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
640
+						->withLanguage($code)
641 641
 				);
642 642
 			}
643 643
 
644 644
 			$result[$code] = $value;
645 645
 		}
646 646
 
647
-		return new MultilingualTextValue( $result );
647
+		return new MultilingualTextValue($result);
648 648
 	}
649 649
 
650 650
 	/**
@@ -652,11 +652,11 @@  discard block
 block discarded – undo
652 652
 	 * @throws ConstraintParameterException if the parameter is invalid
653 653
 	 * @return MultilingualTextValue
654 654
 	 */
655
-	public function parseSyntaxClarificationParameter( array $constraintParameters ) {
656
-		$syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' );
655
+	public function parseSyntaxClarificationParameter(array $constraintParameters) {
656
+		$syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId');
657 657
 
658
-		if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) {
659
-			return new MultilingualTextValue( [] );
658
+		if (!array_key_exists($syntaxClarificationId, $constraintParameters)) {
659
+			return new MultilingualTextValue([]);
660 660
 		}
661 661
 
662 662
 		$syntaxClarifications = $this->parseMultilingualTextParameter(
@@ -675,20 +675,20 @@  discard block
 block discarded – undo
675 675
 	 * @throws ConstraintParameterException if the parameter is invalid
676 676
 	 * @return string[]|null Context::TYPE_* constants
677 677
 	 */
678
-	public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) {
679
-		$constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' );
680
-		$mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' );
681
-		$qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' );
682
-		$referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' );
678
+	public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) {
679
+		$constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId');
680
+		$mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId');
681
+		$qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId');
682
+		$referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId');
683 683
 
684
-		if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) {
684
+		if (!array_key_exists($constraintScopeId, $constraintParameters)) {
685 685
 			return null;
686 686
 		}
687 687
 
688 688
 		$contextTypes = [];
689
-		foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) {
690
-			$scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId );
691
-			switch ( $scopeEntityId->getSerialization() ) {
689
+		foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) {
690
+			$scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId);
691
+			switch ($scopeEntityId->getSerialization()) {
692 692
 				case $mainSnakId:
693 693
 					$contextTypes[] = Context::TYPE_STATEMENT;
694 694
 					break;
@@ -700,13 +700,13 @@  discard block
 block discarded – undo
700 700
 					break;
701 701
 				default:
702 702
 					throw new ConstraintParameterException(
703
-						( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
704
-							->withEntityId( new PropertyId( $constraintScopeId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
703
+						(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
704
+							->withEntityId(new PropertyId($constraintScopeId), Role::CONSTRAINT_PARAMETER_PROPERTY)
705 705
 							->withEntityIdList(
706 706
 								[
707
-									new ItemId( $mainSnakId ),
708
-									new ItemId( $qualifiersId ),
709
-									new ItemId( $referencesId ),
707
+									new ItemId($mainSnakId),
708
+									new ItemId($qualifiersId),
709
+									new ItemId($referencesId),
710 710
 								],
711 711
 								Role::CONSTRAINT_PARAMETER_VALUE
712 712
 							)
@@ -714,15 +714,15 @@  discard block
 block discarded – undo
714 714
 			}
715 715
 		}
716 716
 
717
-		if ( $validScopes !== null ) {
718
-			$invalidScopes = array_diff( $contextTypes, $validScopes );
719
-			if ( $invalidScopes !== [] ) {
720
-				$invalidScope = array_pop( $invalidScopes );
717
+		if ($validScopes !== null) {
718
+			$invalidScopes = array_diff($contextTypes, $validScopes);
719
+			if ($invalidScopes !== []) {
720
+				$invalidScope = array_pop($invalidScopes);
721 721
 				throw new ConstraintParameterException(
722
-					( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) )
723
-						->withConstraintScope( $invalidScope, Role::CONSTRAINT_PARAMETER_VALUE )
724
-						->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
725
-						->withConstraintScopeList( $validScopes, Role::CONSTRAINT_PARAMETER_VALUE )
722
+					(new ViolationMessage('wbqc-violation-message-invalid-scope'))
723
+						->withConstraintScope($invalidScope, Role::CONSTRAINT_PARAMETER_VALUE)
724
+						->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
725
+						->withConstraintScopeList($validScopes, Role::CONSTRAINT_PARAMETER_VALUE)
726 726
 				);
727 727
 			}
728 728
 		}
@@ -736,15 +736,15 @@  discard block
 block discarded – undo
736 736
 	 * @param ItemId $unitId
737 737
 	 * @return string unit
738 738
 	 */
739
-	private function parseUnitParameter( ItemId $unitId ) {
739
+	private function parseUnitParameter(ItemId $unitId) {
740 740
 		$unitRepositoryName = $unitId->getRepositoryName();
741
-		if ( !array_key_exists( $unitRepositoryName, $this->conceptBaseUris ) ) {
741
+		if (!array_key_exists($unitRepositoryName, $this->conceptBaseUris)) {
742 742
 			throw new LogicException(
743
-				'No base URI for concept URI for repository: ' . $unitRepositoryName
743
+				'No base URI for concept URI for repository: '.$unitRepositoryName
744 744
 			);
745 745
 		}
746 746
 		$baseUri = $this->conceptBaseUris[$unitRepositoryName];
747
-		return $baseUri . $unitId->getSerialization();
747
+		return $baseUri.$unitId->getSerialization();
748 748
 	}
749 749
 
750 750
 	/**
@@ -754,23 +754,23 @@  discard block
 block discarded – undo
754 754
 	 * @return UnitsParameter
755 755
 	 * @throws ConstraintParameterException
756 756
 	 */
757
-	private function parseUnitItem( ItemIdSnakValue $item ) {
758
-		switch ( true ) {
757
+	private function parseUnitItem(ItemIdSnakValue $item) {
758
+		switch (true) {
759 759
 			case $item->isValue():
760
-				$unit = $this->parseUnitParameter( $item->getItemId() );
760
+				$unit = $this->parseUnitParameter($item->getItemId());
761 761
 				return new UnitsParameter(
762
-					[ $item->getItemId() ],
763
-					[ UnboundedQuantityValue::newFromNumber( 1, $unit ) ],
762
+					[$item->getItemId()],
763
+					[UnboundedQuantityValue::newFromNumber(1, $unit)],
764 764
 					false
765 765
 				);
766 766
 			case $item->isSomeValue():
767
-				$qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
767
+				$qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
768 768
 				throw new ConstraintParameterException(
769
-					( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) )
770
-						->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
769
+					(new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue'))
770
+						->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY)
771 771
 				);
772 772
 			case $item->isNoValue():
773
-				return new UnitsParameter( [], [], true );
773
+				return new UnitsParameter([], [], true);
774 774
 		}
775 775
 	}
776 776
 
@@ -780,26 +780,26 @@  discard block
 block discarded – undo
780 780
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
781 781
 	 * @return UnitsParameter
782 782
 	 */
783
-	public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) {
784
-		$items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true );
783
+	public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) {
784
+		$items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true);
785 785
 		$unitItems = [];
786 786
 		$unitQuantities = [];
787 787
 		$unitlessAllowed = false;
788 788
 
789
-		foreach ( $items as $item ) {
790
-			$unit = $this->parseUnitItem( $item );
791
-			$unitItems = array_merge( $unitItems, $unit->getUnitItemIds() );
792
-			$unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() );
789
+		foreach ($items as $item) {
790
+			$unit = $this->parseUnitItem($item);
791
+			$unitItems = array_merge($unitItems, $unit->getUnitItemIds());
792
+			$unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities());
793 793
 			$unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed();
794 794
 		}
795 795
 
796
-		if ( $unitQuantities === [] && !$unitlessAllowed ) {
796
+		if ($unitQuantities === [] && !$unitlessAllowed) {
797 797
 			throw new LogicException(
798 798
 				'The "units" parameter is required, and yet we seem to be missing any allowed unit'
799 799
 			);
800 800
 		}
801 801
 
802
-		return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed );
802
+		return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed);
803 803
 	}
804 804
 
805 805
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/AllowedUnitsChecker.php 1 patch
Spacing   +31 added lines, -32 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @throws ConstraintParameterException
76 76
 	 * @return CheckResult
77 77
 	 */
78
-	public function checkConstraint( Context $context, Constraint $constraint ) {
78
+	public function checkConstraint(Context $context, Constraint $constraint) {
79 79
 		$parameters = [];
80 80
 		$constraintParameters = $constraint->getConstraintParameters();
81 81
 		$unitsParameter = $this->constraintParameterParser
@@ -85,45 +85,44 @@  discard block
 block discarded – undo
85 85
 			);
86 86
 
87 87
 		$snak = $context->getSnak();
88
-		if ( !$snak instanceof PropertyValueSnak ) {
88
+		if (!$snak instanceof PropertyValueSnak) {
89 89
 			// nothing to check
90
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
90
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
91 91
 		}
92 92
 
93 93
 		$dataValue = $snak->getDataValue();
94
-		if ( !$dataValue instanceof UnboundedQuantityValue ) {
95
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
96
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
97
-				->withDataValueType( 'quantity' );
98
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
94
+		if (!$dataValue instanceof UnboundedQuantityValue) {
95
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
96
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
97
+				->withDataValueType('quantity');
98
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
99 99
 		}
100 100
 
101
-		if ( $dataValue->getUnit() === '1' ) {
102
-			return $this->checkUnitless( $context, $constraint, $unitsParameter, $snak );
101
+		if ($dataValue->getUnit() === '1') {
102
+			return $this->checkUnitless($context, $constraint, $unitsParameter, $snak);
103 103
 		}
104 104
 
105 105
 		$status = CheckResult::STATUS_VIOLATION;
106
-		$actualUnit = $this->standardize( $dataValue )->getUnit();
107
-		foreach ( $unitsParameter->getUnitQuantities() as $unitQuantity ) {
108
-			$allowedUnit = $this->standardize( $unitQuantity )->getUnit();
109
-			if ( $actualUnit === $allowedUnit ) {
106
+		$actualUnit = $this->standardize($dataValue)->getUnit();
107
+		foreach ($unitsParameter->getUnitQuantities() as $unitQuantity) {
108
+			$allowedUnit = $this->standardize($unitQuantity)->getUnit();
109
+			if ($actualUnit === $allowedUnit) {
110 110
 				$status = CheckResult::STATUS_COMPLIANCE;
111 111
 				break;
112 112
 			}
113 113
 		}
114 114
 
115
-		if ( $status === CheckResult::STATUS_VIOLATION ) {
115
+		if ($status === CheckResult::STATUS_VIOLATION) {
116 116
 			$messageKey = $unitsParameter->getUnitlessAllowed() ?
117
-				'wbqc-violation-message-units-or-none' :
118
-				'wbqc-violation-message-units';
119
-			$message = ( new ViolationMessage( $messageKey ) )
120
-				->withEntityId( $snak->getPropertyId() )
121
-				->withEntityIdList( $unitsParameter->getUnitItemIds() );
117
+				'wbqc-violation-message-units-or-none' : 'wbqc-violation-message-units';
118
+			$message = (new ViolationMessage($messageKey))
119
+				->withEntityId($snak->getPropertyId())
120
+				->withEntityIdList($unitsParameter->getUnitItemIds());
122 121
 		} else {
123 122
 			$message = null;
124 123
 		}
125 124
 
126
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
125
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
127 126
 	}
128 127
 
129 128
 	/**
@@ -139,17 +138,17 @@  discard block
 block discarded – undo
139 138
 		UnitsParameter $unitsParameter,
140 139
 		PropertyValueSnak $snak
141 140
 	) {
142
-		if ( $unitsParameter->getUnitlessAllowed() ) {
141
+		if ($unitsParameter->getUnitlessAllowed()) {
143 142
 			$message = null;
144 143
 			$status = CheckResult::STATUS_COMPLIANCE;
145 144
 		} else {
146
-			$message = ( new ViolationMessage( 'wbqc-violation-message-units' ) )
147
-				->withEntityId( $snak->getPropertyId() )
148
-				->withEntityIdList( $unitsParameter->getUnitItemIds() );
145
+			$message = (new ViolationMessage('wbqc-violation-message-units'))
146
+				->withEntityId($snak->getPropertyId())
147
+				->withEntityIdList($unitsParameter->getUnitItemIds());
149 148
 			$status = CheckResult::STATUS_VIOLATION;
150 149
 		}
151 150
 
152
-		return new CheckResult( $context, $constraint, [], $status, $message );
151
+		return new CheckResult($context, $constraint, [], $status, $message);
153 152
 	}
154 153
 
155 154
 	/**
@@ -158,20 +157,20 @@  discard block
 block discarded – undo
158 157
 	 * @param UnboundedQuantityValue $value
159 158
 	 * @return UnboundedQuantityValue
160 159
 	 */
161
-	private function standardize( UnboundedQuantityValue $value ) {
162
-		if ( $this->unitConverter === null ) {
160
+	private function standardize(UnboundedQuantityValue $value) {
161
+		if ($this->unitConverter === null) {
163 162
 			return $value;
164 163
 		}
165 164
 
166
-		$standard = $this->unitConverter->toStandardUnits( $value );
167
-		if ( $standard !== null ) {
165
+		$standard = $this->unitConverter->toStandardUnits($value);
166
+		if ($standard !== null) {
168 167
 			return $standard;
169 168
 		} else {
170 169
 			return $value;
171 170
 		}
172 171
 	}
173 172
 
174
-	public function checkConstraintParameters( Constraint $constraint ) {
173
+	public function checkConstraintParameters(Constraint $constraint) {
175 174
 		$constraintParameters = $constraint->getConstraintParameters();
176 175
 		$exceptions = [];
177 176
 		try {
@@ -180,7 +179,7 @@  discard block
 block discarded – undo
180 179
 				$constraint->getConstraintTypeItemId(),
181 180
 				true
182 181
 			);
183
-		} catch ( ConstraintParameterException $e ) {
182
+		} catch (ConstraintParameterException $e) {
184 183
 			$exceptions[] = $e;
185 184
 		}
186 185
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintReportFactory.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	public static function getDefaultInstance() {
153 153
 		static $instance = null;
154 154
 
155
-		if ( $instance === null ) {
155
+		if ($instance === null) {
156 156
 			$wikibaseRepo = WikibaseRepo::getDefaultInstance();
157 157
 			$entityIdFormatter = $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory()->getEntityIdFormatter(
158 158
 				$wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory()->newLabelDescriptionLookup(
@@ -233,21 +233,21 @@  discard block
 block discarded – undo
233 233
 	 * @return DelegatingConstraintChecker
234 234
 	 */
235 235
 	public function getConstraintChecker() {
236
-		if ( $this->delegatingConstraintChecker === null ) {
236
+		if ($this->delegatingConstraintChecker === null) {
237 237
 			$this->delegatingConstraintChecker = new DelegatingConstraintChecker(
238 238
 				$this->lookup,
239 239
 				$this->getConstraintCheckerMap(),
240
-				new CachingConstraintLookup( $this->getConstraintRepository() ),
240
+				new CachingConstraintLookup($this->getConstraintRepository()),
241 241
 				$this->constraintParameterParser,
242 242
 				$this->statementGuidParser,
243 243
 				new LoggingHelper(
244 244
 					$this->dataFactory,
245
-					LoggerFactory::getInstance( 'WikibaseQualityConstraints' ),
245
+					LoggerFactory::getInstance('WikibaseQualityConstraints'),
246 246
 					$this->config
247 247
 				),
248
-				$this->config->get( 'WBQualityConstraintsCheckQualifiers' ),
249
-				$this->config->get( 'WBQualityConstraintsCheckReferences' ),
250
-				$this->config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' )
248
+				$this->config->get('WBQualityConstraintsCheckQualifiers'),
249
+				$this->config->get('WBQualityConstraintsCheckReferences'),
250
+				$this->config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers')
251 251
 			);
252 252
 		}
253 253
 
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
 	 * @return ConstraintChecker[]
259 259
 	 */
260 260
 	private function getConstraintCheckerMap() {
261
-		if ( $this->constraintCheckerMap === null ) {
261
+		if ($this->constraintCheckerMap === null) {
262 262
 			$connectionCheckerHelper = new ConnectionCheckerHelper();
263
-			$rangeCheckerHelper = new RangeCheckerHelper( $this->config, $this->unitConverter );
264
-			if ( $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ) !== '' ) {
263
+			$rangeCheckerHelper = new RangeCheckerHelper($this->config, $this->unitConverter);
264
+			if ($this->config->get('WBQualityConstraintsSparqlEndpoint') !== '') {
265 265
 				$sparqlHelper = new SparqlHelper(
266 266
 					$this->config,
267 267
 					$this->rdfVocabulary,
@@ -284,74 +284,74 @@  discard block
 block discarded – undo
284 284
 			);
285 285
 
286 286
 			$this->constraintCheckerMap = [
287
-				$this->config->get( 'WBQualityConstraintsConflictsWithConstraintId' )
287
+				$this->config->get('WBQualityConstraintsConflictsWithConstraintId')
288 288
 					=> new ConflictsWithChecker(
289 289
 						$this->lookup,
290 290
 						$this->constraintParameterParser,
291 291
 						$connectionCheckerHelper,
292 292
 						$this->constraintParameterRenderer
293 293
 					),
294
-				$this->config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' )
294
+				$this->config->get('WBQualityConstraintsItemRequiresClaimConstraintId')
295 295
 					=> new ItemChecker(
296 296
 						$this->lookup,
297 297
 						$this->constraintParameterParser,
298 298
 						$connectionCheckerHelper,
299 299
 						$this->constraintParameterRenderer
300 300
 					),
301
-				$this->config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' )
301
+				$this->config->get('WBQualityConstraintsValueRequiresClaimConstraintId')
302 302
 					=> new TargetRequiredClaimChecker(
303 303
 						$this->lookup,
304 304
 						$this->constraintParameterParser,
305 305
 						$connectionCheckerHelper,
306 306
 						$this->constraintParameterRenderer
307 307
 					),
308
-				$this->config->get( 'WBQualityConstraintsSymmetricConstraintId' )
308
+				$this->config->get('WBQualityConstraintsSymmetricConstraintId')
309 309
 					=> new SymmetricChecker(
310 310
 						$this->lookup,
311 311
 						$connectionCheckerHelper,
312 312
 						$this->constraintParameterRenderer
313 313
 					),
314
-				$this->config->get( 'WBQualityConstraintsInverseConstraintId' )
314
+				$this->config->get('WBQualityConstraintsInverseConstraintId')
315 315
 					=> new InverseChecker(
316 316
 						$this->lookup,
317 317
 						$this->constraintParameterParser,
318 318
 						$connectionCheckerHelper,
319 319
 						$this->constraintParameterRenderer
320 320
 					),
321
-				$this->config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' )
321
+				$this->config->get('WBQualityConstraintsUsedAsQualifierConstraintId')
322 322
 					=> new QualifierChecker(),
323
-				$this->config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' )
323
+				$this->config->get('WBQualityConstraintsAllowedQualifiersConstraintId')
324 324
 					=> new QualifiersChecker(
325 325
 						$this->constraintParameterParser,
326 326
 						$this->constraintParameterRenderer
327 327
 					),
328
-				$this->config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' )
328
+				$this->config->get('WBQualityConstraintsMandatoryQualifierConstraintId')
329 329
 					=> new MandatoryQualifiersChecker(
330 330
 						$this->constraintParameterParser,
331 331
 						$this->constraintParameterRenderer
332 332
 					),
333
-				$this->config->get( 'WBQualityConstraintsRangeConstraintId' )
333
+				$this->config->get('WBQualityConstraintsRangeConstraintId')
334 334
 					=> new RangeChecker(
335 335
 						$this->propertyDataTypeLookup,
336 336
 						$this->constraintParameterParser,
337 337
 						$rangeCheckerHelper,
338 338
 						$this->constraintParameterRenderer
339 339
 					),
340
-				$this->config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' )
340
+				$this->config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId')
341 341
 					=> new DiffWithinRangeChecker(
342 342
 						$this->constraintParameterParser,
343 343
 						$rangeCheckerHelper,
344 344
 						$this->constraintParameterRenderer,
345 345
 						$this->config
346 346
 					),
347
-				$this->config->get( 'WBQualityConstraintsTypeConstraintId' )
347
+				$this->config->get('WBQualityConstraintsTypeConstraintId')
348 348
 					=> new TypeChecker(
349 349
 						$this->lookup,
350 350
 						$this->constraintParameterParser,
351 351
 						$typeCheckerHelper,
352 352
 						$this->config
353 353
 					),
354
-				$this->config->get( 'WBQualityConstraintsValueTypeConstraintId' )
354
+				$this->config->get('WBQualityConstraintsValueTypeConstraintId')
355 355
 					=> new ValueTypeChecker(
356 356
 						$this->lookup,
357 357
 						$this->constraintParameterParser,
@@ -359,40 +359,40 @@  discard block
 block discarded – undo
359 359
 						$typeCheckerHelper,
360 360
 						$this->config
361 361
 					),
362
-				$this->config->get( 'WBQualityConstraintsSingleValueConstraintId' )
362
+				$this->config->get('WBQualityConstraintsSingleValueConstraintId')
363 363
 					=> new SingleValueChecker(),
364
-				$this->config->get( 'WBQualityConstraintsMultiValueConstraintId' )
364
+				$this->config->get('WBQualityConstraintsMultiValueConstraintId')
365 365
 					=> new MultiValueChecker(),
366
-				$this->config->get( 'WBQualityConstraintsDistinctValuesConstraintId' )
366
+				$this->config->get('WBQualityConstraintsDistinctValuesConstraintId')
367 367
 					=> new UniqueValueChecker(
368 368
 						$this->constraintParameterRenderer,
369 369
 						$sparqlHelper
370 370
 					),
371
-				$this->config->get( 'WBQualityConstraintsFormatConstraintId' )
371
+				$this->config->get('WBQualityConstraintsFormatConstraintId')
372 372
 					=> new FormatChecker(
373 373
 						$this->constraintParameterParser,
374 374
 						$this->constraintParameterRenderer,
375 375
 						$this->config,
376 376
 						$sparqlHelper
377 377
 					),
378
-				$this->config->get( 'WBQualityConstraintsCommonsLinkConstraintId' )
378
+				$this->config->get('WBQualityConstraintsCommonsLinkConstraintId')
379 379
 					=> new CommonsLinkChecker(
380 380
 						$this->constraintParameterParser,
381 381
 						$this->constraintParameterRenderer,
382 382
 						$this->titleParser
383 383
 					),
384
-				$this->config->get( 'WBQualityConstraintsOneOfConstraintId' )
384
+				$this->config->get('WBQualityConstraintsOneOfConstraintId')
385 385
 					=> new OneOfChecker(
386 386
 						$this->constraintParameterParser,
387 387
 						$this->constraintParameterRenderer
388 388
 					),
389
-				$this->config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' )
389
+				$this->config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId')
390 390
 					=> new ValueOnlyChecker(),
391
-				$this->config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' )
391
+				$this->config->get('WBQualityConstraintsUsedAsReferenceConstraintId')
392 392
 					=> new ReferenceChecker(),
393
-				$this->config->get( 'WBQualityConstraintsNoBoundsConstraintId' )
393
+				$this->config->get('WBQualityConstraintsNoBoundsConstraintId')
394 394
 					=> new NoBoundsChecker(),
395
-				$this->config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' )
395
+				$this->config->get('WBQualityConstraintsAllowedUnitsConstraintId')
396 396
 					=> new AllowedUnitsChecker(
397 397
 						$this->constraintParameterParser,
398 398
 						$this->unitConverter
@@ -407,26 +407,26 @@  discard block
 block discarded – undo
407 407
 	 * @return array[]
408 408
 	 */
409 409
 	public function getConstraintParameterMap() {
410
-		if ( $this->constraintParameterMap === null ) {
410
+		if ($this->constraintParameterMap === null) {
411 411
 			$this->constraintParameterMap = [
412
-				'Commons link' => [ 'namespace' ],
413
-				'Conflicts with' => [ 'property', 'item' ],
414
-				'Diff within range' => [ 'property', 'minimum_quantity', 'maximum_quantity' ],
415
-				'Format' => [ 'pattern' ],
416
-				'Inverse' => [ 'property' ],
417
-				'Item' => [ 'property', 'item' ],
418
-				'Mandatory qualifiers' => [ 'property' ],
412
+				'Commons link' => ['namespace'],
413
+				'Conflicts with' => ['property', 'item'],
414
+				'Diff within range' => ['property', 'minimum_quantity', 'maximum_quantity'],
415
+				'Format' => ['pattern'],
416
+				'Inverse' => ['property'],
417
+				'Item' => ['property', 'item'],
418
+				'Mandatory qualifiers' => ['property'],
419 419
 				'Multi value' => [],
420
-				'One of' => [ 'item' ],
420
+				'One of' => ['item'],
421 421
 				'Qualifier' => [],
422
-				'Qualifiers' => [ 'property' ],
423
-				'Range' => [ 'minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date' ],
422
+				'Qualifiers' => ['property'],
423
+				'Range' => ['minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date'],
424 424
 				'Single value' => [],
425 425
 				'Symmetric' => [],
426
-				'Target required claim' => [ 'property', 'item' ],
427
-				'Type' => [ 'class', 'relation' ],
426
+				'Target required claim' => ['property', 'item'],
427
+				'Type' => ['class', 'relation'],
428 428
 				'Unique value' => [],
429
-				'Value type' => [ 'class', 'relation' ]
429
+				'Value type' => ['class', 'relation']
430 430
 			];
431 431
 		}
432 432
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 * @return ConstraintRepository
438 438
 	 */
439 439
 	public function getConstraintRepository() {
440
-		if ( $this->constraintRepository === null ) {
440
+		if ($this->constraintRepository === null) {
441 441
 			$this->constraintRepository = new ConstraintRepository();
442 442
 		}
443 443
 
Please login to merge, or discard this patch.