Completed
Push — master ( 3c74bb...3be357 )
by
unknown
02:56
created
src/ConstraintCheck/Helper/ConstraintParameterParser.php 1 patch
Spacing   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 	 * @param array $parameters
77 77
 	 * @throws ConstraintParameterException
78 78
 	 */
79
-	public function checkError( array $parameters ) {
80
-		if ( array_key_exists( '@error', $parameters ) ) {
79
+	public function checkError(array $parameters) {
80
+		if (array_key_exists('@error', $parameters)) {
81 81
 			$error = $parameters['@error'];
82
-			if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) {
82
+			if (array_key_exists('toolong', $error) && $error['toolong']) {
83 83
 				$msg = 'wbqc-violation-message-parameters-error-toolong';
84 84
 			} else {
85 85
 				$msg = 'wbqc-violation-message-parameters-error-unknown';
86 86
 			}
87
-			throw new ConstraintParameterException( wfMessage( $msg )->escaped() );
87
+			throw new ConstraintParameterException(wfMessage($msg)->escaped());
88 88
 		}
89 89
 	}
90 90
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 	 * @param string $parameterId
95 95
 	 * @throws ConstraintParameterException
96 96
 	 */
97
-	private function requireSingleParameter( array $parameters, $parameterId ) {
98
-		if ( count( $parameters[$parameterId] ) !== 1 ) {
97
+	private function requireSingleParameter(array $parameters, $parameterId) {
98
+		if (count($parameters[$parameterId]) !== 1) {
99 99
 			throw new ConstraintParameterException(
100
-				wfMessage( 'wbqc-violation-message-parameter-single' )
101
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
100
+				wfMessage('wbqc-violation-message-parameter-single')
101
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
102 102
 					->escaped()
103 103
 			);
104 104
 		}
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 	 * @return void
112 112
 	 * @throws ConstraintParameterException
113 113
 	 */
114
-	private function requireValueParameter( Snak $snak, $parameterId ) {
115
-		if ( !( $snak instanceof PropertyValueSnak ) ) {
114
+	private function requireValueParameter(Snak $snak, $parameterId) {
115
+		if (!($snak instanceof PropertyValueSnak)) {
116 116
 			throw new ConstraintParameterException(
117
-				wfMessage( 'wbqc-violation-message-parameter-value' )
118
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
117
+				wfMessage('wbqc-violation-message-parameter-value')
118
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
119 119
 					->escaped()
120 120
 			);
121 121
 		}
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
 	 * @throws ConstraintParameterException
129 129
 	 * @return EntityId
130 130
 	 */
131
-	private function parseEntityIdParameter( array $snakSerialization, $parameterId ) {
132
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
133
-		$this->requireValueParameter( $snak, $parameterId );
131
+	private function parseEntityIdParameter(array $snakSerialization, $parameterId) {
132
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
133
+		$this->requireValueParameter($snak, $parameterId);
134 134
 		$value = $snak->getDataValue();
135
-		if ( $value instanceof EntityIdValue ) {
135
+		if ($value instanceof EntityIdValue) {
136 136
 			return $value->getEntityId();
137 137
 		} else {
138 138
 			throw new ConstraintParameterException(
139
-				wfMessage( 'wbqc-violation-message-parameter-entity' )
139
+				wfMessage('wbqc-violation-message-parameter-entity')
140 140
 					->rawParams(
141
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
142
-						$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
141
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
142
+						$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
143 143
 					)
144 144
 					->escaped()
145 145
 			);
@@ -152,21 +152,21 @@  discard block
 block discarded – undo
152 152
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
153 153
 	 * @return string[] class entity ID serializations
154 154
 	 */
155
-	public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) {
156
-		$this->checkError( $constraintParameters );
157
-		$classId = $this->config->get( 'WBQualityConstraintsClassId' );
158
-		if ( !array_key_exists( $classId, $constraintParameters ) ) {
155
+	public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) {
156
+		$this->checkError($constraintParameters);
157
+		$classId = $this->config->get('WBQualityConstraintsClassId');
158
+		if (!array_key_exists($classId, $constraintParameters)) {
159 159
 			throw new ConstraintParameterException(
160
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
161
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
162
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
160
+				wfMessage('wbqc-violation-message-parameter-needed')
161
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
162
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY))
163 163
 					->escaped()
164 164
 			);
165 165
 		}
166 166
 
167 167
 		$classes = [];
168
-		foreach ( $constraintParameters[$classId] as $class ) {
169
-			$classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization();
168
+		foreach ($constraintParameters[$classId] as $class) {
169
+			$classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization();
170 170
 		}
171 171
 		return $classes;
172 172
 	}
@@ -177,33 +177,33 @@  discard block
 block discarded – undo
177 177
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
178 178
 	 * @return string 'instance' or 'subclass'
179 179
 	 */
180
-	public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) {
181
-		$this->checkError( $constraintParameters );
182
-		$relationId = $this->config->get( 'WBQualityConstraintsRelationId' );
183
-		if ( !array_key_exists( $relationId, $constraintParameters ) ) {
180
+	public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) {
181
+		$this->checkError($constraintParameters);
182
+		$relationId = $this->config->get('WBQualityConstraintsRelationId');
183
+		if (!array_key_exists($relationId, $constraintParameters)) {
184 184
 			throw new ConstraintParameterException(
185
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
186
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
187
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
185
+				wfMessage('wbqc-violation-message-parameter-needed')
186
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
187
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY))
188 188
 					->escaped()
189 189
 			);
190 190
 		}
191 191
 
192
-		$this->requireSingleParameter( $constraintParameters, $relationId );
193
-		$relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId );
194
-		$instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' );
195
-		$subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' );
196
-		switch ( $relationEntityId ) {
192
+		$this->requireSingleParameter($constraintParameters, $relationId);
193
+		$relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId);
194
+		$instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId');
195
+		$subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId');
196
+		switch ($relationEntityId) {
197 197
 			case $instanceId:
198 198
 				return 'instance';
199 199
 			case $subclassId:
200 200
 				return 'subclass';
201 201
 			default:
202 202
 				throw new ConstraintParameterException(
203
-					wfMessage( 'wbqc-violation-message-parameter-oneof' )
204
-						->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
205
-						->numParams( 2 )
206
-						->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $instanceId, $subclassId ], Role::CONSTRAINT_PARAMETER_VALUE ) )
203
+					wfMessage('wbqc-violation-message-parameter-oneof')
204
+						->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY))
205
+						->numParams(2)
206
+						->rawParams($this->constraintParameterRenderer->formatItemIdList([$instanceId, $subclassId], Role::CONSTRAINT_PARAMETER_VALUE))
207 207
 						->escaped()
208 208
 				);
209 209
 		}
@@ -216,21 +216,21 @@  discard block
 block discarded – undo
216 216
 	 * @throws ConstraintParameterException
217 217
 	 * @return PropertyId
218 218
 	 */
219
-	private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) {
220
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
221
-		$this->requireValueParameter( $snak, $parameterId );
219
+	private function parsePropertyIdParameter(array $snakSerialization, $parameterId) {
220
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
221
+		$this->requireValueParameter($snak, $parameterId);
222 222
 		$value = $snak->getDataValue();
223
-		if ( $value instanceof EntityIdValue ) {
223
+		if ($value instanceof EntityIdValue) {
224 224
 			$id = $value->getEntityId();
225
-			if ( $id instanceof PropertyId ) {
225
+			if ($id instanceof PropertyId) {
226 226
 				return $id;
227 227
 			}
228 228
 		}
229 229
 		throw new ConstraintParameterException(
230
-			wfMessage( 'wbqc-violation-message-parameter-property' )
230
+			wfMessage('wbqc-violation-message-parameter-property')
231 231
 				->rawParams(
232
-					$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
233
-					$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
232
+					$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
233
+					$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
234 234
 				)
235 235
 				->escaped()
236 236
 		);
@@ -243,34 +243,34 @@  discard block
 block discarded – undo
243 243
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
244 244
 	 * @return PropertyId
245 245
 	 */
246
-	public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) {
247
-		$this->checkError( $constraintParameters );
248
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
249
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
246
+	public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) {
247
+		$this->checkError($constraintParameters);
248
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
249
+		if (!array_key_exists($propertyId, $constraintParameters)) {
250 250
 			throw new ConstraintParameterException(
251
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
252
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
253
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
251
+				wfMessage('wbqc-violation-message-parameter-needed')
252
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
253
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY))
254 254
 					->escaped()
255 255
 			);
256 256
 		}
257 257
 
258
-		$this->requireSingleParameter( $constraintParameters, $propertyId );
259
-		return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId );
258
+		$this->requireSingleParameter($constraintParameters, $propertyId);
259
+		return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId);
260 260
 	}
261 261
 
262
-	private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) {
262
+	private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) {
263 263
 		$dataValue = $snak->getDataValue();
264
-		if ( $dataValue instanceof EntityIdValue &&
264
+		if ($dataValue instanceof EntityIdValue &&
265 265
 			$dataValue->getEntityId() instanceof ItemId
266 266
 		) {
267
-			return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() );
267
+			return ItemIdSnakValue::fromItemId($dataValue->getEntityId());
268 268
 		} else {
269 269
 			throw new ConstraintParameterException(
270
-				wfMessage( 'wbqc-violation-message-parameter-item' )
270
+				wfMessage('wbqc-violation-message-parameter-item')
271 271
 					->rawParams(
272
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
273
-						$this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
272
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
273
+						$this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
274 274
 					)
275 275
 					->escaped()
276 276
 			);
@@ -284,15 +284,15 @@  discard block
 block discarded – undo
284 284
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
285 285
 	 * @return ItemIdSnakValue[] array of values
286 286
 	 */
287
-	public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) {
288
-		$this->checkError( $constraintParameters );
289
-		$qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
290
-		if ( !array_key_exists( $qualifierId, $constraintParameters ) ) {
291
-			if ( $required ) {
287
+	public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) {
288
+		$this->checkError($constraintParameters);
289
+		$qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
290
+		if (!array_key_exists($qualifierId, $constraintParameters)) {
291
+			if ($required) {
292 292
 				throw new ConstraintParameterException(
293
-					wfMessage( 'wbqc-violation-message-parameter-needed' )
294
-						->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
295
-						->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
293
+					wfMessage('wbqc-violation-message-parameter-needed')
294
+						->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
295
+						->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY))
296 296
 						->escaped()
297 297
 				);
298 298
 			} else {
@@ -301,11 +301,11 @@  discard block
 block discarded – undo
301 301
 		}
302 302
 
303 303
 		$values = [];
304
-		foreach ( $constraintParameters[$qualifierId] as $parameter ) {
305
-			$snak = $this->snakDeserializer->deserialize( $parameter );
306
-			switch ( true ) {
304
+		foreach ($constraintParameters[$qualifierId] as $parameter) {
305
+			$snak = $this->snakDeserializer->deserialize($parameter);
306
+			switch (true) {
307 307
 				case $snak instanceof PropertyValueSnak:
308
-					$values[] = $this->parseItemIdParameter( $snak, $qualifierId );
308
+					$values[] = $this->parseItemIdParameter($snak, $qualifierId);
309 309
 					break;
310 310
 				case $snak instanceof PropertySomeValueSnak:
311 311
 					$values[] = ItemIdSnakValue::someValue();
@@ -324,28 +324,28 @@  discard block
 block discarded – undo
324 324
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
325 325
 	 * @return PropertyId[]
326 326
 	 */
327
-	public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) {
328
-		$this->checkError( $constraintParameters );
329
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
330
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
327
+	public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) {
328
+		$this->checkError($constraintParameters);
329
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
330
+		if (!array_key_exists($propertyId, $constraintParameters)) {
331 331
 			throw new ConstraintParameterException(
332
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
333
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
334
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
332
+				wfMessage('wbqc-violation-message-parameter-needed')
333
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
334
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY))
335 335
 					->escaped()
336 336
 			);
337 337
 		}
338 338
 
339 339
 		$parameters = $constraintParameters[$propertyId];
340
-		if ( count( $parameters ) === 1 &&
341
-			$this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak
340
+		if (count($parameters) === 1 &&
341
+			$this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak
342 342
 		) {
343 343
 			return [];
344 344
 		}
345 345
 
346 346
 		$properties = [];
347
-		foreach ( $parameters as $parameter ) {
348
-			$properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId );
347
+		foreach ($parameters as $parameter) {
348
+			$properties[] = $this->parsePropertyIdParameter($parameter, $propertyId);
349 349
 		}
350 350
 		return $properties;
351 351
 	}
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
 	 * @throws ConstraintParameterException
357 357
 	 * @return DataValue|null
358 358
 	 */
359
-	private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) {
360
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
361
-		if ( $snak instanceof PropertyValueSnak ) {
359
+	private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) {
360
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
361
+		if ($snak instanceof PropertyValueSnak) {
362 362
 			return $snak->getDataValue();
363
-		} elseif ( $snak instanceof PropertyNoValueSnak ) {
363
+		} elseif ($snak instanceof PropertyNoValueSnak) {
364 364
 			return null;
365 365
 		} else {
366 366
 			throw new ConstraintParameterException(
367
-				wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' )
368
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
367
+				wfMessage('wbqc-violation-message-parameter-value-or-novalue')
368
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
369 369
 					->escaped()
370 370
 			);
371 371
 		}
@@ -376,13 +376,13 @@  discard block
 block discarded – undo
376 376
 	 * @param string $parameterId
377 377
 	 * @return DataValue|null
378 378
 	 */
379
-	private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) {
379
+	private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) {
380 380
 		try {
381
-			return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId );
382
-		} catch ( ConstraintParameterException $e ) {
381
+			return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId);
382
+		} catch (ConstraintParameterException $e) {
383 383
 			// unknown value means “now”
384
-			$timeParser = ( new TimeParserFactory() )->getTimeParser();
385
-			return $timeParser->parse( gmdate( '+Y-m-d\T00:00:00\Z' ) );
384
+			$timeParser = (new TimeParserFactory())->getTimeParser();
385
+			return $timeParser->parse(gmdate('+Y-m-d\T00:00:00\Z'));
386 386
 		}
387 387
 	}
388 388
 
@@ -393,14 +393,14 @@  discard block
 block discarded – undo
393 393
 	 * @param string $unit
394 394
 	 * @return bool
395 395
 	 */
396
-	private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) {
397
-		if ( $min === null || $max === null ) {
396
+	private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) {
397
+		if ($min === null || $max === null) {
398 398
 			return false;
399 399
 		}
400
-		if ( $min->getType() !== 'quantity' || $max->getType() !== 'quantity' ) {
400
+		if ($min->getType() !== 'quantity' || $max->getType() !== 'quantity') {
401 401
 			return false;
402 402
 		}
403
-		return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit );
403
+		return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit);
404 404
 	}
405 405
 
406 406
 	/**
@@ -411,9 +411,9 @@  discard block
 block discarded – undo
411 411
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
412 412
 	 * @return DataValue[] a pair of two quantity-type data values, either of which may be null to signify an open range
413 413
 	 */
414
-	public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) {
415
-		$this->checkError( $constraintParameters );
416
-		switch ( $type ) {
414
+	public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) {
415
+		$this->checkError($constraintParameters);
416
+		switch ($type) {
417 417
 			case 'quantity':
418 418
 				$configKey = 'Quantity';
419 419
 				break;
@@ -422,46 +422,46 @@  discard block
 block discarded – undo
422 422
 				break;
423 423
 			default:
424 424
 				throw new ConstraintParameterException(
425
-					wfMessage( 'wbqc-violation-message-value-needed-of-types-2' )
425
+					wfMessage('wbqc-violation-message-value-needed-of-types-2')
426 426
 						->rawParams(
427
-							wfMessage( 'datatypes-type-quantity' )->escaped(),
428
-							wfMessage( 'datatypes-type-time' )->escaped()
427
+							wfMessage('datatypes-type-quantity')->escaped(),
428
+							wfMessage('datatypes-type-time')->escaped()
429 429
 						)
430 430
 						->escaped()
431 431
 				);
432 432
 		}
433
-		$minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' );
434
-		$maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' );
435
-		if ( !array_key_exists( $minimumId, $constraintParameters ) ||
436
-			!array_key_exists( $maximumId, $constraintParameters )
433
+		$minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id');
434
+		$maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id');
435
+		if (!array_key_exists($minimumId, $constraintParameters) ||
436
+			!array_key_exists($maximumId, $constraintParameters)
437 437
 		) {
438 438
 			throw new ConstraintParameterException(
439
-				wfMessage( 'wbqc-violation-message-range-parameters-needed' )
439
+				wfMessage('wbqc-violation-message-range-parameters-needed')
440 440
 					->rawParams(
441
-						wfMessage( 'datatypes-type-' . $type )->escaped(),
442
-						$this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
443
-						$this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY )
441
+						wfMessage('datatypes-type-'.$type)->escaped(),
442
+						$this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY),
443
+						$this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY)
444 444
 					)
445
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
445
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
446 446
 					->escaped()
447 447
 			);
448 448
 		}
449 449
 
450
-		$this->requireSingleParameter( $constraintParameters, $minimumId );
451
-		$this->requireSingleParameter( $constraintParameters, $maximumId );
450
+		$this->requireSingleParameter($constraintParameters, $minimumId);
451
+		$this->requireSingleParameter($constraintParameters, $maximumId);
452 452
 		$parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter';
453
-		$min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId );
454
-		$max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId );
453
+		$min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId);
454
+		$max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId);
455 455
 
