Completed
Push — master ( 57089b...06ffb3 )
by
unknown
02:43
created
src/ConstraintCheck/Helper/ConstraintParameterParser.php 1 patch
Spacing   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -78,15 +78,15 @@  discard block
 block discarded – undo
78 78
 	 * @param array $parameters
79 79
 	 * @throws ConstraintParameterException
80 80
 	 */
81
-	public function checkError( array $parameters ) {
82
-		if ( array_key_exists( '@error', $parameters ) ) {
81
+	public function checkError(array $parameters) {
82
+		if (array_key_exists('@error', $parameters)) {
83 83
 			$error = $parameters['@error'];
84
-			if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) {
84
+			if (array_key_exists('toolong', $error) && $error['toolong']) {
85 85
 				$msg = 'wbqc-violation-message-parameters-error-toolong';
86 86
 			} else {
87 87
 				$msg = 'wbqc-violation-message-parameters-error-unknown';
88 88
 			}
89
-			throw new ConstraintParameterException( wfMessage( $msg )->escaped() );
89
+			throw new ConstraintParameterException(wfMessage($msg)->escaped());
90 90
 		}
91 91
 	}
92 92
 
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
 	 * @param string $parameterId
97 97
 	 * @throws ConstraintParameterException
98 98
 	 */
99
-	private function requireSingleParameter( array $parameters, $parameterId ) {
100
-		if ( count( $parameters[$parameterId] ) !== 1 ) {
99
+	private function requireSingleParameter(array $parameters, $parameterId) {
100
+		if (count($parameters[$parameterId]) !== 1) {
101 101
 			throw new ConstraintParameterException(
102
-				wfMessage( 'wbqc-violation-message-parameter-single' )
103
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
102
+				wfMessage('wbqc-violation-message-parameter-single')
103
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
104 104
 					->escaped()
105 105
 			);
106 106
 		}
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
 	 * @return void
114 114
 	 * @throws ConstraintParameterException
115 115
 	 */
116
-	private function requireValueParameter( Snak $snak, $parameterId ) {
117
-		if ( !( $snak instanceof PropertyValueSnak ) ) {
116
+	private function requireValueParameter(Snak $snak, $parameterId) {
117
+		if (!($snak instanceof PropertyValueSnak)) {
118 118
 			throw new ConstraintParameterException(
119
-				wfMessage( 'wbqc-violation-message-parameter-value' )
120
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
119
+				wfMessage('wbqc-violation-message-parameter-value')
120
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
121 121
 					->escaped()
122 122
 			);
123 123
 		}
@@ -130,18 +130,18 @@  discard block
 block discarded – undo
130 130
 	 * @throws ConstraintParameterException
131 131
 	 * @return EntityId
132 132
 	 */
133
-	private function parseEntityIdParameter( array $snakSerialization, $parameterId ) {
134
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
135
-		$this->requireValueParameter( $snak, $parameterId );
133
+	private function parseEntityIdParameter(array $snakSerialization, $parameterId) {
134
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
135
+		$this->requireValueParameter($snak, $parameterId);
136 136
 		$value = $snak->getDataValue();
137
-		if ( $value instanceof EntityIdValue ) {
137
+		if ($value instanceof EntityIdValue) {
138 138
 			return $value->getEntityId();
139 139
 		} else {
140 140
 			throw new ConstraintParameterException(
141
-				wfMessage( 'wbqc-violation-message-parameter-entity' )
141
+				wfMessage('wbqc-violation-message-parameter-entity')
142 142
 					->rawParams(
143
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
144
-						$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
143
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
144
+						$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
145 145
 					)
146 146
 					->escaped()
147 147
 			);
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
155 155
 	 * @return string[] class entity ID serializations
156 156
 	 */
157
-	public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) {
158
-		$this->checkError( $constraintParameters );
159
-		$classId = $this->config->get( 'WBQualityConstraintsClassId' );
160
-		if ( !array_key_exists( $classId, $constraintParameters ) ) {
157
+	public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) {
158
+		$this->checkError($constraintParameters);
159
+		$classId = $this->config->get('WBQualityConstraintsClassId');
160
+		if (!array_key_exists($classId, $constraintParameters)) {
161 161
 			throw new ConstraintParameterException(
162
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
163
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
164
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
162
+				wfMessage('wbqc-violation-message-parameter-needed')
163
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
164
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY))
165 165
 					->escaped()
166 166
 			);
167 167
 		}
168 168
 
169 169
 		$classes = [];
170
-		foreach ( $constraintParameters[$classId] as $class ) {
171
-			$classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization();
170
+		foreach ($constraintParameters[$classId] as $class) {
171
+			$classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization();
172 172
 		}
173 173
 		return $classes;
174 174
 	}
@@ -179,24 +179,24 @@  discard block
 block discarded – undo
179 179
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
180 180
 	 * @return string 'instance', 'subclass', or 'instanceOrSubclass'
181 181
 	 */
182
-	public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) {
183
-		$this->checkError( $constraintParameters );
184
-		$relationId = $this->config->get( 'WBQualityConstraintsRelationId' );
185
-		if ( !array_key_exists( $relationId, $constraintParameters ) ) {
182
+	public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) {
183
+		$this->checkError($constraintParameters);
184
+		$relationId = $this->config->get('WBQualityConstraintsRelationId');
185
+		if (!array_key_exists($relationId, $constraintParameters)) {
186 186
 			throw new ConstraintParameterException(
187
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
188
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
189
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
187
+				wfMessage('wbqc-violation-message-parameter-needed')
188
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
189
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY))
190 190
 					->escaped()
191 191
 			);
192 192
 		}
193 193
 
194
-		$this->requireSingleParameter( $constraintParameters, $relationId );
195
-		$relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId );
196
-		$instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' );
197
-		$subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' );
198
-		$instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' );
199
-		switch ( $relationEntityId ) {
194
+		$this->requireSingleParameter($constraintParameters, $relationId);
195
+		$relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId);
196
+		$instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId');
197
+		$subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId');
198
+		$instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId');
199
+		switch ($relationEntityId) {
200 200
 			case $instanceId:
201 201
 				return 'instance';
202 202
 			case $subclassId:
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
 				return 'instanceOrSubclass';
206 206
 			default:
207 207
 				throw new ConstraintParameterException(
208
-					wfMessage( 'wbqc-violation-message-parameter-oneof' )
209
-						->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
210
-						->numParams( 3 )
211
-						->rawParams( $this->constraintParameterRenderer->formatItemIdList(
212
-							[ $instanceId, $subclassId, $instanceOrSubclassId ],
208
+					wfMessage('wbqc-violation-message-parameter-oneof')
209
+						->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY))
210
+						->numParams(3)
211
+						->rawParams($this->constraintParameterRenderer->formatItemIdList(
212
+							[$instanceId, $subclassId, $instanceOrSubclassId],
213 213
 							Role::CONSTRAINT_PARAMETER_VALUE
214
-						) )
214
+						))
215 215
 						->escaped()
216 216
 				);
217 217
 		}
@@ -224,21 +224,21 @@  discard block
 block discarded – undo
224 224
 	 * @throws ConstraintParameterException
225 225
 	 * @return PropertyId
226 226
 	 */
227
-	private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) {
228
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
229
-		$this->requireValueParameter( $snak, $parameterId );
227
+	private function parsePropertyIdParameter(array $snakSerialization, $parameterId) {
228
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
229
+		$this->requireValueParameter($snak, $parameterId);
230 230
 		$value = $snak->getDataValue();
231
-		if ( $value instanceof EntityIdValue ) {
231
+		if ($value instanceof EntityIdValue) {
232 232
 			$id = $value->getEntityId();
233
-			if ( $id instanceof PropertyId ) {
233
+			if ($id instanceof PropertyId) {
234 234
 				return $id;
235 235
 			}
236 236
 		}
237 237
 		throw new ConstraintParameterException(
238
-			wfMessage( 'wbqc-violation-message-parameter-property' )
238
+			wfMessage('wbqc-violation-message-parameter-property')
239 239
 				->rawParams(
240
-					$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
241
-					$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
240
+					$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
241
+					$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
242 242
 				)
243 243
 				->escaped()
244 244
 		);
@@ -251,34 +251,34 @@  discard block
 block discarded – undo
251 251
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
252 252
 	 * @return PropertyId
253 253
 	 */
254
-	public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) {
255
-		$this->checkError( $constraintParameters );
256
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
257
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
254
+	public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) {
255
+		$this->checkError($constraintParameters);
256
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
257
+		if (!array_key_exists($propertyId, $constraintParameters)) {
258 258
 			throw new ConstraintParameterException(
259
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
260
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
261
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
259
+				wfMessage('wbqc-violation-message-parameter-needed')
260
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
261
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY))
262 262
 					->escaped()
263 263
 			);
264 264
 		}
265 265
 
266
-		$this->requireSingleParameter( $constraintParameters, $propertyId );
267
-		return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId );
266
+		$this->requireSingleParameter($constraintParameters, $propertyId);
267
+		return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId);
268 268
 	}
269 269
 
270
-	private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) {
270
+	private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) {
271 271
 		$dataValue = $snak->getDataValue();
272
-		if ( $dataValue instanceof EntityIdValue &&
272
+		if ($dataValue instanceof EntityIdValue &&
273 273
 			$dataValue->getEntityId() instanceof ItemId
274 274
 		) {
275
-			return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() );
275
+			return ItemIdSnakValue::fromItemId($dataValue->getEntityId());
276 276
 		} else {
277 277
 			throw new ConstraintParameterException(
278
-				wfMessage( 'wbqc-violation-message-parameter-item' )
278
+				wfMessage('wbqc-violation-message-parameter-item')
279 279
 					->rawParams(
280
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
281
-						$this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
280
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
281
+						$this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
282 282
 					)
283 283
 					->escaped()
284 284
 			);
@@ -292,15 +292,15 @@  discard block
 block discarded – undo
292 292
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
293 293
 	 * @return ItemIdSnakValue[] array of values
294 294
 	 */
295
-	public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) {
296
-		$this->checkError( $constraintParameters );
297
-		$qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
298
-		if ( !array_key_exists( $qualifierId, $constraintParameters ) ) {
299
-			if ( $required ) {
295
+	public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) {
296
+		$this->checkError($constraintParameters);
297
+		$qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
298
+		if (!array_key_exists($qualifierId, $constraintParameters)) {
299
+			if ($required) {
300 300
 				throw new ConstraintParameterException(
301
-					wfMessage( 'wbqc-violation-message-parameter-needed' )
302
-						->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
303
-						->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
301
+					wfMessage('wbqc-violation-message-parameter-needed')
302
+						->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
303
+						->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY))
304 304
 						->escaped()
305 305
 				);
306 306
 			} else {
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
 		}
310 310
 
311 311
 		$values = [];
312
-		foreach ( $constraintParameters[$qualifierId] as $parameter ) {
313
-			$snak = $this->snakDeserializer->deserialize( $parameter );
314
-			switch ( true ) {
312
+		foreach ($constraintParameters[$qualifierId] as $parameter) {
313
+			$snak = $this->snakDeserializer->deserialize($parameter);
314
+			switch (true) {
315 315
 				case $snak instanceof PropertyValueSnak:
316
-					$values[] = $this->parseItemIdParameter( $snak, $qualifierId );
316
+					$values[] = $this->parseItemIdParameter($snak, $qualifierId);
317 317
 					break;
318 318
 				case $snak instanceof PropertySomeValueSnak:
319 319
 					$values[] = ItemIdSnakValue::someValue();
@@ -332,28 +332,28 @@  discard block
 block discarded – undo
332 332
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
333 333
 	 * @return PropertyId[]
334 334
 	 */
335
-	public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) {
336
-		$this->checkError( $constraintParameters );
337
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
338
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
335
+	public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) {
336
+		$this->checkError($constraintParameters);
337
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
338
+		if (!array_key_exists($propertyId, $constraintParameters)) {
339 339
 			throw new ConstraintParameterException(
340
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
341
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
342
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
340
+				wfMessage('wbqc-violation-message-parameter-needed')
341
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
342
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY))
343 343
 					->escaped()
344 344
 			);
345 345
 		}
346 346
 
347 347
 		$parameters = $constraintParameters[$propertyId];
348
-		if ( count( $parameters ) === 1 &&
349
-			$this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak
348
+		if (count($parameters) === 1 &&
349
+			$this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak
350 350
 		) {
351 351
 			return [];
352 352
 		}
353 353
 
354 354
 		$properties = [];
355
-		foreach ( $parameters as $parameter ) {
356
-			$properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId );
355
+		foreach ($parameters as $parameter) {
356
+			$properties[] = $this->parsePropertyIdParameter($parameter, $propertyId);
357 357
 		}
358 358
 		return $properties;
359 359
 	}
@@ -364,16 +364,16 @@  discard block
 block discarded – undo
364 364
 	 * @throws ConstraintParameterException
365 365
 	 * @return DataValue|null
366 366
 	 */
367
-	private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) {
368
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
369
-		if ( $snak instanceof PropertyValueSnak ) {
367
+	private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) {
368
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
369
+		if ($snak instanceof PropertyValueSnak) {
370 370
 			return $snak->getDataValue();
371
-		} elseif ( $snak instanceof PropertyNoValueSnak ) {
371
+		} elseif ($snak instanceof PropertyNoValueSnak) {
372 372
 			return null;
373 373
 		} else {
374 374
 			throw new ConstraintParameterException(
375
-				wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' )
376
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
375
+				wfMessage('wbqc-violation-message-parameter-value-or-novalue')
376
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
377 377
 					->escaped()
378 378
 			);
379 379
 		}
@@ -384,13 +384,13 @@  discard block
 block discarded – undo
384 384
 	 * @param string $parameterId
385 385
 	 * @return DataValue|null
386 386
 	 */
387
-	private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) {
387
+	private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) {
388 388
 		try {
389
-			return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId );
390
-		} catch ( ConstraintParameterException $e ) {
389
+			return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId);
390
+		} catch (ConstraintParameterException $e) {
391 391
 			// unknown value means “now”
392
-			$timeParser = ( new TimeParserFactory() )->getTimeParser();
393
-			return $timeParser->parse( gmdate( '+Y-m-d\T00:00:00\Z' ) );
392
+			$timeParser = (new TimeParserFactory())->getTimeParser();
393
+			return $timeParser->parse(gmdate('+Y-m-d\T00:00:00\Z'));
394 394
 		}
395 395
 	}
396 396
 
@@ -401,14 +401,14 @@  discard block
 block discarded – undo
401 401
 	 * @param string $unit
402 402
 	 * @return bool
403 403
 	 */
404
-	private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) {
405
-		if ( !( $min instanceof UnboundedQuantityValue ) ||
406
-			!( $max instanceof UnboundedQuantityValue )
404
+	private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) {
405
+		if (!($min instanceof UnboundedQuantityValue) ||
406
+			!($max instanceof UnboundedQuantityValue)
407 407
 		) {
408 408
 			return false;
409 409
 		}
410 410
 
411
-		return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit );
411
+		return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit);
412 412
 	}
413 413
 
414 414
 	/**
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
420 420
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
421 421
 	 */
422
-	public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) {
423
-		$this->checkError( $constraintParameters );
424
-		switch ( $type ) {
422
+	public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) {
423
+		$this->checkError($constraintParameters);
424
+		switch ($type) {
425 425
 			case 'quantity':
426 426
 				$configKey = 'Quantity';
427 427
 				break;
@@ -430,47 +430,47 @@  discard block
 block discarded – undo
430 430
 				break;
431 431
 			default:
432 432
 				throw new ConstraintParameterException(
433
-					wfMessage( 'wbqc-violation-message-value-needed-of-types-2' )
433
+					wfMessage('wbqc-violation-message-value-needed-of-types-2')
434 434
 						->rawParams(
435
-							$this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ),
436
-							wfMessage( 'datatypes-type-quantity' )->escaped(),
437
-							wfMessage( 'datatypes-type-time' )->escaped()
435
+							$this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM),
436
+							wfMessage('datatypes-type-quantity')->escaped(),
437
+							wfMessage('datatypes-type-time')->escaped()
438 438
 						)
439 439
 						->escaped()
440 440
 				);
441 441
 		}
442
-		$minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' );
443
-		$maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' );
444
-		if ( !array_key_exists( $minimumId, $constraintParameters ) ||
445
-			!array_key_exists( $maximumId, $constraintParameters )
442
+		$minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id');
443
+		$maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id');
444
+		if (!array_key_exists($minimumId, $constraintParameters) ||
445
+			!array_key_exists($maximumId, $constraintParameters)
446 446
 		) {
447 447
 			throw new ConstraintParameterException(
448
-				wfMessage( 'wbqc-violation-message-range-parameters-needed' )
448
+				wfMessage('wbqc-violation-message-range-parameters-needed')
449 449
 					->rawParams(
450
-						wfMessage( 'datatypes-type-' . $type )->escaped(),
451
-						$this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
452
-						$this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY )
450
+						wfMessage('datatypes-type-'.$type)->escaped(),
451
+						$this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY),
452
+						$this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY)
453 453
 					)
454
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
454
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
455 455
 					->escaped()
456 456
 			);
457 457
 		}
458 458
 
459
-		$this->requireSingleParameter( $constraintParameters, $minimumId );
460
-		$this->requireSingleParameter( $constraintParameters, $maximumId );
459
+		$this->requireSingleParameter($constraintParameters, $minimumId);
460
+		$this->requireSingleParameter($constraintParameters, $maximumId);
461 461
 		$parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter';
462
-		$min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId );
463
-		$max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId );
462
+		$min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId);
463
+		$max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId);
464 464
 
465
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
466
-		if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) {
465
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
466
+		if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) {
467 467
 			throw new ConstraintParameterException(
468
-				wfMessage( 'wbqc-violation-message-range-parameters-one-year' )
468
+				wfMessage('wbqc-violation-message-range-parameters-one-year')
469 469
 					->escaped()
470 470
 			);
471 471
 		}
472 472
 
473
-		return [ $min, $max ];
473
+		return [$min, $max];
474 474
 	}
475 475
 
476 476
 	/**
@@ -480,18 +480,18 @@  discard block
 block discarded – undo
480 480
 	 * @throws ConstraintParameterException
481 481
 	 * @return string
482 482
 	 */
483
-	private function parseStringParameter( array $snakSerialization, $parameterId ) {
484
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
485
-		$this->requireValueParameter( $snak, $parameterId );
483
+	private function parseStringParameter(array $snakSerialization, $parameterId) {
484
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
485
+		$this->requireValueParameter($snak, $parameterId);
486 486
 		$value = $snak->getDataValue();
487
-		if ( $value instanceof StringValue ) {
487
+		if ($value instanceof StringValue) {
488 488
 			return $value->getValue();
489 489
 		} else {
490 490
 			throw new ConstraintParameterException(
491
-				wfMessage( 'wbqc-violation-message-parameter-string' )
491
+				wfMessage('wbqc-violation-message-parameter-string')
492 492
 					->rawParams(
493
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
494
-						$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
493
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
494
+						$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
495 495
 					)
496 496
 					->escaped()
497 497
 			);
@@ -504,15 +504,15 @@  discard block
 block discarded – undo
504 504
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
505 505
 	 * @return string
506 506
 	 */
507
-	public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) {
508
-		$this->checkError( $constraintParameters );
509
-		$namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' );
510
-		if ( !array_key_exists( $namespaceId, $constraintParameters ) ) {
507
+	public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) {
508
+		$this->checkError($constraintParameters);
509
+		$namespaceId = $this->config->get('WBQualityConstraintsNamespaceId');
510
+		if (!array_key_exists($namespaceId, $constraintParameters)) {
511 511
 			return '';
512 512
 		}
513 513
 
514
-		$this->requireSingleParameter( $constraintParameters, $namespaceId );
515
-		return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId );
514
+		$this->requireSingleParameter($constraintParameters, $namespaceId);
515
+		return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId);
516 516
 	}
517 517
 
518 518
 	/**
@@ -521,20 +521,20 @@  discard block
 block discarded – undo
521 521
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
522 522
 	 * @return string
523 523
 	 */
524
-	public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) {
525
-		$this->checkError( $constraintParameters );
526
-		$formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' );
527
-		if ( !array_key_exists( $formatId, $constraintParameters ) ) {
524
+	public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) {
525
+		$this->checkError($constraintParameters);
526
+		$formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId');
527
+		if (!array_key_exists($formatId, $constraintParameters)) {
528 528
 			throw new ConstraintParameterException(
529
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
530
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
531
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
529
+				wfMessage('wbqc-violation-message-parameter-needed')
530
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
531
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY))
532 532
 					->escaped()
533 533
 			);
534 534
 		}
535 535
 
536
-		$this->requireSingleParameter( $constraintParameters, $formatId );
537
-		return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId );
536
+		$this->requireSingleParameter($constraintParameters, $formatId);
537
+		return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId);
538 538
 	}