456
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
457
-		if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) {
456
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
457
+		if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) {
458 458
 			throw new ConstraintParameterException(
459
-				wfMessage( 'wbqc-violation-message-range-parameters-one-year' )
459
+				wfMessage('wbqc-violation-message-range-parameters-one-year')
460 460
 					->escaped()
461 461
 			);
462 462
 		}
463 463
 
464
-		return [ $min, $max ];
464
+		return [$min, $max];
465 465
 	}
466 466
 
467 467
 	/**
@@ -471,18 +471,18 @@  discard block
 block discarded – undo
471 471
 	 * @throws ConstraintParameterException
472 472
 	 * @return string
473 473
 	 */
474
-	private function parseStringParameter( array $snakSerialization, $parameterId ) {
475
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
476
-		$this->requireValueParameter( $snak, $parameterId );
474
+	private function parseStringParameter(array $snakSerialization, $parameterId) {
475
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
476
+		$this->requireValueParameter($snak, $parameterId);
477 477
 		$value = $snak->getDataValue();
478
-		if ( $value instanceof StringValue ) {
478
+		if ($value instanceof StringValue) {
479 479
 			return $value->getValue();
480 480
 		} else {
481 481
 			throw new ConstraintParameterException(
482
-				wfMessage( 'wbqc-violation-message-parameter-string' )
482
+				wfMessage('wbqc-violation-message-parameter-string')
483 483
 					->rawParams(
484
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
485
-						$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
484
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
485
+						$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
486 486
 					)
487 487
 					->escaped()
488 488
 			);
@@ -495,15 +495,15 @@  discard block
 block discarded – undo
495 495
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
496 496
 	 * @return string
497 497
 	 */
498
-	public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) {
499
-		$this->checkError( $constraintParameters );
500
-		$namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' );
501
-		if ( !array_key_exists( $namespaceId, $constraintParameters ) ) {
498
+	public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) {
499
+		$this->checkError($constraintParameters);
500
+		$namespaceId = $this->config->get('WBQualityConstraintsNamespaceId');
501
+		if (!array_key_exists($namespaceId, $constraintParameters)) {
502 502
 			return '';
503 503
 		}
504 504
 
505
-		$this->requireSingleParameter( $constraintParameters, $namespaceId );
506
-		return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId );
505
+		$this->requireSingleParameter($constraintParameters, $namespaceId);
506
+		return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId);
507 507
 	}
508 508
 
509 509
 	/**
@@ -512,20 +512,20 @@  discard block
 block discarded – undo
512 512
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
513 513
 	 * @return string
514 514
 	 */
515
-	public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) {
516
-		$this->checkError( $constraintParameters );
517
-		$formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' );
518
-		if ( !array_key_exists( $formatId, $constraintParameters ) ) {
515
+	public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) {
516
+		$this->checkError($constraintParameters);
517
+		$formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId');
518
+		if (!array_key_exists($formatId, $constraintParameters)) {
519 519
 			throw new ConstraintParameterException(
520
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
521
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
522
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
520
+				wfMessage('wbqc-violation-message-parameter-needed')
521
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
522
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY))
523 523
 					->escaped()
524 524
 			);
525 525
 		}
526 526
 
527
-		$this->requireSingleParameter( $constraintParameters, $formatId );
528
-		return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId );
527
+		$this->requireSingleParameter($constraintParameters, $formatId);
528
+		return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId);
529 529
 	}