539 539
 
540 540
 	/**
@@ -542,16 +542,16 @@  discard block
 block discarded – undo
542 542
 	 * @throws ConstraintParameterException if the parameter is invalid
543 543
 	 * @return EntityId[]
544 544
 	 */
545
-	public function parseExceptionParameter( array $constraintParameters ) {
546
-		$this->checkError( $constraintParameters );
547
-		$exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' );
548
-		if ( !array_key_exists( $exceptionId, $constraintParameters ) ) {
545
+	public function parseExceptionParameter(array $constraintParameters) {
546
+		$this->checkError($constraintParameters);
547
+		$exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId');
548
+		if (!array_key_exists($exceptionId, $constraintParameters)) {
549 549
 			return [];
550 550
 		}
551 551
 
552 552
 		return array_map(
553
-			function( $snakSerialization ) use ( $exceptionId ) {
554
-				return $this->parseEntityIdParameter( $snakSerialization, $exceptionId );
553
+			function($snakSerialization) use ($exceptionId) {
554
+				return $this->parseEntityIdParameter($snakSerialization, $exceptionId);
555 555
 			},
556 556
 			$constraintParameters[$exceptionId]
557 557
 		);
@@ -562,27 +562,27 @@  discard block
 block discarded – undo
562 562
 	 * @throws ConstraintParameterException if the parameter is invalid
563 563
 	 * @return string|null 'mandatory' or null
564 564
 	 */
565
-	public function parseConstraintStatusParameter( array $constraintParameters ) {
566
-		$this->checkError( $constraintParameters );
567
-		$constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' );
568
-		if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) {
565
+	public function parseConstraintStatusParameter(array $constraintParameters) {
566
+		$this->checkError($constraintParameters);
567
+		$constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId');
568
+		if (!array_key_exists($constraintStatusId, $constraintParameters)) {
569 569
 			return null;
570 570
 		}
571 571
 
572
-		$mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' );
573
-		$this->requireSingleParameter( $constraintParameters, $constraintStatusId );
574
-		$snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] );
575
-		$this->requireValueParameter( $snak, $constraintStatusId );
572
+		$mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId');
573
+		$this->requireSingleParameter($constraintParameters, $constraintStatusId);
574
+		$snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]);
575
+		$this->requireValueParameter($snak, $constraintStatusId);
576 576
 		$statusId = $snak->getDataValue()->getEntityId()->getSerialization();
577 577
 
578
-		if ( $statusId === $mandatoryId ) {
578
+		if ($statusId === $mandatoryId) {
579 579
 			return 'mandatory';
580 580
 		} else {
581 581
 			throw new ConstraintParameterException(
582
-				wfMessage( 'wbqc-violation-message-parameter-oneof' )
583
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
584
-					->numParams( 1 )
585
-					->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) )
582
+				wfMessage('wbqc-violation-message-parameter-oneof')
583
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY))
584
+					->numParams(1)
585
+					->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE))
586 586
 					->escaped()
587 587
 			);
588 588
 		}
@@ -595,13 +595,13 @@  discard block
 block discarded – undo
595 595
 	 * @return void
596 596
 	 * @throws ConstraintParameterException
597 597
 	 */
598
-	private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) {
599
-		if ( !( $dataValue instanceof MonolingualTextValue ) ) {
598
+	private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) {
599
+		if (!($dataValue instanceof MonolingualTextValue)) {
600 600
 			throw new ConstraintParameterException(
601
-				wfMessage( 'wbqc-violation-message-parameter-monolingualtext' )
601
+				wfMessage('wbqc-violation-message-parameter-monolingualtext')
602 602
 					->rawParams(
603
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
604
-						$this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
603
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
604
+						$this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
605 605
 					)
606 606
 					->escaped()
607 607
 			);
@@ -616,26 +616,26 @@  discard block
 block discarded – undo
616 616
 	 * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts
617 617
 	 * @return MultilingualTextValue
618 618
 	 */
619
-	private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) {
619
+	private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) {
620 620
 		$result = [];
621 621
 
622
-		foreach ( $snakSerializations as $snakSerialization ) {
623
-			$snak = $this->snakDeserializer->deserialize( $snakSerialization );
624
-			$this->requireValueParameter( $snak, $parameterId );
622
+		foreach ($snakSerializations as $snakSerialization) {
623
+			$snak = $this->snakDeserializer->deserialize($snakSerialization);
624
+			$this->requireValueParameter($snak, $parameterId);
625 625
 
626 626
 			$value = $snak->getDataValue();
627
-			$this->requireMonolingualTextParameter( $value, $parameterId );
627
+			$this->requireMonolingualTextParameter($value, $parameterId);
628 628
 			/** @var MonolingualTextValue $value */
629 629
 
630 630
 			$code = $value->getLanguageCode();
631
-			if ( array_key_exists( $code, $result ) ) {
631
+			if (array_key_exists($code, $result)) {
632 632
 				throw new ConstraintParameterException(
633
-					wfMessage( 'wbqc-violation-message-parameter-single-per-language' )
633
+					wfMessage('wbqc-violation-message-parameter-single-per-language')
634 634
 						->rawParams(
635
-							$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY )
635
+							$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)
636 636
 						)
637 637
 						->plaintextParams(
638
-							Language::fetchLanguageName( $code ),
638
+							Language::fetchLanguageName($code),
639 639
 							$code
640 640
 						)
641 641
 						->escaped()
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 			$result[$code] = $value;
646 646
 		}
647 647
 
648
-		return new MultilingualTextValue( $result );
648
+		return new MultilingualTextValue($result);
649 649
 	}
650 650
 
651 651
 	/**
@@ -653,11 +653,11 @@  discard block
 block discarded – undo
653 653
 	 * @throws ConstraintParameterException if the parameter is invalid
654 654
 	 * @return MultilingualTextValue
655 655
 	 */
656
-	public function parseSyntaxClarificationParameter( array $constraintParameters ) {
657
-		$syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' );
656
+	public function parseSyntaxClarificationParameter(array $constraintParameters) {
657
+		$syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId');
658 658
 
659
-		if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) {
660
-			return new MultilingualTextValue( [] );
659
+		if (!array_key_exists($syntaxClarificationId, $constraintParameters)) {
660
+			return new MultilingualTextValue([]);
661 661
 		}
662 662
 
663 663
 		$syntaxClarifications = $this->parseMultilingualTextParameter(
@@ -676,20 +676,20 @@  discard block
 block discarded – undo
676 676
 	 * @throws ConstraintParameterException if the parameter is invalid
677 677
 	 * @return string[]|null Context::TYPE_* constants
678 678
 	 */
679
-	public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) {
680
-		$constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' );
681
-		$mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' );
682
-		$qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' );
683
-		$referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' );
679
+	public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) {
680
+		$constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId');
681
+		$mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId');
682
+		$qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId');
683
+		$referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId');
684 684
 
685
-		if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) {
685
+		if (!array_key_exists($constraintScopeId, $constraintParameters)) {
686 686
 			return null;
687 687
 		}
688 688
 
689 689
 		$contextTypes = [];
690
-		foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) {
691
-			$scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId );
692
-			switch ( $scopeEntityId->getSerialization() ) {
690
+		foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) {
691
+			$scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId);
692
+			switch ($scopeEntityId->getSerialization()) {
693 693
 				case $mainSnakId:
694 694
 					$contextTypes[] = Context::TYPE_STATEMENT;
695 695
 					break;
@@ -701,14 +701,14 @@  discard block
 block discarded – undo
701 701
 					break;
702 702
 				default:
703 703
 					throw new ConstraintParameterException(
704
-						wfMessage( 'wbqc-violation-message-parameter-oneof' )
704
+						wfMessage('wbqc-violation-message-parameter-oneof')
705 705
 							->rawParams(
706 706
 								$this->constraintParameterRenderer->formatPropertyId(
707 707
 									$constraintScopeId,
708 708
 									Role::CONSTRAINT_PARAMETER_PROPERTY
709 709
 								)
710 710
 							)
711
-							->numParams( 3 )
711
+							->numParams(3)
712 712
 							->rawParams(
713 713
 								$this->constraintParameterRenderer->formatItemIdList(
714 714
 									[
@@ -724,12 +724,12 @@  discard block
 block discarded – undo
724 724
 			}
725 725
 		}
726 726
 
727
-		if ( $validScopes !== null ) {
728
-			$invalidScopes = array_diff( $contextTypes, $validScopes );
729
-			if ( $invalidScopes !== [] ) {
730
-				$invalidScope = array_pop( $invalidScopes );
727
+		if ($validScopes !== null) {
728
+			$invalidScopes = array_diff($contextTypes, $validScopes);
729
+			if ($invalidScopes !== []) {
730
+				$invalidScope = array_pop($invalidScopes);
731 731
 				throw new ConstraintParameterException(
732
-					wfMessage( 'wbqc-violation-message-invalid-scope' )
732
+					wfMessage('wbqc-violation-message-invalid-scope')
733 733
 						->rawParams(
734 734
 							$this->constraintParameterRenderer->formatConstraintScope(
735 735
 								$invalidScope,
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 								Role::CONSTRAINT_TYPE_ITEM
741 741
 							)
742 742
 						)
743
-						->numParams( count( $validScopes ) )
743
+						->numParams(count($validScopes))
744 744
 						->rawParams(
745 745
 							$this->constraintParameterRenderer->formatConstraintScopeList(
746 746
 								$validScopes,
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/FormatChecker.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
 	 * @throws ConstraintParameterException
94 94
 	 * @return CheckResult
95 95
 	 */
96
-	public function checkConstraint( Context $context, Constraint $constraint ) {
96
+	public function checkConstraint(Context $context, Constraint $constraint) {
97 97
 		$parameters = [];
98 98
 		$constraintParameters = $constraint->getConstraintParameters();
99 99
 
100
-		$format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
101
-		$parameters['pattern'] = [ $format ];
100
+		$format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId());
101
+		$parameters['pattern'] = [$format];
102 102
 
103 103
 		$syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter(
104 104
 			$constraintParameters
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 
107 107
 		$snak = $context->getSnak();
108 108
 
109
-		if ( !$snak instanceof PropertyValueSnak ) {
109
+		if (!$snak instanceof PropertyValueSnak) {
110 110
 			// nothing to check
111
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
111
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
112 112
 		}
113 113
 
114 114
 		$dataValue = $snak->getDataValue();
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		 * error handling:
118 118
 		 *   type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext'
119 119
 		 */
120
-		switch ( $dataValue->getType() ) {
120
+		switch ($dataValue->getType()) {
121 121
 			case 'string':
122 122
 				$text = $dataValue->getValue();
123 123
 				break;
@@ -126,46 +126,46 @@  discard block
 block discarded – undo
126 126
 				$text = $dataValue->getText();
127 127
 				break;
128 128
 			default:
129
-				$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) )
130
-					->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
131
-					->withDataValueType( 'string' )
132
-					->withDataValueType( 'monolingualtext' );
133
-				return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
129
+				$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2'))
130
+					->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
131
+					->withDataValueType('string')
132
+					->withDataValueType('monolingualtext');
133
+				return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
134 134
 		}
135 135
 
136
-		if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) {
137
-			if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) {
136
+		if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) {
137
+			if ($this->sparqlHelper->matchesRegularExpression($text, $format)) {
138 138
 				$message = null;
139 139
 				$status = CheckResult::STATUS_COMPLIANCE;
140 140
 			} else {
141
-				$message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) )
142
-					->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY )
143
-					->withDataValue( new StringValue( $text ), Role::OBJECT )
144
-					->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE )
145
-					->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE );
141
+				$message = (new ViolationMessage('wbqc-violation-message-format-clarification'))
142
+					->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY)
143
+					->withDataValue(new StringValue($text), Role::OBJECT)
144
+					->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE)
145
+					->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE);
146 146
 				$status = CheckResult::STATUS_VIOLATION;
147 147
 			}
148 148
 		} else {
149
-			$message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) )
150
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM );
149
+			$message = (new ViolationMessage('wbqc-violation-message-security-reason'))
150
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM);
151 151
 			$status = CheckResult::STATUS_TODO;
152 152
 		}
153
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
153
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
154 154
 	}
155 155
 
156
-	public function checkConstraintParameters( Constraint $constraint ) {
156
+	public function checkConstraintParameters(Constraint $constraint) {
157 157
 		$constraintParameters = $constraint->getConstraintParameters();
158 158
 		$exceptions = [];
159 159
 		try {
160
-			$this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
161
-		} catch ( ConstraintParameterException $e ) {
160
+			$this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId());
161
+		} catch (ConstraintParameterException $e) {
162 162
 			$exceptions[] = $e;
163 163
 		}
164 164
 		try {
165 165
 			$this->constraintParameterParser->parseSyntaxClarificationParameter(
166 166
 				$constraintParameters
167 167
 			);
168
-		} catch ( ConstraintParameterException $e ) {
168
+		} catch (ConstraintParameterException $e) {
169 169
 			$exceptions[] = $e;
170 170
 		}
171 171
 		return $exceptions;
Please login to merge, or discard this patch.