530 530
 
531 531
 	/**
@@ -533,16 +533,16 @@  discard block
 block discarded – undo
533 533
 	 * @throws ConstraintParameterException if the parameter is invalid
534 534
 	 * @return EntityId[]
535 535
 	 */
536
-	public function parseExceptionParameter( array $constraintParameters ) {
537
-		$this->checkError( $constraintParameters );
538
-		$exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' );
539
-		if ( !array_key_exists( $exceptionId, $constraintParameters ) ) {
536
+	public function parseExceptionParameter(array $constraintParameters) {
537
+		$this->checkError($constraintParameters);
538
+		$exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId');
539
+		if (!array_key_exists($exceptionId, $constraintParameters)) {
540 540
 			return [];
541 541
 		}
542 542
 
543 543
 		return array_map(
544
-			function( $snakSerialization ) use ( $exceptionId ) {
545
-				return $this->parseEntityIdParameter( $snakSerialization, $exceptionId );
544
+			function($snakSerialization) use ($exceptionId) {
545
+				return $this->parseEntityIdParameter($snakSerialization, $exceptionId);
546 546
 			},
547 547
 			$constraintParameters[$exceptionId]
548 548
 		);
@@ -553,27 +553,27 @@  discard block
 block discarded – undo
553 553
 	 * @throws ConstraintParameterException if the parameter is invalid
554 554
 	 * @return string|null 'mandatory' or null
555 555
 	 */
556
-	public function parseConstraintStatusParameter( array $constraintParameters ) {
557
-		$this->checkError( $constraintParameters );
558
-		$constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' );
559
-		if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) {
556
+	public function parseConstraintStatusParameter(array $constraintParameters) {
557
+		$this->checkError($constraintParameters);
558
+		$constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId');
559
+		if (!array_key_exists($constraintStatusId, $constraintParameters)) {
560 560
 			return null;
561 561
 		}
562 562
 
563
-		$mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' );
564
-		$this->requireSingleParameter( $constraintParameters, $constraintStatusId );
565
-		$snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] );
566
-		$this->requireValueParameter( $snak, $constraintStatusId );
563
+		$mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId');
564
+		$this->requireSingleParameter($constraintParameters, $constraintStatusId);
565
+		$snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]);
566
+		$this->requireValueParameter($snak, $constraintStatusId);
567 567
 		$statusId = $snak->getDataValue()->getEntityId()->getSerialization();
568 568
 
569
-		if ( $statusId === $mandatoryId ) {
569
+		if ($statusId === $mandatoryId) {
570 570
 			return 'mandatory';
571 571
 		} else {
572 572
 			throw new ConstraintParameterException(
573
-				wfMessage( 'wbqc-violation-message-parameter-oneof' )
574
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
575
-					->numParams( 1 )
576
-					->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) )
573
+				wfMessage('wbqc-violation-message-parameter-oneof')
574
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY))
575
+					->numParams(1)
576
+					->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE))
577 577
 					->escaped()
578 578
 			);
579 579
 		}
@@ -586,13 +586,13 @@  discard block
 block discarded – undo
586 586
 	 * @return void
587 587
 	 * @throws ConstraintParameterException
588 588
 	 */
589
-	private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) {
590
-		if ( !( $dataValue instanceof MonolingualTextValue ) ) {
589
+	private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) {
590
+		if (!($dataValue instanceof MonolingualTextValue)) {
591 591
 			throw new ConstraintParameterException(
592
-				wfMessage( 'wbqc-violation-message-parameter-monolingualtext' )
592
+				wfMessage('wbqc-violation-message-parameter-monolingualtext')
593 593
 					->rawParams(
594
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
595
-						$this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
594
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
595
+						$this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
596 596
 					)
597 597
 					->escaped()
598 598
 			);
@@ -607,26 +607,26 @@  discard block
 block discarded – undo
607 607
 	 * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts
608 608
 	 * @return string[]
609 609
 	 */
610
-	private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) {
610
+	private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) {
611 611
 		$result = [];
612 612
 
613
-		foreach ( $snakSerializations as $snakSerialization ) {
614
-			$snak = $this->snakDeserializer->deserialize( $snakSerialization );
615
-			$this->requireValueParameter( $snak, $parameterId );
613
+		foreach ($snakSerializations as $snakSerialization) {
614
+			$snak = $this->snakDeserializer->deserialize($snakSerialization);
615
+			$this->requireValueParameter($snak, $parameterId);
616 616
 
617 617
 			$value = $snak->getDataValue();
618
-			$this->requireMonolingualTextParameter( $value, $parameterId );
618
+			$this->requireMonolingualTextParameter($value, $parameterId);
619 619
 			/** @var MonolingualTextValue $value */
620 620
 
621 621
 			$code = $value->getLanguageCode();
622
-			if ( array_key_exists( $code, $result ) ) {
622
+			if (array_key_exists($code, $result)) {
623 623
 				throw new ConstraintParameterException(
624
-					wfMessage( 'wbqc-violation-message-parameter-single-per-language' )
624
+					wfMessage('wbqc-violation-message-parameter-single-per-language')
625 625
 						->rawParams(
626
-							$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY )
626
+							$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)
627 627
 						)
628 628
 						->plaintextParams(
629
-							Language::fetchLanguageName( $code ),
629
+							Language::fetchLanguageName($code),
630 630
 							$code
631 631
 						)
632 632
 						->escaped()
@@ -645,23 +645,23 @@  discard block
 block discarded – undo
645 645
 	 * @throws ConstraintParameterException if the parameter is invalid
646 646
 	 * @return string|null
647 647
 	 */
648
-	public function parseSyntaxClarificationParameter( array $constraintParameters, Language $language ) {
649
-		$syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' );
648
+	public function parseSyntaxClarificationParameter(array $constraintParameters, Language $language) {
649
+		$syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId');
650 650
 
651
-		if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) {
651
+		if (!array_key_exists($syntaxClarificationId, $constraintParameters)) {
652 652
 			return null;
653 653
 		}
654 654
 
655 655
 		$languageCodes = $language->getFallbackLanguages();
656
-		array_unshift( $languageCodes, $language->getCode() );
656
+		array_unshift($languageCodes, $language->getCode());
657 657
 
658 658
 		$syntaxClarifications = $this->parseMultilingualTextParameter(
659 659
 			$constraintParameters[$syntaxClarificationId],
660 660
 			$syntaxClarificationId
661 661
 		);
662 662
 
663
-		foreach ( $languageCodes as $languageCode ) {
664
-			if ( array_key_exists( $languageCode, $syntaxClarifications ) ) {
663
+		foreach ($languageCodes as $languageCode) {
664
+			if (array_key_exists($languageCode, $syntaxClarifications)) {
665 665
 				return $syntaxClarifications[$languageCode];
666 666
 			}
667 667
 		}
@@ -677,20 +677,20 @@  discard block
 block discarded – undo
677 677
 	 * @throws ConstraintParameterException if the parameter is invalid
678 678
 	 * @return string[]|null Context::TYPE_* constants
679 679
 	 */
680
-	public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) {
681
-		$constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' );
682
-		$mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' );
683
-		$qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' );
684
-		$referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' );
680
+	public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) {
681
+		$constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId');
682
+		$mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId');
683
+		$qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId');
684
+		$referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId');
685 685
 
686
-		if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) {
686
+		if (!array_key_exists($constraintScopeId, $constraintParameters)) {
687 687
 			return null;
688 688
 		}
689 689
 
690 690
 		$contextTypes = [];
691
-		foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) {
692
-			$scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId );
693
-			switch ( $scopeEntityId->getSerialization() ) {
691
+		foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) {
692
+			$scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId);
693
+			switch ($scopeEntityId->getSerialization()) {
694 694
 				case $mainSnakId:
695 695
 					$contextTypes[] = Context::TYPE_STATEMENT;
696 696
 					break;
@@ -702,14 +702,14 @@  discard block
 block discarded – undo
702 702
 					break;
703 703
 				default:
704 704
 					throw new ConstraintParameterException(
705
-						wfMessage( 'wbqc-violation-message-parameter-oneof' )
705
+						wfMessage('wbqc-violation-message-parameter-oneof')
706 706
 							->rawParams(
707 707
 								$this->constraintParameterRenderer->formatPropertyId(
708 708
 									$constraintScopeId,
709 709
 									Role::CONSTRAINT_PARAMETER_PROPERTY
710 710
 								)
711 711
 							)
712
-							->numParams( 3 )
712
+							->numParams(3)
713 713
 							->rawParams(
714 714
 								$this->constraintParameterRenderer->formatItemIdList(
715 715
 									[
@@ -725,12 +725,12 @@  discard block
 block discarded – undo
725 725
 			}
726 726
 		}
727 727
 
728
-		if ( $validScopes !== null ) {
729
-			$invalidScopes = array_diff( $contextTypes, $validScopes );
730
-			if ( $invalidScopes !== [] ) {
731
-				$invalidScope = array_pop( $invalidScopes );
728
+		if ($validScopes !== null) {
729
+			$invalidScopes = array_diff($contextTypes, $validScopes);
730
+			if ($invalidScopes !== []) {
731
+				$invalidScope = array_pop($invalidScopes);
732 732
 				throw new ConstraintParameterException(
733
-					wfMessage( 'wbqc-violation-message-invalid-scope' )
733
+					wfMessage('wbqc-violation-message-invalid-scope')
734 734
 						->rawParams(
735 735
 							$this->constraintParameterRenderer->formatConstraintScope(
736 736
 								$invalidScope,
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 								Role::CONSTRAINT_TYPE_ITEM
742 742
 							)
743 743
 						)
744
-						->numParams( count( $validScopes ) )
744
+						->numParams(count($validScopes))
745 745
 						->rawParams(
746 746
 							$this->constraintParameterRenderer->formatConstraintScopeList(
747 747
 								$validScopes,
Please login to merge, or discard this patch.