Completed
Push — master ( 7f5e0a...4d626c )
by
unknown
21s
created
src/ConstraintsServices.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -40,91 +40,91 @@
 block discarded – undo
40 40
 	public const EXPIRY_LOCK = 'WBQC_ExpiryLock';
41 41
 	public const VIOLATION_MESSAGE_RENDERER_FACTORY = 'WBQC_ViolationMessageRendererFactory';
42 42
 
43
-	private static function getService( ?MediaWikiServices $services, $name ) {
43
+	private static function getService(?MediaWikiServices $services, $name) {
44 44
 		$services ??= MediaWikiServices::getInstance();
45
-		return $services->getService( $name );
45
+		return $services->getService($name);
46 46
 	}
47 47
 
48
-	public static function getLoggingHelper( MediaWikiServices $services = null ): LoggingHelper {
49
-		return self::getService( $services, self::LOGGING_HELPER );
48
+	public static function getLoggingHelper(MediaWikiServices $services = null): LoggingHelper {
49
+		return self::getService($services, self::LOGGING_HELPER);
50 50
 	}
51 51
 
52 52
 	public static function getConstraintStore(
53 53
 		MediaWikiServices $services = null
54 54
 	): ConstraintStore {
55
-		return self::getService( $services, self::CONSTRAINT_STORE );
55
+		return self::getService($services, self::CONSTRAINT_STORE);
56 56
 	}
57 57
 
58
-	public static function getConstraintLookup( MediaWikiServices $services = null ): ConstraintLookup {
59
-		return self::getService( $services, self::CONSTRAINT_LOOKUP );
58
+	public static function getConstraintLookup(MediaWikiServices $services = null): ConstraintLookup {
59
+		return self::getService($services, self::CONSTRAINT_LOOKUP);
60 60
 	}
61 61
 
62 62
 	public static function getCheckResultSerializer(
63 63
 		MediaWikiServices $services = null
64 64
 	): CheckResultSerializer {
65
-		return self::getService( $services, self::CHECK_RESULT_SERIALIZER );
65
+		return self::getService($services, self::CHECK_RESULT_SERIALIZER);
66 66
 	}
67 67
 
68 68
 	public static function getCheckResultDeserializer(
69 69
 		MediaWikiServices $services = null
70 70
 	): CheckResultDeserializer {
71
-		return self::getService( $services, self::CHECK_RESULT_DESERIALIZER );
71
+		return self::getService($services, self::CHECK_RESULT_DESERIALIZER);
72 72
 	}
73 73
 
74 74
 	public static function getViolationMessageSerializer(
75 75
 		MediaWikiServices $services = null
76 76
 	): ViolationMessageSerializer {
77
-		return self::getService( $services, self::VIOLATION_MESSAGE_SERIALIZER );
77
+		return self::getService($services, self::VIOLATION_MESSAGE_SERIALIZER);
78 78
 	}
79 79
 
80 80
 	public static function getViolationMessageDeserializer(
81 81
 		MediaWikiServices $services = null
82 82
 	): ViolationMessageDeserializer {
83
-		return self::getService( $services, self::VIOLATION_MESSAGE_DESERIALIZER );
83
+		return self::getService($services, self::VIOLATION_MESSAGE_DESERIALIZER);
84 84
 	}
85 85
 
86 86
 	public static function getConstraintParameterParser(
87 87
 		MediaWikiServices $services = null
88 88
 	): ConstraintParameterParser {
89
-		return self::getService( $services, self::CONSTRAINT_PARAMETER_PARSER );
89
+		return self::getService($services, self::CONSTRAINT_PARAMETER_PARSER);
90 90
 	}
91 91
 
92 92
 	public static function getConnectionCheckerHelper(
93 93
 		MediaWikiServices $services = null
94 94
 	): ConnectionCheckerHelper {
95
-		return self::getService( $services, self::CONNECTION_CHECKER_HELPER );
95
+		return self::getService($services, self::CONNECTION_CHECKER_HELPER);
96 96
 	}
97 97
 
98
-	public static function getRangeCheckerHelper( MediaWikiServices $services = null ): RangeCheckerHelper {
99
-		return self::getService( $services, self::RANGE_CHECKER_HELPER );
98
+	public static function getRangeCheckerHelper(MediaWikiServices $services = null): RangeCheckerHelper {
99
+		return self::getService($services, self::RANGE_CHECKER_HELPER);
100 100
 	}
101 101
 
102
-	public static function getSparqlHelper( MediaWikiServices $services = null ): SparqlHelper {
103
-		return self::getService( $services, self::SPARQL_HELPER );
102
+	public static function getSparqlHelper(MediaWikiServices $services = null): SparqlHelper {
103
+		return self::getService($services, self::SPARQL_HELPER);
104 104
 	}
105 105
 
106
-	public static function getTypeCheckerHelper( MediaWikiServices $services = null ): TypeCheckerHelper {
107
-		return self::getService( $services, self::TYPE_CHECKER_HELPER );
106
+	public static function getTypeCheckerHelper(MediaWikiServices $services = null): TypeCheckerHelper {
107
+		return self::getService($services, self::TYPE_CHECKER_HELPER);
108 108
 	}
109 109
 
110 110
 	public static function getDelegatingConstraintChecker(
111 111
 		MediaWikiServices $services = null
112 112
 	): DelegatingConstraintChecker {
113
-		return self::getService( $services, self::DELEGATING_CONSTRAINT_CHECKER );
113
+		return self::getService($services, self::DELEGATING_CONSTRAINT_CHECKER);
114 114
 	}
115 115
 
116
-	public static function getResultsSource( MediaWikiServices $services = null ): ResultsSource {
117
-		return self::getService( $services, self::RESULTS_SOURCE );
116
+	public static function getResultsSource(MediaWikiServices $services = null): ResultsSource {
117
+		return self::getService($services, self::RESULTS_SOURCE);
118 118
 	}
119 119
 
120
-	public static function getExpiryLock( MediaWikiServices $services = null ): ExpiryLock {
121
-		return self::getService( $services, self::EXPIRY_LOCK );
120
+	public static function getExpiryLock(MediaWikiServices $services = null): ExpiryLock {
121
+		return self::getService($services, self::EXPIRY_LOCK);
122 122
 	}
123 123
 
124 124
 	public static function getViolationMessageRendererFactory(
125 125
 		MediaWikiServices $services = null
126 126
 	): ViolationMessageRendererFactory {
127
-		return self::getService( $services, self::VIOLATION_MESSAGE_RENDERER_FACTORY );
127
+		return self::getService($services, self::VIOLATION_MESSAGE_RENDERER_FACTORY);
128 128
 	}
129 129
 
130 130
 }
Please login to merge, or discard this patch.
src/WikibaseServices.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,33 +20,33 @@
 block discarded – undo
20 20
 	public const PROPERTY_DATA_TYPE_LOOKUP = 'WBQC_PropertyDataTypeLookup';
21 21
 	public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache';
22 22
 
23
-	private static function getService( ?MediaWikiServices $services, $name ) {
23
+	private static function getService(?MediaWikiServices $services, $name) {
24 24
 		$services ??= MediaWikiServices::getInstance();
25
-		return $services->getService( $name );
25
+		return $services->getService($name);
26 26
 	}
27 27
 
28 28
 	/**
29 29
 	 * @param MediaWikiServices|null $services
30 30
 	 * @return EntityLookup
31 31
 	 */
32
-	public static function getEntityLookup( MediaWikiServices $services = null ) {
33
-		return self::getService( $services, self::ENTITY_LOOKUP );
32
+	public static function getEntityLookup(MediaWikiServices $services = null) {
33
+		return self::getService($services, self::ENTITY_LOOKUP);
34 34
 	}
35 35
 
36 36
 	/**
37 37
 	 * @param MediaWikiServices|null $services
38 38
 	 * @return PropertyDataTypeLookup
39 39
 	 */
40
-	public static function getPropertyDataTypeLookup( MediaWikiServices $services = null ) {
41
-		return self::getService( $services, self::PROPERTY_DATA_TYPE_LOOKUP );
40
+	public static function getPropertyDataTypeLookup(MediaWikiServices $services = null) {
41
+		return self::getService($services, self::PROPERTY_DATA_TYPE_LOOKUP);
42 42
 	}
43 43
 
44 44
 	/**
45 45
 	 * @param MediaWikiServices|null $services
46 46
 	 * @return EntityLookup
47 47
 	 */
48
-	public static function getEntityLookupWithoutCache( MediaWikiServices $services = null ) {
49
-		return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE );
48
+	public static function getEntityLookupWithoutCache(MediaWikiServices $services = null) {
49
+		return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE);
50 50
 	}
51 51
 
52 52
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/DelegatingConstraintChecker.php 1 patch
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck;
6 6
 
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
 		callable $defaultResultsPerEntity = null
124 124
 	): array {
125 125
 		$checkResults = [];
126
-		$entity = $this->entityLookup->getEntity( $entityId );
126
+		$entity = $this->entityLookup->getEntity($entityId);
127 127
 
128
-		if ( $entity instanceof StatementListProvidingEntity ) {
129
-			$startTime = microtime( true );
128
+		if ($entity instanceof StatementListProvidingEntity) {
129
+			$startTime = microtime(true);
130 130
 
131 131
 			$checkResults = $this->checkEveryStatement(
132 132
 				$entity,
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 				$defaultResultsPerContext
135 135
 			);
136 136
 
137
-			$endTime = microtime( true );
137
+			$endTime = microtime(true);
138 138
 
139
-			if ( $constraintIds === null ) { // only log full constraint checks
139
+			if ($constraintIds === null) { // only log full constraint checks
140 140
 				$this->loggingHelper->logConstraintCheckOnEntity(
141 141
 					$entityId,
142 142
 					$checkResults,
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 			}
147 147
 		}
148 148
 
149
-		if ( $defaultResultsPerEntity !== null ) {
150
-			$checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults );
149
+		if ($defaultResultsPerEntity !== null) {
150
+			$checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults);
151 151
 		}
152 152
 
153
-		return $this->sortResult( $checkResults );
153
+		return $this->sortResult($checkResults);
154 154
 	}
155 155
 
156 156
 	/**
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
 		callable $defaultResults = null
173 173
 	): array {
174 174
 
175
-		$parsedGuid = $this->statementGuidParser->parse( $guid );
175
+		$parsedGuid = $this->statementGuidParser->parse($guid);
176 176
 		$entityId = $parsedGuid->getEntityId();
177
-		$entity = $this->entityLookup->getEntity( $entityId );
178
-		if ( $entity instanceof StatementListProvidingEntity ) {
179
-			$statement = $entity->getStatements()->getFirstStatementWithGuid( $guid );
180
-			if ( $statement ) {
177
+		$entity = $this->entityLookup->getEntity($entityId);
178
+		if ($entity instanceof StatementListProvidingEntity) {
179
+			$statement = $entity->getStatements()->getFirstStatementWithGuid($guid);
180
+			if ($statement) {
181 181
 				$result = $this->checkStatement(
182 182
 					$entity,
183 183
 					$statement,
184 184
 					$constraintIds,
185 185
 					$defaultResults
186 186
 				);
187
-				$output = $this->sortResult( $result );
187
+				$output = $this->sortResult($result);
188 188
 				return $output;
189 189
 			}
190 190
 		}
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
 		return [];
193 193
 	}
194 194
 
195
-	private function getValidContextTypes( Constraint $constraint ): array {
196
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
195
+	private function getValidContextTypes(Constraint $constraint): array {
196
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
197 197
 			return [
198 198
 				Context::TYPE_STATEMENT,
199 199
 				Context::TYPE_QUALIFIER,
@@ -201,21 +201,21 @@  discard block
 block discarded – undo
201 201
 			];
202 202
 		}
203 203
 
204
-		return array_keys( array_filter(
204
+		return array_keys(array_filter(
205 205
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(),
206
-			static fn ( $status ) => $status !== CheckResult::STATUS_NOT_IN_SCOPE
207
-		) );
206
+			static fn ($status) => $status !== CheckResult::STATUS_NOT_IN_SCOPE
207
+		));
208 208
 	}
209 209
 
210
-	private function getValidEntityTypes( Constraint $constraint ): array {
211
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
212
-			return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED );
210
+	private function getValidEntityTypes(Constraint $constraint): array {
211
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
212
+			return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED);
213 213
 		}
214 214
 
215
-		return array_keys( array_filter(
215
+		return array_keys(array_filter(
216 216
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(),
217
-			static fn ( $status ) => $status !== CheckResult::STATUS_NOT_IN_SCOPE
218
-		) );
217
+			static fn ($status) => $status !== CheckResult::STATUS_NOT_IN_SCOPE
218
+		));
219 219
 	}
220 220
 
221 221
 	/**
@@ -226,38 +226,38 @@  discard block
 block discarded – undo
226 226
 	 *
227 227
 	 * @return ConstraintParameterException[]
228 228
 	 */
229
-	private function checkCommonConstraintParameters( Constraint $constraint ): array {
229
+	private function checkCommonConstraintParameters(Constraint $constraint): array {
230 230
 		$constraintParameters = $constraint->getConstraintParameters();
231 231
 		try {
232
-			$this->constraintParameterParser->checkError( $constraintParameters );
233
-		} catch ( ConstraintParameterException $e ) {
234
-			return [ $e ];
232
+			$this->constraintParameterParser->checkError($constraintParameters);
233
+		} catch (ConstraintParameterException $e) {
234
+			return [$e];
235 235
 		}
236 236
 
237 237
 		$problems = [];
238 238
 		try {
239
-			$this->constraintParameterParser->parseExceptionParameter( $constraintParameters );
240
-		} catch ( ConstraintParameterException $e ) {
239
+			$this->constraintParameterParser->parseExceptionParameter($constraintParameters);
240
+		} catch (ConstraintParameterException $e) {
241 241
 			$problems[] = $e;
242 242
 		}
243 243
 		try {
244
-			$this->constraintParameterParser->parseConstraintClarificationParameter( $constraintParameters );
245
-		} catch ( ConstraintParameterException $e ) {
244
+			$this->constraintParameterParser->parseConstraintClarificationParameter($constraintParameters);
245
+		} catch (ConstraintParameterException $e) {
246 246
 			$problems[] = $e;
247 247
 		}
248 248
 		try {
249
-			$this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters );
250
-		} catch ( ConstraintParameterException $e ) {
249
+			$this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters);
250
+		} catch (ConstraintParameterException $e) {
251 251
 			$problems[] = $e;
252 252
 		}
253 253
 		try {
254 254
 			$this->constraintParameterParser->parseConstraintScopeParameters(
255 255
 				$constraintParameters,
256 256
 				$constraint->getConstraintTypeItemId(),
257
-				$this->getValidContextTypes( $constraint ),
258
-				$this->getValidEntityTypes( $constraint )
257
+				$this->getValidContextTypes($constraint),
258
+				$this->getValidEntityTypes($constraint)
259 259
 			);
260
-		} catch ( ConstraintParameterException $e ) {
260
+		} catch (ConstraintParameterException $e) {
261 261
 			$problems[] = $e;
262 262
 		}
263 263
 		return $problems;
@@ -270,16 +270,16 @@  discard block
 block discarded – undo
270 270
 	 * @return ConstraintParameterException[][] first level indexed by constraint ID,
271 271
 	 * second level like checkConstraintParametersOnConstraintId (but without possibility of null)
272 272
 	 */
273
-	public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ): array {
274
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
273
+	public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId): array {
274
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
275 275
 		$result = [];
276 276
 
277
-		foreach ( $constraints as $constraint ) {
278
-			$problems = $this->checkCommonConstraintParameters( $constraint );
277
+		foreach ($constraints as $constraint) {
278
+			$problems = $this->checkCommonConstraintParameters($constraint);
279 279
 
280
-			if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
280
+			if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
281 281
 				$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
282
-				$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
282
+				$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
283 283
 			}
284 284
 
285 285
 			$result[$constraint->getConstraintId()] = $problems;
@@ -296,18 +296,18 @@  discard block
 block discarded – undo
296 296
 	 * @return ConstraintParameterException[]|null list of constraint parameter exceptions
297 297
 	 * (empty means all parameters okay), or null if constraint is not found
298 298
 	 */
299
-	public function checkConstraintParametersOnConstraintId( string $constraintId ): ?array {
300
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
299
+	public function checkConstraintParametersOnConstraintId(string $constraintId): ?array {
300
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
301 301
 		'@phan-var NumericPropertyId $propertyId';
302
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
302
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
303 303
 
304
-		foreach ( $constraints as $constraint ) {
305
-			if ( $constraint->getConstraintId() === $constraintId ) {
306
-				$problems = $this->checkCommonConstraintParameters( $constraint );
304
+		foreach ($constraints as $constraint) {
305
+			if ($constraint->getConstraintId() === $constraintId) {
306
+				$problems = $this->checkCommonConstraintParameters($constraint);
307 307
 
308
-				if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
308
+				if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
309 309
 					$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
310
-					$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
310
+					$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
311 311
 				}
312 312
 
313 313
 				return $problems;
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
 		$result = [];
333 333
 
334 334
 		/** @var Statement $statement */
335
-		foreach ( $entity->getStatements() as $statement ) {
336
-			$result = array_merge( $result,
335
+		foreach ($entity->getStatements() as $statement) {
336
+			$result = array_merge($result,
337 337
 				$this->checkStatement(
338 338
 					$entity,
339 339
 					$statement,
340 340
 					$constraintIds,
341 341
 					$defaultResultsPerContext
342
-				) );
342
+				));
343 343
 		}
344 344
 
345 345
 		return $result;
@@ -361,32 +361,32 @@  discard block
 block discarded – undo
361 361
 	): array {
362 362
 		$result = [];
363 363
 
364
-		$result = array_merge( $result,
364
+		$result = array_merge($result,
365 365
 			$this->checkConstraintsForMainSnak(
366 366
 				$entity,
367 367
 				$statement,
368 368
 				$constraintIds,
369 369
 				$defaultResultsPerContext
370
-			) );
370
+			));
371 371
 
372
-		if ( $this->checkQualifiers ) {
373
-			$result = array_merge( $result,
372
+		if ($this->checkQualifiers) {
373
+			$result = array_merge($result,
374 374
 				$this->checkConstraintsForQualifiers(
375 375
 					$entity,
376 376
 					$statement,
377 377
 					$constraintIds,
378 378
 					$defaultResultsPerContext
379
-				) );
379
+				));
380 380
 		}
381 381
 
382
-		if ( $this->checkReferences ) {
383
-			$result = array_merge( $result,
382
+		if ($this->checkReferences) {
383
+			$result = array_merge($result,
384 384
 				$this->checkConstraintsForReferences(
385 385
 					$entity,
386 386
 					$statement,
387 387
 					$constraintIds,
388 388
 					$defaultResultsPerContext
389
-				) );
389
+				));
390 390
 		}
391 391
 
392 392
 		return $result;
@@ -401,17 +401,17 @@  discard block
 block discarded – undo
401 401
 	 * @param string[]|null $constraintIds
402 402
 	 * @return Constraint[]
403 403
 	 */
404
-	private function getConstraintsToUse( PropertyId $propertyId, ?array $constraintIds ): array {
405
-		if ( !( $propertyId instanceof NumericPropertyId ) ) {
404
+	private function getConstraintsToUse(PropertyId $propertyId, ?array $constraintIds): array {
405
+		if (!($propertyId instanceof NumericPropertyId)) {
406 406
 			throw new InvalidArgumentException(
407
-				'Non-numeric property ID not supported:' . $propertyId->getSerialization()
407
+				'Non-numeric property ID not supported:'.$propertyId->getSerialization()
408 408
 			);
409 409
 		}
410
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
411
-		if ( $constraintIds !== null ) {
410
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
411
+		if ($constraintIds !== null) {
412 412
 			$constraintsToUse = [];
413
-			foreach ( $constraints as $constraint ) {
414
-				if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) {
413
+			foreach ($constraints as $constraint) {
414
+				if (in_array($constraint->getConstraintId(), $constraintIds)) {
415 415
 					$constraintsToUse[] = $constraint;
416 416
 				}
417 417
 			}
@@ -435,18 +435,18 @@  discard block
 block discarded – undo
435 435
 		?array $constraintIds,
436 436
 		?callable $defaultResults
437 437
 	): array {
438
-		$context = new MainSnakContext( $entity, $statement );
438
+		$context = new MainSnakContext($entity, $statement);
439 439
 		$constraints = $this->getConstraintsToUse(
440 440
 			$statement->getPropertyId(),
441 441
 			$constraintIds
442 442
 		);
443
-		$result = $defaultResults !== null ? $defaultResults( $context ) : [];
443
+		$result = $defaultResults !== null ? $defaultResults($context) : [];
444 444
 
445
-		foreach ( $constraints as $constraint ) {
445
+		foreach ($constraints as $constraint) {
446 446
 			$parameters = $constraint->getConstraintParameters();
447 447
 			try {
448
-				$exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters );
449
-			} catch ( ConstraintParameterException $e ) {
448
+				$exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters);
449
+			} catch (ConstraintParameterException $e) {
450 450
 				$result[] = new CheckResult(
451 451
 					$context,
452 452
 					$constraint,
@@ -456,13 +456,13 @@  discard block
 block discarded – undo
456 456
 				continue;
457 457
 			}
458 458
 
459
-			if ( in_array( $entity->getId(), $exceptions ) ) {
460
-				$message = new ViolationMessage( 'wbqc-violation-message-exception' );
461
-				$result[] = new CheckResult( $context, $constraint, CheckResult::STATUS_EXCEPTION, $message );
459
+			if (in_array($entity->getId(), $exceptions)) {
460
+				$message = new ViolationMessage('wbqc-violation-message-exception');
461
+				$result[] = new CheckResult($context, $constraint, CheckResult::STATUS_EXCEPTION, $message);
462 462
 				continue;
463 463
 			}
464 464
 
465
-			$result[] = $this->getCheckResultFor( $context, $constraint );
465
+			$result[] = $this->getCheckResultFor($context, $constraint);
466 466
 		}
467 467
 
468 468
 		return $result;
@@ -484,24 +484,24 @@  discard block
 block discarded – undo
484 484
 	): array {
485 485
 		$result = [];
486 486
 
487
-		if ( in_array(
487
+		if (in_array(
488 488
 			$statement->getPropertyId()->getSerialization(),
489 489
 			$this->propertiesWithViolatingQualifiers
490
-		) ) {
490
+		)) {
491 491
 			return $result;
492 492
 		}
493 493
 
494
-		foreach ( $statement->getQualifiers() as $qualifier ) {
495
-			$qualifierContext = new QualifierContext( $entity, $statement, $qualifier );
496
-			if ( $defaultResultsPerContext !== null ) {
497
-				$result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) );
494
+		foreach ($statement->getQualifiers() as $qualifier) {
495
+			$qualifierContext = new QualifierContext($entity, $statement, $qualifier);
496
+			if ($defaultResultsPerContext !== null) {
497
+				$result = array_merge($result, $defaultResultsPerContext($qualifierContext));
498 498
 			}
499 499
 			$qualifierConstraints = $this->getConstraintsToUse(
500 500
 				$qualifierContext->getSnak()->getPropertyId(),
501 501
 				$constraintIds
502 502
 			);
503
-			foreach ( $qualifierConstraints as $qualifierConstraint ) {
504
-				$result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint );
503
+			foreach ($qualifierConstraints as $qualifierConstraint) {
504
+				$result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint);
505 505
 			}
506 506
 		}
507 507
 
@@ -525,19 +525,19 @@  discard block
 block discarded – undo
525 525
 		$result = [];
526 526
 
527 527
 		/** @var Reference $reference */
528
-		foreach ( $statement->getReferences() as $reference ) {
529
-			foreach ( $reference->getSnaks() as $snak ) {
528
+		foreach ($statement->getReferences() as $reference) {
529
+			foreach ($reference->getSnaks() as $snak) {
530 530
 				$referenceContext = new ReferenceContext(
531 531
 					$entity, $statement, $reference, $snak
532 532
 				);
533
-				if ( $defaultResultsPerContext !== null ) {
534
-					$result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) );
533
+				if ($defaultResultsPerContext !== null) {
534
+					$result = array_merge($result, $defaultResultsPerContext($referenceContext));
535 535
 				}
536 536
 				$referenceConstraints = $this->getConstraintsToUse(
537 537
 					$referenceContext->getSnak()->getPropertyId(),
538 538
 					$constraintIds
539 539
 				);
540
-				foreach ( $referenceConstraints as $referenceConstraint ) {
540
+				foreach ($referenceConstraints as $referenceConstraint) {
541 541
 					$result[] = $this->getCheckResultFor(
542 542
 						$referenceContext,
543 543
 						$referenceConstraint
@@ -549,50 +549,50 @@  discard block
 block discarded – undo
549 549
 		return $result;
550 550
 	}
551 551
 
552
-	private function getCheckResultFor( Context $context, Constraint $constraint ): CheckResult {
553
-		if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
552
+	private function getCheckResultFor(Context $context, Constraint $constraint): CheckResult {
553
+		if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
554 554
 			$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
555
-			$result = $this->handleScope( $checker, $context, $constraint );
555
+			$result = $this->handleScope($checker, $context, $constraint);
556 556
 
557
-			if ( $result !== null ) {
558
-				$this->addMetadata( $context, $result );
557
+			if ($result !== null) {
558
+				$this->addMetadata($context, $result);
559 559
 				return $result;
560 560
 			}
561 561
 
562
-			$startTime = microtime( true );
562
+			$startTime = microtime(true);
563 563
 			try {
564
-				$result = $checker->checkConstraint( $context, $constraint );
565
-			} catch ( ConstraintParameterException $e ) {
564
+				$result = $checker->checkConstraint($context, $constraint);
565
+			} catch (ConstraintParameterException $e) {
566 566
 				$result = new CheckResult(
567 567
 					$context,
568 568
 					$constraint,
569 569
 					CheckResult::STATUS_BAD_PARAMETERS,
570 570
 					$e->getViolationMessage()
571 571
 				);
572
-			} catch ( SparqlHelperException $e ) {
573
-				$message = new ViolationMessage( 'wbqc-violation-message-sparql-error' );
574
-				$result = new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, $message );
572
+			} catch (SparqlHelperException $e) {
573
+				$message = new ViolationMessage('wbqc-violation-message-sparql-error');
574
+				$result = new CheckResult($context, $constraint, CheckResult::STATUS_TODO, $message);
575 575
 			}
576
-			$endTime = microtime( true );
576
+			$endTime = microtime(true);
577 577
 
578
-			$this->addMetadata( $context, $result );
578
+			$this->addMetadata($context, $result);
579 579
 
580
-			$this->addConstraintClarification( $result );
580
+			$this->addConstraintClarification($result);
581 581
 
582
-			$this->downgradeResultStatus( $result );
582
+			$this->downgradeResultStatus($result);
583 583
 
584 584
 			$this->loggingHelper->logConstraintCheck(
585 585
 				$context,
586 586
 				$constraint,
587 587
 				$result,
588
-				get_class( $checker ),
588
+				get_class($checker),
589 589
 				$endTime - $startTime,
590 590
 				__METHOD__
591 591
 			);
592 592
 
593 593
 			return $result;
594 594
 		} else {
595
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null );
595
+			return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null);
596 596
 		}
597 597
 	}
598 598
 
@@ -601,87 +601,87 @@  discard block
 block discarded – undo
601 601
 		Context $context,
602 602
 		Constraint $constraint
603 603
 	): ?CheckResult {
604
-		$validContextTypes = $this->getValidContextTypes( $constraint );
605
-		$validEntityTypes = $this->getValidEntityTypes( $constraint );
604
+		$validContextTypes = $this->getValidContextTypes($constraint);
605
+		$validEntityTypes = $this->getValidEntityTypes($constraint);
606 606
 		try {
607
-			[ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters(
607
+			[$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters(
608 608
 				$constraint->getConstraintParameters(),
609 609
 				$constraint->getConstraintTypeItemId(),
610 610
 				$validContextTypes,
611 611
 				$validEntityTypes
612 612
 			);
613
-		} catch ( ConstraintParameterException $e ) {
614
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
613
+		} catch (ConstraintParameterException $e) {
614
+			return new CheckResult($context, $constraint, CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
615 615
 		}
616 616
 
617 617
 		$checkedContextTypes ??= $checker->getDefaultContextTypes();
618 618
 		$contextType = $context->getType();
619
-		if ( !in_array( $contextType, $checkedContextTypes ) ) {
620
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null );
619
+		if (!in_array($contextType, $checkedContextTypes)) {
620
+			return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null);
621 621
 		}
622
-		if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) {
623
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null );
622
+		if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) {
623
+			return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null);
624 624
 		}
625 625
 
626 626
 		$checkedEntityTypes ??= $validEntityTypes;
627 627
 		$entityType = $context->getEntity()->getType();
628
-		if ( !in_array( $entityType, $checkedEntityTypes ) ) {
629
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null );
628
+		if (!in_array($entityType, $checkedEntityTypes)) {
629
+			return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null);
630 630
 		}
631
-		if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) {
632
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null );
631
+		if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) {
632
+			return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null);
633 633
 		}
634 634
 
635 635
 		return null;
636 636
 	}
637 637
 
638
-	private function addMetadata( Context $context, CheckResult $result ): void {
639
-		$result->withMetadata( Metadata::merge( [
638
+	private function addMetadata(Context $context, CheckResult $result): void {
639
+		$result->withMetadata(Metadata::merge([
640 640
 			$result->getMetadata(),
641
-			Metadata::ofDependencyMetadata( DependencyMetadata::merge( [
642
-				DependencyMetadata::ofEntityId( $context->getEntity()->getId() ),
643
-				DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ),
644
-			] ) ),
645
-		] ) );
641
+			Metadata::ofDependencyMetadata(DependencyMetadata::merge([
642
+				DependencyMetadata::ofEntityId($context->getEntity()->getId()),
643
+				DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()),
644
+			])),
645
+		]));
646 646
 	}
647 647
 
648
-	private function addConstraintClarification( CheckResult $result ): void {
648
+	private function addConstraintClarification(CheckResult $result): void {
649 649
 		$constraint = $result->getConstraint();
650 650
 		try {
651 651
 			$constraintClarification = $this->constraintParameterParser
652
-				->parseConstraintClarificationParameter( $constraint->getConstraintParameters() );
653
-			$result->setConstraintClarification( $constraintClarification );
654
-		} catch ( ConstraintParameterException $e ) {
655
-			$result->setStatus( CheckResult::STATUS_BAD_PARAMETERS );
656
-			$result->setMessage( $e->getViolationMessage() );
652
+				->parseConstraintClarificationParameter($constraint->getConstraintParameters());
653
+			$result->setConstraintClarification($constraintClarification);
654
+		} catch (ConstraintParameterException $e) {
655
+			$result->setStatus(CheckResult::STATUS_BAD_PARAMETERS);
656
+			$result->setMessage($e->getViolationMessage());
657 657
 		}
658 658
 	}
659 659
 
660
-	private function downgradeResultStatus( CheckResult $result ): void {
660
+	private function downgradeResultStatus(CheckResult $result): void {
661 661
 		$constraint = $result->getConstraint();
662 662
 		try {
663 663
 			$constraintStatus = $this->constraintParameterParser
664
-				->parseConstraintStatusParameter( $constraint->getConstraintParameters() );
665
-		} catch ( ConstraintParameterException $e ) {
666
-			$result->setStatus( CheckResult::STATUS_BAD_PARAMETERS );
667
-			$result->setMessage( $e->getViolationMessage() );
664
+				->parseConstraintStatusParameter($constraint->getConstraintParameters());
665
+		} catch (ConstraintParameterException $e) {
666
+			$result->setStatus(CheckResult::STATUS_BAD_PARAMETERS);
667
+			$result->setMessage($e->getViolationMessage());
668 668
 			return;
669 669
 		}
670
-		if ( $constraintStatus === null ) {
670
+		if ($constraintStatus === null) {
671 671
 			// downgrade violation to warning
672
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
673
-				$result->setStatus( CheckResult::STATUS_WARNING );
672
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
673
+				$result->setStatus(CheckResult::STATUS_WARNING);
674 674
 			}
675
-		} elseif ( $constraintStatus === 'suggestion' ) {
675
+		} elseif ($constraintStatus === 'suggestion') {
676 676
 			// downgrade violation to suggestion
677
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
678
-				$result->setStatus( CheckResult::STATUS_SUGGESTION );
677
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
678
+				$result->setStatus(CheckResult::STATUS_SUGGESTION);
679 679
 			}
680 680
 		} else {
681
-			if ( $constraintStatus !== 'mandatory' ) {
681
+			if ($constraintStatus !== 'mandatory') {
682 682
 				// @codeCoverageIgnoreStart
683 683
 				throw new LogicException(
684
-					"Unknown constraint status '$constraintStatus', " .
684
+					"Unknown constraint status '$constraintStatus', ".
685 685
 					"only known statuses are 'mandatory' and 'suggestion'"
686 686
 				);
687 687
 				// @codeCoverageIgnoreEnd
@@ -694,12 +694,12 @@  discard block
 block discarded – undo
694 694
 	 *
695 695
 	 * @return CheckResult[]
696 696
 	 */
697
-	private function sortResult( array $result ): array {
698
-		if ( count( $result ) < 2 ) {
697
+	private function sortResult(array $result): array {
698
+		if (count($result) < 2) {
699 699
 			return $result;
700 700
 		}
701 701
 
702
-		$sortFunction = static function ( CheckResult $a, CheckResult $b ) {
702
+		$sortFunction = static function(CheckResult $a, CheckResult $b) {
703 703
 			$orderNum = 0;
704 704
 			$order = [
705 705
 				CheckResult::STATUS_BAD_PARAMETERS => $orderNum++,
@@ -716,55 +716,55 @@  discard block
 block discarded – undo
716 716
 			$statusA = $a->getStatus();
717 717
 			$statusB = $b->getStatus();
718 718
 
719
-			$orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ];
720
-			$orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ];
719
+			$orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other'];
720
+			$orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other'];
721 721
 
722
-			if ( $orderA === $orderB ) {
722
+			if ($orderA === $orderB) {
723 723
 				$cursorA = $a->getContextCursor();
724 724
 				$cursorB = $b->getContextCursor();
725 725
 
726
-				if ( $cursorA instanceof EntityContextCursor ) {
726
+				if ($cursorA instanceof EntityContextCursor) {
727 727
 					return $cursorB instanceof EntityContextCursor ? 0 : -1;
728 728
 				}
729
-				if ( $cursorB instanceof EntityContextCursor ) {
729
+				if ($cursorB instanceof EntityContextCursor) {
730 730
 					return $cursorA instanceof EntityContextCursor ? 0 : 1;
731 731
 				}
732 732
 
733 733
 				$pidA = $cursorA->getSnakPropertyId();
734 734
 				$pidB = $cursorB->getSnakPropertyId();
735 735
 
736
-				if ( $pidA === $pidB ) {
736
+				if ($pidA === $pidB) {
737 737
 					$hashA = $cursorA->getSnakHash();
738 738
 					$hashB = $cursorB->getSnakHash();
739 739
 
740
-					if ( $hashA === $hashB ) {
741
-						if ( $a instanceof NullResult ) {
740
+					if ($hashA === $hashB) {
741
+						if ($a instanceof NullResult) {
742 742
 							return $b instanceof NullResult ? 0 : -1;
743 743
 						}
744
-						if ( $b instanceof NullResult ) {
744
+						if ($b instanceof NullResult) {
745 745
 							return $a instanceof NullResult ? 0 : 1;
746 746
 						}
747 747
 
748 748
 						$typeA = $a->getConstraint()->getConstraintTypeItemId();
749 749
 						$typeB = $b->getConstraint()->getConstraintTypeItemId();
750 750
 
751
-						if ( $typeA == $typeB ) {
751
+						if ($typeA == $typeB) {
752 752
 							return 0;
753 753
 						} else {
754
-							return ( $typeA > $typeB ) ? 1 : -1;
754
+							return ($typeA > $typeB) ? 1 : -1;
755 755
 						}
756 756
 					} else {
757
-						return ( $hashA > $hashB ) ? 1 : -1;
757
+						return ($hashA > $hashB) ? 1 : -1;
758 758
 					}
759 759
 				} else {
760
-					return ( $pidA > $pidB ) ? 1 : -1;
760
+					return ($pidA > $pidB) ? 1 : -1;
761 761
 				}
762 762
 			} else {
763
-				return ( $orderA > $orderB ) ? 1 : -1;
763
+				return ($orderA > $orderB) ? 1 : -1;
764 764
 			}
765 765
 		};
766 766
 
767
-		uasort( $result, $sortFunction );
767
+		uasort($result, $sortFunction);
768 768
 
769 769
 		return $result;
770 770
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/ConstraintParameterParser.php 1 patch
Spacing   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper;
6 6
 
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 	 * Check if any errors are recorded in the constraint parameters.
69 69
 	 * @throws ConstraintParameterException
70 70
 	 */
71
-	public function checkError( array $parameters ): void {
72
-		if ( array_key_exists( '@error', $parameters ) ) {
71
+	public function checkError(array $parameters): void {
72
+		if (array_key_exists('@error', $parameters)) {
73 73
 			$error = $parameters['@error'];
74
-			if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) {
74
+			if (array_key_exists('toolong', $error) && $error['toolong']) {
75 75
 				$msg = 'wbqc-violation-message-parameters-error-toolong';
76 76
 			} else {
77 77
 				$msg = 'wbqc-violation-message-parameters-error-unknown';
78 78
 			}
79
-			throw new ConstraintParameterException( new ViolationMessage( $msg ) );
79
+			throw new ConstraintParameterException(new ViolationMessage($msg));
80 80
 		}
81 81
 	}
82 82
 
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
 	 * Require that $parameters contains exactly one $parameterId parameter.
85 85
 	 * @throws ConstraintParameterException
86 86
 	 */
87
-	private function requireSingleParameter( array $parameters, string $parameterId ): void {
88
-		if ( count( $parameters[$parameterId] ) !== 1 ) {
87
+	private function requireSingleParameter(array $parameters, string $parameterId): void {
88
+		if (count($parameters[$parameterId]) !== 1) {
89 89
 			throw new ConstraintParameterException(
90
-				( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) )
91
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
90
+				(new ViolationMessage('wbqc-violation-message-parameter-single'))
91
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
92 92
 			);
93 93
 		}
94 94
 	}
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * Require that $snak is a {@link PropertyValueSnak}.
98 98
 	 * @throws ConstraintParameterException
99 99
 	 */
100
-	private function requireValueParameter( Snak $snak, string $parameterId ): void {
101
-		if ( !( $snak instanceof PropertyValueSnak ) ) {
100
+	private function requireValueParameter(Snak $snak, string $parameterId): void {
101
+		if (!($snak instanceof PropertyValueSnak)) {
102 102
 			throw new ConstraintParameterException(
103
-				( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) )
104
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
103
+				(new ViolationMessage('wbqc-violation-message-parameter-value'))
104
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
105 105
 			);
106 106
 		}
107 107
 	}
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
 	 * Parse a single entity ID parameter.
111 111
 	 * @throws ConstraintParameterException
112 112
 	 */
113
-	private function parseEntityIdParameter( array $snakSerialization, string $parameterId ): EntityId {
114
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
115
-		$this->requireValueParameter( $snak, $parameterId );
113
+	private function parseEntityIdParameter(array $snakSerialization, string $parameterId): EntityId {
114
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
115
+		$this->requireValueParameter($snak, $parameterId);
116 116
 		$value = $snak->getDataValue();
117
-		if ( $value instanceof EntityIdValue ) {
117
+		if ($value instanceof EntityIdValue) {
118 118
 			return $value->getEntityId();
119 119
 		} else {
120 120
 			throw new ConstraintParameterException(
121
-				( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) )
122
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
123
-					->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
121
+				(new ViolationMessage('wbqc-violation-message-parameter-entity'))
122
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
123
+					->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
124 124
 			);
125 125
 		}
126 126
 	}
@@ -131,20 +131,20 @@  discard block
 block discarded – undo
131 131
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
132 132
 	 * @return string[] class entity ID serializations
133 133
 	 */
134
-	public function parseClassParameter( array $constraintParameters, string $constraintTypeItemId ): array {
135
-		$this->checkError( $constraintParameters );
136
-		$classId = $this->config->get( 'WBQualityConstraintsClassId' );
137
-		if ( !array_key_exists( $classId, $constraintParameters ) ) {
134
+	public function parseClassParameter(array $constraintParameters, string $constraintTypeItemId): array {
135
+		$this->checkError($constraintParameters);
136
+		$classId = $this->config->get('WBQualityConstraintsClassId');
137
+		if (!array_key_exists($classId, $constraintParameters)) {
138 138
 			throw new ConstraintParameterException(
139
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
140
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
141
-					->withEntityId( new NumericPropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
139
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
140
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
141
+					->withEntityId(new NumericPropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY)
142 142
 			);
143 143
 		}
144 144
 
145 145
 		$classes = [];
146
-		foreach ( $constraintParameters[$classId] as $class ) {
147
-			$classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization();
146
+		foreach ($constraintParameters[$classId] as $class) {
147
+			$classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization();
148 148
 		}
149 149
 		return $classes;
150 150
 	}
@@ -155,31 +155,31 @@  discard block
 block discarded – undo
155 155
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
156 156
 	 * @return string 'instance', 'subclass', or 'instanceOrSubclass'
157 157
 	 */
158
-	public function parseRelationParameter( array $constraintParameters, string $constraintTypeItemId ): string {
159
-		$this->checkError( $constraintParameters );
160
-		$relationId = $this->config->get( 'WBQualityConstraintsRelationId' );
161
-		if ( !array_key_exists( $relationId, $constraintParameters ) ) {
158
+	public function parseRelationParameter(array $constraintParameters, string $constraintTypeItemId): string {
159
+		$this->checkError($constraintParameters);
160
+		$relationId = $this->config->get('WBQualityConstraintsRelationId');
161
+		if (!array_key_exists($relationId, $constraintParameters)) {
162 162
 			throw new ConstraintParameterException(
163
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
164
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
165
-					->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
163
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
164
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
165
+					->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY)
166 166
 			);
167 167
 		}
168 168
 
169
-		$this->requireSingleParameter( $constraintParameters, $relationId );
170
-		$relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId );
171
-		if ( !( $relationEntityId instanceof ItemId ) ) {
169
+		$this->requireSingleParameter($constraintParameters, $relationId);
170
+		$relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId);
171
+		if (!($relationEntityId instanceof ItemId)) {
172 172
 			throw new ConstraintParameterException(
173
-				( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) )
174
-					->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
175
-					->withDataValue( new EntityIdValue( $relationEntityId ), Role::CONSTRAINT_PARAMETER_VALUE )
173
+				(new ViolationMessage('wbqc-violation-message-parameter-item'))
174
+					->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY)
175
+					->withDataValue(new EntityIdValue($relationEntityId), Role::CONSTRAINT_PARAMETER_VALUE)
176 176
 			);
177 177
 		}
178
-		return $this->mapItemId( $relationEntityId, [
179
-			$this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ) => 'instance',
180
-			$this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ) => 'subclass',
181
-			$this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ) => 'instanceOrSubclass',
182
-		], $relationId );
178
+		return $this->mapItemId($relationEntityId, [
179
+			$this->config->get('WBQualityConstraintsInstanceOfRelationId') => 'instance',
180
+			$this->config->get('WBQualityConstraintsSubclassOfRelationId') => 'subclass',
181
+			$this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId') => 'instanceOrSubclass',
182
+		], $relationId);
183 183
 	}
184 184
 
185 185
 	/**
@@ -189,20 +189,20 @@  discard block
 block discarded – undo
189 189
 	 * @throws ConstraintParameterException
190 190
 	 * @return PropertyId
191 191
 	 */
192
-	private function parsePropertyIdParameter( array $snakSerialization, string $parameterId ): PropertyId {
193
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
194
-		$this->requireValueParameter( $snak, $parameterId );
192
+	private function parsePropertyIdParameter(array $snakSerialization, string $parameterId): PropertyId {
193
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
194
+		$this->requireValueParameter($snak, $parameterId);
195 195
 		$value = $snak->getDataValue();
196
-		if ( $value instanceof EntityIdValue ) {
196
+		if ($value instanceof EntityIdValue) {
197 197
 			$id = $value->getEntityId();
198
-			if ( $id instanceof PropertyId ) {
198
+			if ($id instanceof PropertyId) {
199 199
 				return $id;
200 200
 			}
201 201
 		}
202 202
 		throw new ConstraintParameterException(
203
-			( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) )
204
-				->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
205
-				->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
203
+			(new ViolationMessage('wbqc-violation-message-parameter-property'))
204
+				->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
205
+				->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
206 206
 		);
207 207
 	}
208 208
 
@@ -213,33 +213,33 @@  discard block
 block discarded – undo
213 213
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
214 214
 	 * @return PropertyId
215 215
 	 */
216
-	public function parsePropertyParameter( array $constraintParameters, string $constraintTypeItemId ): PropertyId {
217
-		$this->checkError( $constraintParameters );
218
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
219
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
216
+	public function parsePropertyParameter(array $constraintParameters, string $constraintTypeItemId): PropertyId {
217
+		$this->checkError($constraintParameters);
218
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
219
+		if (!array_key_exists($propertyId, $constraintParameters)) {
220 220
 			throw new ConstraintParameterException(
221
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
222
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
223
-					->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
221
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
222
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
223
+					->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
224 224
 			);
225 225
 		}
226 226
 
227
-		$this->requireSingleParameter( $constraintParameters, $propertyId );
228
-		return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId );
227
+		$this->requireSingleParameter($constraintParameters, $propertyId);
228
+		return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId);
229 229
 	}
230 230
 
231
-	private function parseItemIdParameter( PropertyValueSnak $snak, string $parameterId ): ItemIdSnakValue {
231
+	private function parseItemIdParameter(PropertyValueSnak $snak, string $parameterId): ItemIdSnakValue {
232 232
 		$dataValue = $snak->getDataValue();
233
-		if ( $dataValue instanceof EntityIdValue ) {
233
+		if ($dataValue instanceof EntityIdValue) {
234 234
 			$entityId = $dataValue->getEntityId();
235
-			if ( $entityId instanceof ItemId ) {
236
-				return ItemIdSnakValue::fromItemId( $entityId );
235
+			if ($entityId instanceof ItemId) {
236
+				return ItemIdSnakValue::fromItemId($entityId);
237 237
 			}
238 238
 		}
239 239
 		throw new ConstraintParameterException(
240
-			( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) )
241
-				->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
242
-				->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
240
+			(new ViolationMessage('wbqc-violation-message-parameter-item'))
241
+				->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
242
+				->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
243 243
 		);
244 244
 	}
245 245
 
@@ -257,14 +257,14 @@  discard block
 block discarded – undo
257 257
 		bool $required,
258 258
 		string $parameterId = null
259 259
 	): array {
260
-		$this->checkError( $constraintParameters );
261
-		$parameterId ??= $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
262
-		if ( !array_key_exists( $parameterId, $constraintParameters ) ) {
263
-			if ( $required ) {
260
+		$this->checkError($constraintParameters);
261
+		$parameterId ??= $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
262
+		if (!array_key_exists($parameterId, $constraintParameters)) {
263
+			if ($required) {
264 264
 				throw new ConstraintParameterException(
265
-					( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
266
-						->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
267
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
265
+					(new ViolationMessage('wbqc-violation-message-parameter-needed'))
266
+						->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
267
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
268 268
 				);
269 269
 			} else {
270 270
 				return [];
@@ -272,11 +272,11 @@  discard block
 block discarded – undo
272 272
 		}
273 273
 
274 274
 		$values = [];
275
-		foreach ( $constraintParameters[$parameterId] as $parameter ) {
276
-			$snak = $this->snakDeserializer->deserialize( $parameter );
277
-			switch ( true ) {
275
+		foreach ($constraintParameters[$parameterId] as $parameter) {
276
+			$snak = $this->snakDeserializer->deserialize($parameter);
277
+			switch (true) {
278 278
 				case $snak instanceof PropertyValueSnak:
279
-					$values[] = $this->parseItemIdParameter( $snak, $parameterId );
279
+					$values[] = $this->parseItemIdParameter($snak, $parameterId);
280 280
 					break;
281 281
 				case $snak instanceof PropertySomeValueSnak:
282 282
 					$values[] = ItemIdSnakValue::someValue();
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
 		bool $required,
305 305
 		string $parameterId
306 306
 	): array {
307
-		return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId {
308
-			if ( $value->isValue() ) {
307
+		return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId {
308
+			if ($value->isValue()) {
309 309
 				return $value->getItemId();
310 310
 			} else {
311 311
 				throw new ConstraintParameterException(
312
-					( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) )
313
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
312
+					(new ViolationMessage('wbqc-violation-message-parameter-value'))
313
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
314 314
 				);
315 315
 			}
316 316
 		}, $this->parseItemsParameter(
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 			$constraintTypeItemId,
319 319
 			$required,
320 320
 			$parameterId
321
-		) );
321
+		));
322 322
 	}
323 323
 
324 324
 	/**
@@ -326,18 +326,18 @@  discard block
 block discarded – undo
326 326
 	 * @throws ConstraintParameterException
327 327
 	 * @return mixed elements of $mapping
328 328
 	 */
329
-	private function mapItemId( ItemId $itemId, array $mapping, string $parameterId ) {
329
+	private function mapItemId(ItemId $itemId, array $mapping, string $parameterId) {
330 330
 		$serialization = $itemId->getSerialization();
331
-		if ( array_key_exists( $serialization, $mapping ) ) {
331
+		if (array_key_exists($serialization, $mapping)) {
332 332
 			return $mapping[$serialization];
333 333
 		} else {
334
-			$allowed = array_map( static function ( $id ) {
335
-				return new ItemId( $id );
336
-			}, array_keys( $mapping ) );
334
+			$allowed = array_map(static function($id) {
335
+				return new ItemId($id);
336
+			}, array_keys($mapping));
337 337
 			throw new ConstraintParameterException(
338
-				( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
339
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
340
-					->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE )
338
+				(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
339
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
340
+					->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE)
341 341
 			);
342 342
 		}
343 343
 	}
@@ -348,27 +348,27 @@  discard block
 block discarded – undo
348 348
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
349 349
 	 * @return PropertyId[]
350 350
 	 */
351
-	public function parsePropertiesParameter( array $constraintParameters, string $constraintTypeItemId ): array {
352
-		$this->checkError( $constraintParameters );
353
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
354
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
351
+	public function parsePropertiesParameter(array $constraintParameters, string $constraintTypeItemId): array {
352
+		$this->checkError($constraintParameters);
353
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
354
+		if (!array_key_exists($propertyId, $constraintParameters)) {
355 355
 			throw new ConstraintParameterException(
356
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
357
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
358
-					->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
356
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
357
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
358
+					->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
359 359
 			);
360 360
 		}
361 361
 
362 362
 		$parameters = $constraintParameters[$propertyId];
363
-		if ( count( $parameters ) === 1 &&
364
-			$this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak
363
+		if (count($parameters) === 1 &&
364
+			$this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak
365 365
 		) {
366 366
 			return [];
367 367
 		}
368 368
 
369 369
 		$properties = [];
370
-		foreach ( $parameters as $parameter ) {
371
-			$properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId );
370
+		foreach ($parameters as $parameter) {
371
+			$properties[] = $this->parsePropertyIdParameter($parameter, $propertyId);
372 372
 		}
373 373
 		return $properties;
374 374
 	}
@@ -376,24 +376,24 @@  discard block
 block discarded – undo
376 376
 	/**
377 377
 	 * @throws ConstraintParameterException
378 378
 	 */
379
-	private function parseValueOrNoValueParameter( array $snakSerialization, string $parameterId ): ?DataValue {
380
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
381
-		if ( $snak instanceof PropertyValueSnak ) {
379
+	private function parseValueOrNoValueParameter(array $snakSerialization, string $parameterId): ?DataValue {
380
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
381
+		if ($snak instanceof PropertyValueSnak) {
382 382
 			return $snak->getDataValue();
383
-		} elseif ( $snak instanceof PropertyNoValueSnak ) {
383
+		} elseif ($snak instanceof PropertyNoValueSnak) {
384 384
 			return null;
385 385
 		} else {
386 386
 			throw new ConstraintParameterException(
387
-				( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) )
388
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
387
+				(new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue'))
388
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
389 389
 			);
390 390
 		}
391 391
 	}
392 392
 
393
-	private function parseValueOrNoValueOrNowParameter( array $snakSerialization, string $parameterId ): ?DataValue {
393
+	private function parseValueOrNoValueOrNowParameter(array $snakSerialization, string $parameterId): ?DataValue {
394 394
 		try {
395
-			return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId );
396
-		} catch ( ConstraintParameterException $e ) {
395
+			return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId);
396
+		} catch (ConstraintParameterException $e) {
397 397
 			// unknown value means “now”
398 398
 			return new NowValue();
399 399
 		}
@@ -402,14 +402,14 @@  discard block
 block discarded – undo
402 402
 	/**
403 403
 	 * Checks whether there is exactly one non-null quantity with the given unit.
404 404
 	 */
405
-	private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, string $unit ): bool {
406
-		if ( !( $min instanceof UnboundedQuantityValue ) ||
407
-			!( $max instanceof UnboundedQuantityValue )
405
+	private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, string $unit): bool {
406
+		if (!($min instanceof UnboundedQuantityValue) ||
407
+			!($max instanceof UnboundedQuantityValue)
408 408
 		) {
409 409
 			return false;
410 410
 		}
411 411
 
412
-		return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit );
412
+		return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit);
413 413
 	}
414 414
 
415 415
 	/**
@@ -429,42 +429,42 @@  discard block
 block discarded – undo
429 429
 		string $constraintTypeItemId,
430 430
 		string $type
431 431
 	): array {
432
-		$this->checkError( $constraintParameters );
433
-		if ( !array_key_exists( $minimumId, $constraintParameters ) ||
434
-			!array_key_exists( $maximumId, $constraintParameters )
432
+		$this->checkError($constraintParameters);
433
+		if (!array_key_exists($minimumId, $constraintParameters) ||
434
+			!array_key_exists($maximumId, $constraintParameters)
435 435
 		) {
436 436
 			throw new ConstraintParameterException(
437
-				( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) )
438
-					->withDataValueType( $type )
439
-					->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
440
-					->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
441
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
437
+				(new ViolationMessage('wbqc-violation-message-range-parameters-needed'))
438
+					->withDataValueType($type)
439
+					->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
440
+					->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
441
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
442 442
 			);
443 443
 		}
444 444
 
445
-		$this->requireSingleParameter( $constraintParameters, $minimumId );
446
-		$this->requireSingleParameter( $constraintParameters, $maximumId );
445
+		$this->requireSingleParameter($constraintParameters, $minimumId);
446
+		$this->requireSingleParameter($constraintParameters, $maximumId);
447 447
 		$parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter';
448
-		$min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId );
449
-		$max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId );
448
+		$min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId);
449
+		$max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId);
450 450
 
451
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
452
-		if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) {
451
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
452
+		if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) {
453 453
 			throw new ConstraintParameterException(
454
-				new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' )
454
+				new ViolationMessage('wbqc-violation-message-range-parameters-one-year')
455 455
 			);
456 456
 		}
457
-		if ( ( $min === null && $max === null ) ||
458
-			( $min !== null && $max !== null && $min->equals( $max ) )
457
+		if (($min === null && $max === null) ||
458
+			($min !== null && $max !== null && $min->equals($max))
459 459
 		) {
460 460
 			throw new ConstraintParameterException(
461
-				( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) )
462
-					->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
463
-					->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
461
+				(new ViolationMessage('wbqc-violation-message-range-parameters-same'))
462
+					->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
463
+					->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY)
464 464
 			);
465 465
 		}
466 466
 
467
-		return [ $min, $max ];
467
+		return [$min, $max];
468 468
 	}
469 469
 
470 470
 	/**
@@ -474,11 +474,11 @@  discard block
 block discarded – undo
474 474
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
475 475
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
476 476
 	 */
477
-	public function parseQuantityRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
477
+	public function parseQuantityRangeParameter(array $constraintParameters, string $constraintTypeItemId): array {
478 478
 		return $this->parseRangeParameter(
479 479
 			$constraintParameters,
480
-			$this->config->get( 'WBQualityConstraintsMinimumQuantityId' ),
481
-			$this->config->get( 'WBQualityConstraintsMaximumQuantityId' ),
480
+			$this->config->get('WBQualityConstraintsMinimumQuantityId'),
481
+			$this->config->get('WBQualityConstraintsMaximumQuantityId'),
482 482
 			$constraintTypeItemId,
483 483
 			'quantity'
484 484
 		);
@@ -491,11 +491,11 @@  discard block
 block discarded – undo
491 491
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
492 492
 	 * @return DataValue[] a pair of two data values, either of which may be null to signify an open range
493 493
 	 */
494
-	public function parseTimeRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
494
+	public function parseTimeRangeParameter(array $constraintParameters, string $constraintTypeItemId): array {
495 495
 		return $this->parseRangeParameter(
496 496
 			$constraintParameters,
497
-			$this->config->get( 'WBQualityConstraintsMinimumDateId' ),
498
-			$this->config->get( 'WBQualityConstraintsMaximumDateId' ),
497
+			$this->config->get('WBQualityConstraintsMinimumDateId'),
498
+			$this->config->get('WBQualityConstraintsMaximumDateId'),
499 499
 			$constraintTypeItemId,
500 500
 			'time'
501 501
 		);
@@ -508,20 +508,20 @@  discard block
 block discarded – undo
508 508
 	 * @throws ConstraintParameterException
509 509
 	 * @return string[]
510 510
 	 */
511
-	public function parseLanguageParameter( array $constraintParameters, string $constraintTypeItemId ): array {
512
-		$this->checkError( $constraintParameters );
513
-		$languagePropertyId = $this->config->get( 'WBQualityConstraintsLanguagePropertyId' );
514
-		if ( !array_key_exists( $languagePropertyId, $constraintParameters ) ) {
511
+	public function parseLanguageParameter(array $constraintParameters, string $constraintTypeItemId): array {
512
+		$this->checkError($constraintParameters);
513
+		$languagePropertyId = $this->config->get('WBQualityConstraintsLanguagePropertyId');
514
+		if (!array_key_exists($languagePropertyId, $constraintParameters)) {
515 515
 			throw new ConstraintParameterException(
516
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
517
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
518
-					->withEntityId( new NumericPropertyId( $languagePropertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
516
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
517
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
518
+					->withEntityId(new NumericPropertyId($languagePropertyId), Role::CONSTRAINT_PARAMETER_PROPERTY)
519 519
 			);
520 520
 		}
521 521
 
522 522
 		$languages = [];
523
-		foreach ( $constraintParameters[$languagePropertyId] as $snak ) {
524
-			$languages[] = $this->parseStringParameter( $snak, $languagePropertyId );
523
+		foreach ($constraintParameters[$languagePropertyId] as $snak) {
524
+			$languages[] = $this->parseStringParameter($snak, $languagePropertyId);
525 525
 		}
526 526
 		return $languages;
527 527
 	}
@@ -530,17 +530,17 @@  discard block
 block discarded – undo
530 530
 	 * Parse a single string parameter.
531 531
 	 * @throws ConstraintParameterException
532 532
 	 */
533
-	private function parseStringParameter( array $snakSerialization, string $parameterId ): string {
534
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
535
-		$this->requireValueParameter( $snak, $parameterId );
533
+	private function parseStringParameter(array $snakSerialization, string $parameterId): string {
534
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
535
+		$this->requireValueParameter($snak, $parameterId);
536 536
 		$value = $snak->getDataValue();
537
-		if ( $value instanceof StringValue ) {
537
+		if ($value instanceof StringValue) {
538 538
 			return $value->getValue();
539 539
 		} else {
540 540
 			throw new ConstraintParameterException(
541
-				( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) )
542
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
543
-					->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
541
+				(new ViolationMessage('wbqc-violation-message-parameter-string'))
542
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
543
+					->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
544 544
 			);
545 545
 		}
546 546
 	}
@@ -551,15 +551,15 @@  discard block
 block discarded – undo
551 551
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
552 552
 	 * @return string
553 553
 	 */
554
-	public function parseNamespaceParameter( array $constraintParameters, string $constraintTypeItemId ): string {
555
-		$this->checkError( $constraintParameters );
556
-		$namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' );
557
-		if ( !array_key_exists( $namespaceId, $constraintParameters ) ) {
554
+	public function parseNamespaceParameter(array $constraintParameters, string $constraintTypeItemId): string {
555
+		$this->checkError($constraintParameters);
556
+		$namespaceId = $this->config->get('WBQualityConstraintsNamespaceId');
557
+		if (!array_key_exists($namespaceId, $constraintParameters)) {
558 558
 			return '';
559 559
 		}
560 560
 
561
-		$this->requireSingleParameter( $constraintParameters, $namespaceId );
562
-		return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId );
561
+		$this->requireSingleParameter($constraintParameters, $namespaceId);
562
+		return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId);
563 563
 	}
564 564
 
565 565
 	/**
@@ -568,19 +568,19 @@  discard block
 block discarded – undo
568 568
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
569 569
 	 * @return string
570 570
 	 */
571
-	public function parseFormatParameter( array $constraintParameters, string $constraintTypeItemId ): string {
572
-		$this->checkError( $constraintParameters );
573
-		$formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' );
574
-		if ( !array_key_exists( $formatId, $constraintParameters ) ) {
571
+	public function parseFormatParameter(array $constraintParameters, string $constraintTypeItemId): string {
572
+		$this->checkError($constraintParameters);
573
+		$formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId');
574
+		if (!array_key_exists($formatId, $constraintParameters)) {
575 575
 			throw new ConstraintParameterException(
576
-				( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) )
577
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
578
-					->withEntityId( new NumericPropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
576
+				(new ViolationMessage('wbqc-violation-message-parameter-needed'))
577
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
578
+					->withEntityId(new NumericPropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY)
579 579
 			);
580 580
 		}
581 581
 
582
-		$this->requireSingleParameter( $constraintParameters, $formatId );
583
-		return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId );
582
+		$this->requireSingleParameter($constraintParameters, $formatId);
583
+		return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId);
584 584
 	}
585 585
 
586 586
 	/**
@@ -588,16 +588,16 @@  discard block
 block discarded – undo
588 588
 	 * @throws ConstraintParameterException if the parameter is invalid
589 589
 	 * @return EntityId[]
590 590
 	 */
591
-	public function parseExceptionParameter( array $constraintParameters ): array {
592
-		$this->checkError( $constraintParameters );
593
-		$exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' );
594
-		if ( !array_key_exists( $exceptionId, $constraintParameters ) ) {
591
+	public function parseExceptionParameter(array $constraintParameters): array {
592
+		$this->checkError($constraintParameters);
593
+		$exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId');
594
+		if (!array_key_exists($exceptionId, $constraintParameters)) {
595 595
 			return [];
596 596
 		}
597 597
 
598 598
 		return array_map(
599
-			function ( $snakSerialization ) use ( $exceptionId ) {
600
-				return $this->parseEntityIdParameter( $snakSerialization, $exceptionId );
599
+			function($snakSerialization) use ($exceptionId) {
600
+				return $this->parseEntityIdParameter($snakSerialization, $exceptionId);
601 601
 			},
602 602
 			$constraintParameters[$exceptionId]
603 603
 		);
@@ -608,39 +608,39 @@  discard block
 block discarded – undo
608 608
 	 * @throws ConstraintParameterException if the parameter is invalid
609 609
 	 * @return string|null 'mandatory', 'suggestion' or null
610 610
 	 */
611
-	public function parseConstraintStatusParameter( array $constraintParameters ): ?string {
612
-		$this->checkError( $constraintParameters );
613
-		$constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' );
614
-		if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) {
611
+	public function parseConstraintStatusParameter(array $constraintParameters): ?string {
612
+		$this->checkError($constraintParameters);
613
+		$constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId');
614
+		if (!array_key_exists($constraintStatusId, $constraintParameters)) {
615 615
 			return null;
616 616
 		}
617 617
 
618
-		$mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' );
619
-		$supportedStatuses = [ new ItemId( $mandatoryId ) ];
620
-		if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) {
621
-			$suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' );
622
-			$supportedStatuses[] = new ItemId( $suggestionId );
618
+		$mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId');
619
+		$supportedStatuses = [new ItemId($mandatoryId)];
620
+		if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) {
621
+			$suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId');
622
+			$supportedStatuses[] = new ItemId($suggestionId);
623 623
 		} else {
624 624
 			$suggestionId = null;
625 625
 		}
626 626
 
627
-		$this->requireSingleParameter( $constraintParameters, $constraintStatusId );
628
-		$snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] );
629
-		$this->requireValueParameter( $snak, $constraintStatusId );
627
+		$this->requireSingleParameter($constraintParameters, $constraintStatusId);
628
+		$snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]);
629
+		$this->requireValueParameter($snak, $constraintStatusId);
630 630
 		'@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak';
631 631
 		$dataValue = $snak->getDataValue();
632 632
 		'@phan-var EntityIdValue $dataValue';
633 633
 		$entityId = $dataValue->getEntityId();
634 634
 		$statusId = $entityId->getSerialization();
635 635
 
636
-		if ( $statusId === $mandatoryId ) {
636
+		if ($statusId === $mandatoryId) {
637 637
 			return 'mandatory';
638
-		} elseif ( $statusId === $suggestionId ) {
638
+		} elseif ($statusId === $suggestionId) {
639 639
 			return 'suggestion';
640 640
 		} else {
641 641
 			throw new ConstraintParameterException(
642
-				( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) )
643
-					->withEntityId( new NumericPropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
642
+				(new ViolationMessage('wbqc-violation-message-parameter-oneof'))
643
+					->withEntityId(new NumericPropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY)
644 644
 					->withEntityIdList(
645 645
 						$supportedStatuses,
646 646
 						Role::CONSTRAINT_PARAMETER_VALUE
@@ -653,12 +653,12 @@  discard block
 block discarded – undo
653 653
 	 * Require that $dataValue is a {@link MonolingualTextValue}.
654 654
 	 * @throws ConstraintParameterException
655 655
 	 */
656
-	private function requireMonolingualTextParameter( DataValue $dataValue, string $parameterId ): void {
657
-		if ( !( $dataValue instanceof MonolingualTextValue ) ) {
656
+	private function requireMonolingualTextParameter(DataValue $dataValue, string $parameterId): void {
657
+		if (!($dataValue instanceof MonolingualTextValue)) {
658 658
 			throw new ConstraintParameterException(
659
-				( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) )
660
-					->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
661
-					->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
659
+				(new ViolationMessage('wbqc-violation-message-parameter-monolingualtext'))
660
+					->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
661
+					->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
662 662
 			);
663 663
 		}
664 664
 	}
@@ -668,31 +668,31 @@  discard block
 block discarded – undo
668 668
 	 *
669 669
 	 * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts
670 670
 	 */
671
-	private function parseMultilingualTextParameter( array $snakSerializations, string $parameterId ): MultilingualTextValue {
671
+	private function parseMultilingualTextParameter(array $snakSerializations, string $parameterId): MultilingualTextValue {
672 672
 		$result = [];
673 673
 
674
-		foreach ( $snakSerializations as $snakSerialization ) {
675
-			$snak = $this->snakDeserializer->deserialize( $snakSerialization );
676
-			$this->requireValueParameter( $snak, $parameterId );
674
+		foreach ($snakSerializations as $snakSerialization) {
675
+			$snak = $this->snakDeserializer->deserialize($snakSerialization);
676
+			$this->requireValueParameter($snak, $parameterId);
677 677
 
678 678
 			$value = $snak->getDataValue();
679
-			$this->requireMonolingualTextParameter( $value, $parameterId );
679
+			$this->requireMonolingualTextParameter($value, $parameterId);
680 680
 			/** @var MonolingualTextValue $value */
681 681
 			'@phan-var MonolingualTextValue $value';
682 682
 
683 683
 			$code = $value->getLanguageCode();
684
-			if ( array_key_exists( $code, $result ) ) {
684
+			if (array_key_exists($code, $result)) {
685 685
 				throw new ConstraintParameterException(
686
-					( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) )
687
-						->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
688
-						->withLanguage( $code )
686
+					(new ViolationMessage('wbqc-violation-message-parameter-single-per-language'))
687
+						->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY)
688
+						->withLanguage($code)
689 689
 				);
690 690
 			}
691 691
 
692 692
 			$result[$code] = $value;
693 693
 		}
694 694
 
695
-		return new MultilingualTextValue( $result );
695
+		return new MultilingualTextValue($result);
696 696
 	}
697 697
 
698 698
 	/**
@@ -700,11 +700,11 @@  discard block
 block discarded – undo
700 700
 	 * @throws ConstraintParameterException if the parameter is invalid
701 701
 	 * @return MultilingualTextValue
702 702
 	 */
703
-	public function parseSyntaxClarificationParameter( array $constraintParameters ): MultilingualTextValue {
704
-		$syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' );
703
+	public function parseSyntaxClarificationParameter(array $constraintParameters): MultilingualTextValue {
704
+		$syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId');
705 705
 
706
-		if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) {
707
-			return new MultilingualTextValue( [] );
706
+		if (!array_key_exists($syntaxClarificationId, $constraintParameters)) {
707
+			return new MultilingualTextValue([]);
708 708
 		}
709 709
 
710 710
 		$syntaxClarifications = $this->parseMultilingualTextParameter(
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
 	 * @throws ConstraintParameterException if the parameter is invalid
721 721
 	 * @return MultilingualTextValue
722 722
 	 */
723
-	public function parseConstraintClarificationParameter( array $constraintParameters ): MultilingualTextValue {
724
-		$constraintClarificationId = $this->config->get( 'WBQualityConstraintsConstraintClarificationId' );
723
+	public function parseConstraintClarificationParameter(array $constraintParameters): MultilingualTextValue {
724
+		$constraintClarificationId = $this->config->get('WBQualityConstraintsConstraintClarificationId');
725 725
 
726
-		if ( !array_key_exists( $constraintClarificationId, $constraintParameters ) ) {
727
-			return new MultilingualTextValue( [] );
726
+		if (!array_key_exists($constraintClarificationId, $constraintParameters)) {
727
+			return new MultilingualTextValue([]);
728 728
 		}
729 729
 
730 730
 		$constraintClarifications = $this->parseMultilingualTextParameter(
@@ -757,14 +757,14 @@  discard block
 block discarded – undo
757 757
 		array $validContextTypes,
758 758
 		array $validEntityTypes
759 759
 	): array {
760
-		$contextTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' );
760
+		$contextTypeParameterId = $this->config->get('WBQualityConstraintsConstraintScopeId');
761 761
 		$contextTypeItemIds = $this->parseItemIdsParameter(
762 762
 			$constraintParameters,
763 763
 			$constraintTypeItemId,
764 764
 			false,
765 765
 			$contextTypeParameterId
766 766
 		);
767
-		$entityTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintEntityTypesId' );
767
+		$entityTypeParameterId = $this->config->get('WBQualityConstraintsConstraintEntityTypesId');
768 768
 		$entityTypeItemIds = $this->parseItemIdsParameter(
769 769
 			$constraintParameters,
770 770
 			$constraintTypeItemId,
@@ -780,26 +780,26 @@  discard block
 block discarded – undo
780 780
 		$contextTypes = null;
781 781
 		$entityTypes = null;
782 782
 
783
-		if ( $contextTypeParameterId === $entityTypeParameterId ) {
783
+		if ($contextTypeParameterId === $entityTypeParameterId) {
784 784
 			$itemIds = $contextTypeItemIds;
785 785
 			$mapping = $contextTypeMapping + $entityTypeMapping;
786
-			foreach ( $itemIds as $itemId ) {
787
-				$mapped = $this->mapItemId( $itemId, $mapping, $contextTypeParameterId );
788
-				if ( in_array( $mapped, $contextTypeMapping, true ) ) {
786
+			foreach ($itemIds as $itemId) {
787
+				$mapped = $this->mapItemId($itemId, $mapping, $contextTypeParameterId);
788
+				if (in_array($mapped, $contextTypeMapping, true)) {
789 789
 					$contextTypes[] = $mapped;
790 790
 				} else {
791 791
 					$entityTypes[] = $mapped;
792 792
 				}
793 793
 			}
794 794
 		} else {
795
-			foreach ( $contextTypeItemIds as $contextTypeItemId ) {
795
+			foreach ($contextTypeItemIds as $contextTypeItemId) {
796 796
 				$contextTypes[] = $this->mapItemId(
797 797
 					$contextTypeItemId,
798 798
 					$contextTypeMapping,
799 799
 					$contextTypeParameterId
800 800
 				);
801 801
 			}
802
-			foreach ( $entityTypeItemIds as $entityTypeItemId ) {
802
+			foreach ($entityTypeItemIds as $entityTypeItemId) {
803 803
 				$entityTypes[] = $this->mapItemId(
804 804
 					$entityTypeItemId,
805 805
 					$entityTypeMapping,
@@ -808,21 +808,21 @@  discard block
 block discarded – undo
808 808
 			}
809 809
 		}
810 810
 
811
-		$this->checkValidScope( $constraintTypeItemId, $contextTypes, $validContextTypes );
812
-		$this->checkValidScope( $constraintTypeItemId, $entityTypes, $validEntityTypes );
811
+		$this->checkValidScope($constraintTypeItemId, $contextTypes, $validContextTypes);
812
+		$this->checkValidScope($constraintTypeItemId, $entityTypes, $validEntityTypes);
813 813
 
814
-		return [ $contextTypes, $entityTypes ];
814
+		return [$contextTypes, $entityTypes];
815 815
 	}
816 816
 
817
-	private function checkValidScope( string $constraintTypeItemId, ?array $types, array $validTypes ): void {
818
-		$invalidTypes = array_diff( $types ?: [], $validTypes );
819
-		if ( $invalidTypes !== [] ) {
820
-			$invalidType = array_pop( $invalidTypes );
817
+	private function checkValidScope(string $constraintTypeItemId, ?array $types, array $validTypes): void {
818
+		$invalidTypes = array_diff($types ?: [], $validTypes);
819
+		if ($invalidTypes !== []) {
820
+			$invalidType = array_pop($invalidTypes);
821 821
 			throw new ConstraintParameterException(
822
-				( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) )
823
-					->withConstraintScope( $invalidType, Role::CONSTRAINT_PARAMETER_VALUE )
824
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
825
-					->withConstraintScopeList( $validTypes, Role::CONSTRAINT_PARAMETER_VALUE )
822
+				(new ViolationMessage('wbqc-violation-message-invalid-scope'))
823
+					->withConstraintScope($invalidType, Role::CONSTRAINT_PARAMETER_VALUE)
824
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
825
+					->withConstraintScopeList($validTypes, Role::CONSTRAINT_PARAMETER_VALUE)
826 826
 			);
827 827
 		}
828 828
 	}
@@ -830,8 +830,8 @@  discard block
 block discarded – undo
830 830
 	/**
831 831
 	 * Turn an item ID into a full unit string (using the concept URI).
832 832
 	 */
833
-	private function parseUnitParameter( ItemId $unitId ): string {
834
-		return $this->unitItemConceptBaseUri . $unitId->getSerialization();
833
+	private function parseUnitParameter(ItemId $unitId): string {
834
+		return $this->unitItemConceptBaseUri.$unitId->getSerialization();
835 835
 	}
836 836
 
837 837
 	/**
@@ -839,23 +839,23 @@  discard block
 block discarded – undo
839 839
 	 *
840 840
 	 * @throws ConstraintParameterException
841 841
 	 */
842
-	private function parseUnitItem( ItemIdSnakValue $item ): UnitsParameter {
843
-		switch ( true ) {
842
+	private function parseUnitItem(ItemIdSnakValue $item): UnitsParameter {
843
+		switch (true) {
844 844
 			case $item->isValue():
845
-				$unit = $this->parseUnitParameter( $item->getItemId() );
845
+				$unit = $this->parseUnitParameter($item->getItemId());
846 846
 				return new UnitsParameter(
847
-					[ $item->getItemId() ],
848
-					[ UnboundedQuantityValue::newFromNumber( 1, $unit ) ],
847
+					[$item->getItemId()],
848
+					[UnboundedQuantityValue::newFromNumber(1, $unit)],
849 849
 					false
850 850
 				);
851 851
 			case $item->isSomeValue():
852
-				$qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
852
+				$qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
853 853
 				throw new ConstraintParameterException(
854
-					( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) )
855
-						->withEntityId( new NumericPropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY )
854
+					(new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue'))
855
+						->withEntityId(new NumericPropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY)
856 856
 				);
857 857
 			case $item->isNoValue():
858
-				return new UnitsParameter( [], [], true );
858
+				return new UnitsParameter([], [], true);
859 859
 		}
860 860
 	}
861 861
 
@@ -865,36 +865,36 @@  discard block
 block discarded – undo
865 865
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
866 866
 	 * @return UnitsParameter
867 867
 	 */
868
-	public function parseUnitsParameter( array $constraintParameters, string $constraintTypeItemId ): UnitsParameter {
869
-		$items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true );
868
+	public function parseUnitsParameter(array $constraintParameters, string $constraintTypeItemId): UnitsParameter {
869
+		$items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true);
870 870
 		$unitItems = [];
871 871
 		$unitQuantities = [];
872 872
 		$unitlessAllowed = false;
873 873
 
874
-		foreach ( $items as $item ) {
875
-			$unit = $this->parseUnitItem( $item );
876
-			$unitItems = array_merge( $unitItems, $unit->getUnitItemIds() );
877
-			$unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() );
874
+		foreach ($items as $item) {
875
+			$unit = $this->parseUnitItem($item);
876
+			$unitItems = array_merge($unitItems, $unit->getUnitItemIds());
877
+			$unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities());
878 878
 			$unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed();
879 879
 		}
880 880
 
881
-		if ( $unitQuantities === [] && !$unitlessAllowed ) {
881
+		if ($unitQuantities === [] && !$unitlessAllowed) {
882 882
 			throw new LogicException(
883 883
 				'The "units" parameter is required, and yet we seem to be missing any allowed unit'
884 884
 			);
885 885
 		}
886 886
 
887
-		return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed );
887
+		return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed);
888 888
 	}
889 889
 
890 890
 	private function getEntityTypeMapping(): array {
891 891
 		return [
892
-			$this->config->get( 'WBQualityConstraintsWikibaseItemId' ) => 'item',
893
-			$this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) => 'property',
894
-			$this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) => 'lexeme',
895
-			$this->config->get( 'WBQualityConstraintsWikibaseFormId' ) => 'form',
896
-			$this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) => 'sense',
897
-			$this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) => 'mediainfo',
892
+			$this->config->get('WBQualityConstraintsWikibaseItemId') => 'item',
893
+			$this->config->get('WBQualityConstraintsWikibasePropertyId') => 'property',
894
+			$this->config->get('WBQualityConstraintsWikibaseLexemeId') => 'lexeme',
895
+			$this->config->get('WBQualityConstraintsWikibaseFormId') => 'form',
896
+			$this->config->get('WBQualityConstraintsWikibaseSenseId') => 'sense',
897
+			$this->config->get('WBQualityConstraintsWikibaseMediaInfoId') => 'mediainfo',
898 898
 		];
899 899
 	}
900 900
 
@@ -904,10 +904,10 @@  discard block
 block discarded – undo
904 904
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
905 905
 	 * @return EntityTypesParameter
906 906
 	 */
907
-	public function parseEntityTypesParameter( array $constraintParameters, string $constraintTypeItemId ): EntityTypesParameter {
907
+	public function parseEntityTypesParameter(array $constraintParameters, string $constraintTypeItemId): EntityTypesParameter {
908 908
 		$entityTypes = [];
909 909
 		$entityTypeItemIds = [];
910
-		$parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
910
+		$parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
911 911
 		$itemIds = $this->parseItemIdsParameter(
912 912
 			$constraintParameters,
913 913
 			$constraintTypeItemId,
@@ -916,22 +916,22 @@  discard block
 block discarded – undo
916 916
 		);
917 917
 
918 918
 		$mapping = $this->getEntityTypeMapping();
919
-		foreach ( $itemIds as $itemId ) {
920
-			$entityType = $this->mapItemId( $itemId, $mapping, $parameterId );
919
+		foreach ($itemIds as $itemId) {
920
+			$entityType = $this->mapItemId($itemId, $mapping, $parameterId);
921 921
 			$entityTypes[] = $entityType;
922 922
 			$entityTypeItemIds[] = $itemId;
923 923
 		}
924 924
 
925
-		if ( $entityTypes === [] ) {
925
+		if ($entityTypes === []) {
926 926
 			// @codeCoverageIgnoreStart
927 927
 			throw new LogicException(
928
-				'The "entity types" parameter is required, ' .
928
+				'The "entity types" parameter is required, '.
929 929
 				'and yet we seem to be missing any allowed entity type'
930 930
 			);
931 931
 			// @codeCoverageIgnoreEnd
932 932
 		}
933 933
 
934
-		return new EntityTypesParameter( $entityTypes, $entityTypeItemIds );
934
+		return new EntityTypesParameter($entityTypes, $entityTypeItemIds);
935 935
 	}
936 936
 
937 937
 	/**
@@ -939,18 +939,18 @@  discard block
 block discarded – undo
939 939
 	 * @throws ConstraintParameterException if the parameter is invalid
940 940
 	 * @return PropertyId[]
941 941
 	 */
942
-	public function parseSeparatorsParameter( array $constraintParameters ): array {
943
-		$separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' );
942
+	public function parseSeparatorsParameter(array $constraintParameters): array {
943
+		$separatorId = $this->config->get('WBQualityConstraintsSeparatorId');
944 944
 
945
-		if ( !array_key_exists( $separatorId, $constraintParameters ) ) {
945
+		if (!array_key_exists($separatorId, $constraintParameters)) {
946 946
 			return [];
947 947
 		}
948 948
 
949 949
 		$parameters = $constraintParameters[$separatorId];
950 950
 		$separators = [];
951 951
 
952
-		foreach ( $parameters as $parameter ) {
953
-			$separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId );
952
+		foreach ($parameters as $parameter) {
953
+			$separators[] = $this->parsePropertyIdParameter($parameter, $separatorId);
954 954
 		}
955 955
 
956 956
 		return $separators;
@@ -958,17 +958,17 @@  discard block
 block discarded – undo
958 958
 
959 959
 	private function getConstraintScopeContextTypeMapping(): array {
960 960
 		return [
961
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ) => Context::TYPE_STATEMENT,
962
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ) => Context::TYPE_QUALIFIER,
963
-			$this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ) => Context::TYPE_REFERENCE,
961
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId') => Context::TYPE_STATEMENT,
962
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId') => Context::TYPE_QUALIFIER,
963
+			$this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId') => Context::TYPE_REFERENCE,
964 964
 		];
965 965
 	}
966 966
 
967 967
 	private function getPropertyScopeContextTypeMapping(): array {
968 968
 		return [
969
-			$this->config->get( 'WBQualityConstraintsAsMainValueId' ) => Context::TYPE_STATEMENT,
970
-			$this->config->get( 'WBQualityConstraintsAsQualifiersId' ) => Context::TYPE_QUALIFIER,
971
-			$this->config->get( 'WBQualityConstraintsAsReferencesId' ) => Context::TYPE_REFERENCE,
969
+			$this->config->get('WBQualityConstraintsAsMainValueId') => Context::TYPE_STATEMENT,
970
+			$this->config->get('WBQualityConstraintsAsQualifiersId') => Context::TYPE_QUALIFIER,
971
+			$this->config->get('WBQualityConstraintsAsReferencesId') => Context::TYPE_REFERENCE,
972 972
 		];
973 973
 	}
974 974
 
@@ -978,9 +978,9 @@  discard block
 block discarded – undo
978 978
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
979 979
 	 * @return string[] list of Context::TYPE_* constants
980 980
 	 */
981
-	public function parsePropertyScopeParameter( array $constraintParameters, string $constraintTypeItemId ): array {
981
+	public function parsePropertyScopeParameter(array $constraintParameters, string $constraintTypeItemId): array {
982 982
 		$contextTypes = [];
983
-		$parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' );
983
+		$parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId');
984 984
 		$itemIds = $this->parseItemIdsParameter(
985 985
 			$constraintParameters,
986 986
 			$constraintTypeItemId,
@@ -989,14 +989,14 @@  discard block
 block discarded – undo
989 989
 		);
990 990
 
991 991
 		$mapping = $this->getPropertyScopeContextTypeMapping();
992
-		foreach ( $itemIds as $itemId ) {
993
-			$contextTypes[] = $this->mapItemId( $itemId, $mapping, $parameterId );
992
+		foreach ($itemIds as $itemId) {
993
+			$contextTypes[] = $this->mapItemId($itemId, $mapping, $parameterId);
994 994
 		}
995 995
 
996
-		if ( $contextTypes === [] ) {
996
+		if ($contextTypes === []) {
997 997
 			// @codeCoverageIgnoreStart
998 998
 			throw new LogicException(
999
-				'The "property scope" parameter is required, ' .
999
+				'The "property scope" parameter is required, '.
1000 1000
 				'and yet we seem to be missing any allowed scope'
1001 1001
 			);
1002 1002
 			// @codeCoverageIgnoreEnd
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/UniqueValueChecker.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker;
6 6
 
@@ -64,18 +64,18 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs
66 66
 	 */
67
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
68
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
69
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED );
67
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
68
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
69
+			return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED);
70 70
 		}
71 71
 
72
-		if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) {
72
+		if (!($this->sparqlHelper instanceof DummySparqlHelper)) {
73 73
 
74 74
 			$separators = $this->constraintParameterParser->parseSeparatorsParameter(
75 75
 				$constraint->getConstraintParameters()
76 76
 			);
77 77
 
78
-			if ( $context->getType() === 'statement' ) {
78
+			if ($context->getType() === 'statement') {
79 79
 				$statement = $context->getSnakStatement();
80 80
 				'@phan-var Statement $statement';
81 81
 				$result = $this->sparqlHelper->findEntitiesWithSameStatement(
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 				);
85 85
 			} else {
86 86
 				$snak = $context->getSnak();
87
-				if ( !$snak instanceof PropertyValueSnak ) {
87
+				if (!$snak instanceof PropertyValueSnak) {
88 88
 					// nothing to check
89
-					return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
89
+					return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
90 90
 				}
91 91
 				$result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference(
92 92
 					$context->getEntity()->getId(),
@@ -99,31 +99,31 @@  discard block
 block discarded – undo
99 99
 			$otherEntities = $result->getArray();
100 100
 			$metadata = $result->getMetadata();
101 101
 
102
-			if ( $otherEntities === [] ) {
102
+			if ($otherEntities === []) {
103 103
 				$status = CheckResult::STATUS_COMPLIANCE;
104 104
 				$message = null;
105 105
 			} else {
106 106
 				$status = CheckResult::STATUS_VIOLATION;
107
-				$message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) )
108
-					->withEntityIdList( $otherEntities, Role::SUBJECT );
107
+				$message = (new ViolationMessage('wbqc-violation-message-unique-value'))
108
+					->withEntityIdList($otherEntities, Role::SUBJECT);
109 109
 			}
110 110
 		} else {
111 111
 			$status = CheckResult::STATUS_TODO;
112
-			$message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) )
113
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM );
112
+			$message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented'))
113
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM);
114 114
 			$metadata = Metadata::blank();
115 115
 		}
116 116
 
117
-		return ( new CheckResult( $context, $constraint, $status, $message ) )
118
-			->withMetadata( $metadata );
117
+		return (new CheckResult($context, $constraint, $status, $message))
118
+			->withMetadata($metadata);
119 119
 	}
120 120
 
121
-	public function checkConstraintParameters( Constraint $constraint ): array {
121
+	public function checkConstraintParameters(Constraint $constraint): array {
122 122
 		$constraintParameters = $constraint->getConstraintParameters();
123 123
 		$exceptions = [];
124 124
 		try {
125
-			$this->constraintParameterParser->parseSeparatorsParameter( $constraintParameters );
126
-		} catch ( ConstraintParameterException $e ) {
125
+			$this->constraintParameterParser->parseSeparatorsParameter($constraintParameters);
126
+		} catch (ConstraintParameterException $e) {
127 127
 			$exceptions[] = $e;
128 128
 		}
129 129
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Cache/CachedEntityIds.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Cache;
6 6
 
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/SparqlHelper.php 1 patch
Spacing   +185 added lines, -188 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper;
6 6
 
@@ -148,74 +148,74 @@  discard block
 block discarded – undo
148 148
 		$this->defaultUserAgent = $defaultUserAgent;
149 149
 		$this->requestFactory = $requestFactory;
150 150
 		$this->entityPrefixes = [];
151
-		foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) {
152
-			$this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName );
151
+		foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) {
152
+			$this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName);
153 153
 		}
154 154
 
155
-		$this->primaryEndpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' );
156
-		$this->additionalEndpoints = $config->get( 'WBQualityConstraintsAdditionalSparqlEndpoints' ) ?: [];
157
-		$this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' );
158
-		$this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' );
159
-		$this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' );
160
-		$this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' );
155
+		$this->primaryEndpoint = $config->get('WBQualityConstraintsSparqlEndpoint');
156
+		$this->additionalEndpoints = $config->get('WBQualityConstraintsAdditionalSparqlEndpoints') ?: [];
157
+		$this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis');
158
+		$this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId');
159
+		$this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId');
160
+		$this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize');
161 161
 		$this->timeoutExceptionClasses = $config->get(
162 162
 			'WBQualityConstraintsSparqlTimeoutExceptionClasses'
163 163
 		);
164 164
 		$this->sparqlHasWikibaseSupport = $config->get(
165 165
 			'WBQualityConstraintsSparqlHasWikibaseSupport'
166 166
 		);
167
-		$this->sparqlThrottlingFallbackDuration = (int)$config->get(
167
+		$this->sparqlThrottlingFallbackDuration = (int) $config->get(
168 168
 			'WBQualityConstraintsSparqlThrottlingFallbackDuration'
169 169
 		);
170 170
 
171
-		$this->prefixes = $this->getQueryPrefixes( $rdfVocabulary );
171
+		$this->prefixes = $this->getQueryPrefixes($rdfVocabulary);
172 172
 	}
173 173
 
174
-	private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ): string {
174
+	private function getQueryPrefixes(RdfVocabulary $rdfVocabulary): string {
175 175
 		// TODO: it would probably be smarter that RdfVocabulary exposed these prefixes somehow
176 176
 		$prefixes = '';
177
-		foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) {
177
+		foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) {
178 178
 			$prefixes .= <<<END
179
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
179
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
180 180
 END;
181 181
 		}
182 182
 		$prefixes .= <<<END
183
-PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}>
184
-PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n
183
+PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}>
184
+PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n
185 185
 END;
186 186
 
187
-		foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) {
187
+		foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) {
188 188
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM];
189 189
 			$prefixes .= <<<END
190
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
190
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
191 191
 END;
192 192
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM];
193 193
 			$prefixes .= <<<END
194
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
194
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
195 195
 END;
196 196
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT];
197 197
 			$prefixes .= <<<END
198
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
198
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
199 199
 END;
200 200
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER];
201 201
 			$prefixes .= <<<END
202
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
202
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
203 203
 END;
204 204
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE];
205 205
 			$prefixes .= <<<END
206
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
206
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
207 207
 END;
208 208
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE];
209 209
 			$prefixes .= <<<END
210
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
210
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
211 211
 END;
212 212
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE];
213 213
 			$prefixes .= <<<END
214
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
214
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
215 215
 END;
216 216
 		}
217 217
 		$prefixes .= <<<END
218
-PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n
218
+PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n
219 219
 END;
220 220
 		return $prefixes;
221 221
 	}
@@ -227,21 +227,20 @@  discard block
 block discarded – undo
227 227
 	 * @return CachedBool
228 228
 	 * @throws SparqlHelperException if the query times out or some other error occurs
229 229
 	 */
230
-	public function hasType( string $id, array $classes ): CachedBool {
230
+	public function hasType(string $id, array $classes): CachedBool {
231 231
 		// TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually
232 232
 		$gearingHint = $this->sparqlHasWikibaseSupport ?
233
-			' hint:Prior hint:gearing "forward".' :
234
-			'';
233
+			' hint:Prior hint:gearing "forward".' : '';
235 234
 
236 235
 		$metadatas = [];
237 236
 
238
-		foreach ( array_chunk( $classes, 20 ) as $classesChunk ) {
239
-			$classesValues = implode( ' ', array_map(
240
-				static function ( $class ) {
241
-					return 'wd:' . $class;
237
+		foreach (array_chunk($classes, 20) as $classesChunk) {
238
+			$classesValues = implode(' ', array_map(
239
+				static function($class) {
240
+					return 'wd:'.$class;
242 241
 				},
243 242
 				$classesChunk
244
-			) );
243
+			));
245 244
 
246 245
 			$query = <<<EOF
247 246
 ASK {
@@ -251,19 +250,19 @@  discard block
 block discarded – undo
251 250
 }
252 251
 EOF;
253 252
 
254
-			$result = $this->runQuery( $query, $this->primaryEndpoint );
253
+			$result = $this->runQuery($query, $this->primaryEndpoint);
255 254
 			$metadatas[] = $result->getMetadata();
256
-			if ( $result->getArray()['boolean'] ) {
255
+			if ($result->getArray()['boolean']) {
257 256
 				return new CachedBool(
258 257
 					true,
259
-					Metadata::merge( $metadatas )
258
+					Metadata::merge($metadatas)
260 259
 				);
261 260
 			}
262 261
 		}
263 262
 
264 263
 		return new CachedBool(
265 264
 			false,
266
-			Metadata::merge( $metadatas )
265
+			Metadata::merge($metadatas)
267 266
 		);
268 267
 	}
269 268
 
@@ -271,7 +270,7 @@  discard block
 block discarded – undo
271 270
 	 * Helper function used by findEntitiesWithSameStatement to filter
272 271
 	 * out entities with different qualifiers or no qualifier value.
273 272
 	 */
274
-	private function nestedSeparatorFilter( PropertyId $separator ): string {
273
+	private function nestedSeparatorFilter(PropertyId $separator): string {
275 274
 		$filter = <<<EOF
276 275
   MINUS {
277 276
     ?statement pq:$separator ?qualifier.
@@ -308,14 +307,14 @@  discard block
 block discarded – undo
308 307
 	 * @return CachedEntityIds
309 308
 	 * @throws SparqlHelperException if the query times out or some other error occurs
310 309
 	 */
311
-	public function findEntitiesWithSameStatement( Statement $statement, array $separators ): CachedEntityIds {
310
+	public function findEntitiesWithSameStatement(Statement $statement, array $separators): CachedEntityIds {
312 311
 		$pid = $statement->getPropertyId()->getSerialization();
313 312
 		$guid = $statement->getGuid();
314 313
 		'@phan-var string $guid'; // statement must have a non-null GUID
315
-		$guidForRdf = str_replace( '$', '-', $guid );
314
+		$guidForRdf = str_replace('$', '-', $guid);
316 315
 
317
-		$separatorFilters = array_map( [ $this, 'nestedSeparatorFilter' ], $separators );
318
-		$finalSeparatorFilter = implode( "\n", $separatorFilters );
316
+		$separatorFilters = array_map([$this, 'nestedSeparatorFilter'], $separators);
317
+		$finalSeparatorFilter = implode("\n", $separatorFilters);
319 318
 
320 319
 		$query = <<<EOF
321 320
 SELECT DISTINCT ?otherEntity WHERE {
@@ -333,12 +332,12 @@  discard block
 block discarded – undo
333 332
 LIMIT 10
334 333
 EOF;
335 334
 
336
-		$results = [ $this->runQuery( $query, $this->primaryEndpoint ) ];
337
-		foreach ( $this->additionalEndpoints as $endpoint ) {
338
-			$results[] = $this->runQuery( $query, $endpoint );
335
+		$results = [$this->runQuery($query, $this->primaryEndpoint)];
336
+		foreach ($this->additionalEndpoints as $endpoint) {
337
+			$results[] = $this->runQuery($query, $endpoint);
339 338
 		}
340 339
 
341
-		return $this->getOtherEntities( $results );
340
+		return $this->getOtherEntities($results);
342 341
 	}
343 342
 
344 343
 	/**
@@ -363,16 +362,15 @@  discard block
 block discarded – undo
363 362
 		$dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty(
364 363
 			$snak->getPropertyId()
365 364
 		);
366
-		[ $value, $isFullValue ] = $this->getRdfLiteral( $dataType, $dataValue );
367
-		if ( $isFullValue ) {
365
+		[$value, $isFullValue] = $this->getRdfLiteral($dataType, $dataValue);
366
+		if ($isFullValue) {
368 367
 			$prefix .= 'v';
369 368
 		}
370 369
 		$path = $type === Context::TYPE_QUALIFIER ?
371
-			"$prefix:$pid" :
372
-			"prov:wasDerivedFrom/$prefix:$pid";
370
+			"$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid";
373 371
 
374 372
 		$deprecatedFilter = '';
375
-		if ( $ignoreDeprecatedStatements ) {
373
+		if ($ignoreDeprecatedStatements) {
376 374
 			$deprecatedFilter = <<< EOF
377 375
   MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }
378 376
 EOF;
@@ -392,19 +390,19 @@  discard block
 block discarded – undo
392 390
 LIMIT 10
393 391
 EOF;
394 392
 
395
-		$results = [ $this->runQuery( $query, $this->primaryEndpoint ) ];
396
-		foreach ( $this->additionalEndpoints as $endpoint ) {
397
-			$results[] = $this->runQuery( $query, $endpoint );
393
+		$results = [$this->runQuery($query, $this->primaryEndpoint)];
394
+		foreach ($this->additionalEndpoints as $endpoint) {
395
+			$results[] = $this->runQuery($query, $endpoint);
398 396
 		}
399 397
 
400
-		return $this->getOtherEntities( $results );
398
+		return $this->getOtherEntities($results);
401 399
 	}
402 400
 
403 401
 	/**
404 402
 	 * Return SPARQL code for a string literal with $text as content.
405 403
 	 */
406
-	private function stringLiteral( string $text ): string {
407
-		return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"';
404
+	private function stringLiteral(string $text): string {
405
+		return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"';
408 406
 	}
409 407
 
410 408
 	/**
@@ -414,26 +412,26 @@  discard block
 block discarded – undo
414 412
 	 *
415 413
 	 * @return CachedEntityIds
416 414
 	 */
417
-	private function getOtherEntities( array $results ): CachedEntityIds {
415
+	private function getOtherEntities(array $results): CachedEntityIds {
418 416
 		$allResultBindings = [];
419 417
 		$metadatas = [];
420 418
 
421
-		foreach ( $results as $result ) {
419
+		foreach ($results as $result) {
422 420
 			$metadatas[] = $result->getMetadata();
423
-			$allResultBindings = array_merge( $allResultBindings, $result->getArray()['results']['bindings'] );
421
+			$allResultBindings = array_merge($allResultBindings, $result->getArray()['results']['bindings']);
424 422
 		}
425 423
 
426 424
 		$entityIds = array_map(
427
-			function ( $resultBindings ) {
425
+			function($resultBindings) {
428 426
 				$entityIRI = $resultBindings['otherEntity']['value'];
429
-				foreach ( $this->entityPrefixes as $entityPrefix ) {
430
-					$entityPrefixLength = strlen( $entityPrefix );
431
-					if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) {
427
+				foreach ($this->entityPrefixes as $entityPrefix) {
428
+					$entityPrefixLength = strlen($entityPrefix);
429
+					if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) {
432 430
 						try {
433 431
 							return $this->entityIdParser->parse(
434
-								substr( $entityIRI, $entityPrefixLength )
432
+								substr($entityIRI, $entityPrefixLength)
435 433
 							);
436
-						} catch ( EntityIdParsingException $e ) {
434
+						} catch (EntityIdParsingException $e) {
437 435
 							// fall through
438 436
 						}
439 437
 					}
@@ -447,8 +445,8 @@  discard block
 block discarded – undo
447 445
 		);
448 446
 
449 447
 		return new CachedEntityIds(
450
-			array_values( array_filter( array_unique( $entityIds ) ) ),
451
-			Metadata::merge( $metadatas )
448
+			array_values(array_filter(array_unique($entityIds))),
449
+			Metadata::merge($metadatas)
452 450
 		);
453 451
 	}
454 452
 
@@ -459,50 +457,50 @@  discard block
 block discarded – undo
459 457
 	 * @return array the literal or IRI as a string in SPARQL syntax,
460 458
 	 * and a boolean indicating whether it refers to a full value node or not
461 459
 	 */
462
-	private function getRdfLiteral( string $dataType, DataValue $dataValue ): array {
463
-		switch ( $dataType ) {
460
+	private function getRdfLiteral(string $dataType, DataValue $dataValue): array {
461
+		switch ($dataType) {
464 462
 			case 'string':
465 463
 			case 'external-id':
466
-				return [ $this->stringLiteral( $dataValue->getValue() ), false ];
464
+				return [$this->stringLiteral($dataValue->getValue()), false];
467 465
 			case 'commonsMedia':
468
-				$url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() );
469
-				return [ '<' . $url . '>', false ];
466
+				$url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue());
467
+				return ['<'.$url.'>', false];
470 468
 			case 'geo-shape':
471
-				$url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() );
472
-				return [ '<' . $url . '>', false ];
469
+				$url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue());
470
+				return ['<'.$url.'>', false];
473 471
 			case 'tabular-data':
474
-				$url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() );
475
-				return [ '<' . $url . '>', false ];
472
+				$url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue());
473
+				return ['<'.$url.'>', false];
476 474
 			case 'url':
477 475
 				$url = $dataValue->getValue();
478
-				if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) {
476
+				if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) {
479 477
 					// not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF)
480 478
 					// such an URL should never reach us, so just throw
481
-					throw new InvalidArgumentException( 'invalid URL: ' . $url );
479
+					throw new InvalidArgumentException('invalid URL: '.$url);
482 480
 				}
483
-				return [ '<' . $url . '>', false ];
481
+				return ['<'.$url.'>', false];
484 482
 			case 'wikibase-item':
485 483
 			case 'wikibase-property':
486 484
 				/** @var EntityIdValue $dataValue */
487 485
 				'@phan-var EntityIdValue $dataValue';
488
-				return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ];
486
+				return ['wd:'.$dataValue->getEntityId()->getSerialization(), false];
489 487
 			case 'monolingualtext':
490 488
 				/** @var MonolingualTextValue $dataValue */
491 489
 				'@phan-var MonolingualTextValue $dataValue';
492 490
 				$lang = $dataValue->getLanguageCode();
493
-				if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) {
491
+				if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) {
494 492
 					// not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG)
495 493
 					// such a language tag should never reach us, so just throw
496
-					throw new InvalidArgumentException( 'invalid language tag: ' . $lang );
494
+					throw new InvalidArgumentException('invalid language tag: '.$lang);
497 495
 				}
498
-				return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ];
496
+				return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false];
499 497
 			case 'globe-coordinate':
500 498
 			case 'quantity':
501 499
 			case 'time':
502 500
 				// @phan-suppress-next-line PhanUndeclaredMethod
503
-				return [ 'wdv:' . $dataValue->getHash(), true ];
501
+				return ['wdv:'.$dataValue->getHash(), true];
504 502
 			default:
505
-				throw new InvalidArgumentException( 'unknown data type: ' . $dataType );
503
+				throw new InvalidArgumentException('unknown data type: '.$dataType);
506 504
 		}
507 505
 	}
508 506
 	// phpcs:enable
@@ -511,43 +509,43 @@  discard block
 block discarded – undo
511 509
 	 * @throws SparqlHelperException if the query times out or some other error occurs
512 510
 	 * @throws ConstraintParameterException if the $regex is invalid
513 511
 	 */
514
-	public function matchesRegularExpression( string $text, string $regex ): bool {
512
+	public function matchesRegularExpression(string $text, string $regex): bool {
515 513
 		// caching wrapper around matchesRegularExpressionWithSparql
516 514
 
517
-		$textHash = hash( 'sha256', $text );
515
+		$textHash = hash('sha256', $text);
518 516
 		$cacheKey = $this->cache->makeKey(
519 517
 			'WikibaseQualityConstraints', // extension
520 518
 			'regex', // action
521 519
 			'WDQS-Java', // regex flavor
522
-			hash( 'sha256', $regex )
520
+			hash('sha256', $regex)
523 521
 		);
524 522
 
525 523
 		$cacheMapArray = $this->cache->getWithSetCallback(
526 524
 			$cacheKey,
527 525
 			WANObjectCache::TTL_DAY,
528
-			function ( $cacheMapArray ) use ( $text, $regex, $textHash ) {
526
+			function($cacheMapArray) use ($text, $regex, $textHash) {
529 527
 				// Initialize the cache map if not set
530
-				if ( $cacheMapArray === false ) {
528
+				if ($cacheMapArray === false) {
531 529
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.init';
532
-					$this->dataFactory->increment( $key );
530
+					$this->dataFactory->increment($key);
533 531
 					return [];
534 532
 				}
535 533
 
536 534
 				$key = 'wikibase.quality.constraints.regex.cache.refresh';
537
-				$this->dataFactory->increment( $key );
538
-				$cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize );
539
-				if ( $cacheMap->has( $textHash ) ) {
535
+				$this->dataFactory->increment($key);
536
+				$cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize);
537
+				if ($cacheMap->has($textHash)) {
540 538
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.hit';
541
-					$this->dataFactory->increment( $key );
542
-					$cacheMap->get( $textHash ); // ping cache
539
+					$this->dataFactory->increment($key);
540
+					$cacheMap->get($textHash); // ping cache
543 541
 				} else {
544 542
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.miss';
545
-					$this->dataFactory->increment( $key );
543
+					$this->dataFactory->increment($key);
546 544
 					try {
547
-						$matches = $this->matchesRegularExpressionWithSparql( $text, $regex );
548
-					} catch ( ConstraintParameterException $e ) {
549
-						$matches = $this->serializeConstraintParameterException( $e );
550
-					} catch ( SparqlHelperException $e ) {
545
+						$matches = $this->matchesRegularExpressionWithSparql($text, $regex);
546
+					} catch (ConstraintParameterException $e) {
547
+						$matches = $this->serializeConstraintParameterException($e);
548
+					} catch (SparqlHelperException $e) {
551 549
 						// don’t cache this
552 550
 						return $cacheMap->toArray();
553 551
 					}
@@ -571,42 +569,42 @@  discard block
 block discarded – undo
571 569
 			]
572 570
 		);
573 571
 
574
-		if ( isset( $cacheMapArray[$textHash] ) ) {
572
+		if (isset($cacheMapArray[$textHash])) {
575 573
 			$key = 'wikibase.quality.constraints.regex.cache.hit';
576
-			$this->dataFactory->increment( $key );
574
+			$this->dataFactory->increment($key);
577 575
 			$matches = $cacheMapArray[$textHash];
578
-			if ( is_bool( $matches ) ) {
576
+			if (is_bool($matches)) {
579 577
 				return $matches;
580
-			} elseif ( is_array( $matches ) &&
581
-				$matches['type'] == ConstraintParameterException::class ) {
582
-				throw $this->deserializeConstraintParameterException( $matches );
578
+			} elseif (is_array($matches) &&
579
+				$matches['type'] == ConstraintParameterException::class) {
580
+				throw $this->deserializeConstraintParameterException($matches);
583 581
 			} else {
584 582
 				throw new UnexpectedValueException(
585
-					'Value of unknown type in object cache (' .
586
-					'cache key: ' . $cacheKey . ', ' .
587
-					'cache map key: ' . $textHash . ', ' .
588
-					'value type: ' . get_debug_type( $matches ) . ')'
583
+					'Value of unknown type in object cache ('.
584
+					'cache key: '.$cacheKey.', '.
585
+					'cache map key: '.$textHash.', '.
586
+					'value type: '.get_debug_type($matches).')'
589 587
 				);
590 588
 			}
591 589
 		} else {
592 590
 			$key = 'wikibase.quality.constraints.regex.cache.miss';
593
-			$this->dataFactory->increment( $key );
594
-			return $this->matchesRegularExpressionWithSparql( $text, $regex );
591
+			$this->dataFactory->increment($key);
592
+			return $this->matchesRegularExpressionWithSparql($text, $regex);
595 593
 		}
596 594
 	}
597 595
 
598
-	private function serializeConstraintParameterException( ConstraintParameterException $cpe ): array {
596
+	private function serializeConstraintParameterException(ConstraintParameterException $cpe): array {
599 597
 		return [
600 598
 			'type' => ConstraintParameterException::class,
601
-			'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ),
599
+			'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()),
602 600
 		];
603 601
 	}
604 602
 
605
-	private function deserializeConstraintParameterException( array $serialization ): ConstraintParameterException {
603
+	private function deserializeConstraintParameterException(array $serialization): ConstraintParameterException {
606 604
 		$message = $this->violationMessageDeserializer->deserialize(
607 605
 			$serialization['violationMessage']
608 606
 		);
609
-		return new ConstraintParameterException( $message );
607
+		return new ConstraintParameterException($message);
610 608
 	}
611 609
 
612 610
 	/**
@@ -616,25 +614,25 @@  discard block
 block discarded – undo
616 614
 	 * @throws SparqlHelperException if the query times out or some other error occurs
617 615
 	 * @throws ConstraintParameterException if the $regex is invalid
618 616
 	 */
619
-	public function matchesRegularExpressionWithSparql( string $text, string $regex ): bool {
620
-		$textStringLiteral = $this->stringLiteral( $text );
621
-		$regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' );
617
+	public function matchesRegularExpressionWithSparql(string $text, string $regex): bool {
618
+		$textStringLiteral = $this->stringLiteral($text);
619
+		$regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$');
622 620
 
623 621
 		$query = <<<EOF
624 622
 SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {}
625 623
 EOF;
626 624
 
627
-		$result = $this->runQuery( $query, $this->primaryEndpoint, false );
625
+		$result = $this->runQuery($query, $this->primaryEndpoint, false);
628 626
 
629 627
 		$vars = $result->getArray()['results']['bindings'][0];
630
-		if ( array_key_exists( 'matches', $vars ) ) {
628
+		if (array_key_exists('matches', $vars)) {
631 629
 			// true or false ⇒ regex okay, text matches or not
632 630
 			return $vars['matches']['value'] === 'true';
633 631
 		} else {
634 632
 			// empty result: regex broken
635 633
 			throw new ConstraintParameterException(
636
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
637
-					->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE )
634
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
635
+					->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE)
638 636
 			);
639 637
 		}
640 638
 	}
@@ -642,14 +640,14 @@  discard block
 block discarded – undo
642 640
 	/**
643 641
 	 * Check whether the text content of an error response indicates a query timeout.
644 642
 	 */
645
-	public function isTimeout( string $responseContent ): bool {
646
-		$timeoutRegex = implode( '|', array_map(
647
-			static function ( $fqn ) {
648
-				return preg_quote( $fqn, '/' );
643
+	public function isTimeout(string $responseContent): bool {
644
+		$timeoutRegex = implode('|', array_map(
645
+			static function($fqn) {
646
+				return preg_quote($fqn, '/');
649 647
 			},
650 648
 			$this->timeoutExceptionClasses
651
-		) );
652
-		return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent );
649
+		));
650
+		return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent);
653 651
 	}
654 652
 
655 653
 	/**
@@ -661,17 +659,17 @@  discard block
 block discarded – undo
661 659
 	 * @return int|boolean the max-age (in seconds)
662 660
 	 * or a plain boolean if no max-age can be determined
663 661
 	 */
664
-	public function getCacheMaxAge( array $responseHeaders ) {
662
+	public function getCacheMaxAge(array $responseHeaders) {
665 663
 		if (
666
-			array_key_exists( 'x-cache-status', $responseHeaders ) &&
667
-			preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] )
664
+			array_key_exists('x-cache-status', $responseHeaders) &&
665
+			preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0])
668 666
 		) {
669 667
 			$maxage = [];
670 668
 			if (
671
-				array_key_exists( 'cache-control', $responseHeaders ) &&
672
-				preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage )
669
+				array_key_exists('cache-control', $responseHeaders) &&
670
+				preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage)
673 671
 			) {
674
-				return intval( $maxage[1] );
672
+				return intval($maxage[1]);
675 673
 			} else {
676 674
 				return true;
677 675
 			}
@@ -692,34 +690,34 @@  discard block
 block discarded – undo
692 690
 	 * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After
693 691
 	 * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format
694 692
 	 */
695
-	public function getThrottling( MWHttpRequest $request ) {
696
-		$retryAfterValue = $request->getResponseHeader( 'Retry-After' );
697
-		if ( $retryAfterValue === null ) {
693
+	public function getThrottling(MWHttpRequest $request) {
694
+		$retryAfterValue = $request->getResponseHeader('Retry-After');
695
+		if ($retryAfterValue === null) {
698 696
 			return self::NO_RETRY_AFTER;
699 697
 		}
700 698
 
701
-		$trimmedRetryAfterValue = trim( $retryAfterValue );
702
-		if ( $trimmedRetryAfterValue === '' ) {
699
+		$trimmedRetryAfterValue = trim($retryAfterValue);
700
+		if ($trimmedRetryAfterValue === '') {
703 701
 			return self::EMPTY_RETRY_AFTER;
704 702
 		}
705 703
 
706
-		if ( is_numeric( $trimmedRetryAfterValue ) ) {
707
-			$delaySeconds = (int)$trimmedRetryAfterValue;
708
-			if ( $delaySeconds >= 0 ) {
709
-				return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) );
704
+		if (is_numeric($trimmedRetryAfterValue)) {
705
+			$delaySeconds = (int) $trimmedRetryAfterValue;
706
+			if ($delaySeconds >= 0) {
707
+				return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S'));
710 708
 			}
711 709
 		} else {
712
-			$return = strtotime( $trimmedRetryAfterValue );
713
-			if ( $return !== false ) {
714
-				return new ConvertibleTimestamp( $return );
710
+			$return = strtotime($trimmedRetryAfterValue);
711
+			if ($return !== false) {
712
+				return new ConvertibleTimestamp($return);
715 713
 			}
716 714
 		}
717 715
 		return self::INVALID_RETRY_AFTER;
718 716
 	}
719 717
 
720
-	private function getTimestampInFuture( DateInterval $delta ) {
718
+	private function getTimestampInFuture(DateInterval $delta) {
721 719
 		$now = new ConvertibleTimestamp();
722
-		return new ConvertibleTimestamp( $now->timestamp->add( $delta ) );
720
+		return new ConvertibleTimestamp($now->timestamp->add($delta));
723 721
 	}
724 722
 
725 723
 	/**
@@ -734,64 +732,63 @@  discard block
 block discarded – undo
734 732
 	 *
735 733
 	 * @throws SparqlHelperException if the query times out or some other error occurs
736 734
 	 */
737
-	protected function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults {
738
-		if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) {
739
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
735
+	protected function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults {
736
+		if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) {
737
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
740 738
 			throw new TooManySparqlRequestsException();
741 739
 		}
742 740
 
743
-		if ( $this->sparqlHasWikibaseSupport ) {
741
+		if ($this->sparqlHasWikibaseSupport) {
744 742
 			$needsPrefixes = false;
745 743
 		}
746 744
 
747
-		if ( $needsPrefixes ) {
748
-			$query = $this->prefixes . $query;
745
+		if ($needsPrefixes) {
746
+			$query = $this->prefixes.$query;
749 747
 		}
750
-		$query = "#wbqc\n" . $query;
748
+		$query = "#wbqc\n".$query;
751 749
 
752
-		$url = $endpoint . '?' . http_build_query(
750
+		$url = $endpoint.'?'.http_build_query(
753 751
 			[
754 752
 				'query' => $query,
755 753
 				'format' => 'json',
756 754
 				'maxQueryTimeMillis' => $this->maxQueryTimeMillis,
757 755
 			],
758
-			'', ini_get( 'arg_separator.output' ),
756
+			'', ini_get('arg_separator.output'),
759 757
 			// encode spaces with %20, not +
760 758
 			PHP_QUERY_RFC3986
761 759
 		);
762 760
 
763 761
 		$options = [
764 762
 			'method' => 'GET',
765
-			'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ),
763
+			'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000),
766 764
 			'connectTimeout' => 'default',
767 765
 			'userAgent' => $this->defaultUserAgent,
768 766
 		];
769
-		$request = $this->requestFactory->create( $url, $options, __METHOD__ );
770
-		$startTime = microtime( true );
767
+		$request = $this->requestFactory->create($url, $options, __METHOD__);
768
+		$startTime = microtime(true);
771 769
 		$requestStatus = $request->execute();
772
-		$endTime = microtime( true );
770
+		$endTime = microtime(true);
773 771
 		$this->dataFactory->timing(
774 772
 			'wikibase.quality.constraints.sparql.timing',
775
-			( $endTime - $startTime ) * 1000
773
+			($endTime - $startTime) * 1000
776 774
 		);
777 775
 
778
-		$this->guardAgainstTooManyRequestsError( $request );
776
+		$this->guardAgainstTooManyRequestsError($request);
779 777
 
780
-		$maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() );
781
-		if ( $maxAge ) {
782
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' );
778
+		$maxAge = $this->getCacheMaxAge($request->getResponseHeaders());
779
+		if ($maxAge) {
780
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.cached');
783 781
 		}
784 782
 
785
-		if ( $requestStatus->isOK() ) {
783
+		if ($requestStatus->isOK()) {
786 784
 			$json = $request->getContent();
787
-			$jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC );
788
-			if ( $jsonStatus->isOK() ) {
785
+			$jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC);
786
+			if ($jsonStatus->isOK()) {
789 787
 				return new CachedQueryResults(
790 788
 					$jsonStatus->getValue(),
791 789
 					Metadata::ofCachingMetadata(
792 790
 						$maxAge ?
793
-							CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) :
794
-							CachingMetadata::fresh()
791
+							CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh()
795 792
 					)
796 793
 				);
797 794
 			} else {
@@ -808,9 +805,9 @@  discard block
 block discarded – undo
808 805
 			// fall through to general error handling
809 806
 		}
810 807
 
811
-		$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' );
808
+		$this->dataFactory->increment('wikibase.quality.constraints.sparql.error');
812 809
 
813
-		if ( $this->isTimeout( $request->getContent() ) ) {
810
+		if ($this->isTimeout($request->getContent())) {
814 811
 			$this->dataFactory->increment(
815 812
 				'wikibase.quality.constraints.sparql.error.timeout'
816 813
 			);
@@ -825,29 +822,29 @@  discard block
 block discarded – undo
825 822
 	 * @param MWHttpRequest $request
826 823
 	 * @throws TooManySparqlRequestsException
827 824
 	 */
828
-	private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void {
829
-		if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) {
825
+	private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void {
826
+		if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) {
830 827
 			return;
831 828
 		}
832 829
 
833 830
 		$fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration;
834 831
 
835
-		if ( $fallbackBlockDuration < 0 ) {
836
-			throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' .
837
-				$fallbackBlockDuration );
832
+		if ($fallbackBlockDuration < 0) {
833
+			throw new InvalidArgumentException('Fallback duration must be positive int but is: '.
834
+				$fallbackBlockDuration);
838 835
 		}
839 836
 
840
-		$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
841
-		$throttlingUntil = $this->getThrottling( $request );
842
-		if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) {
843
-			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request );
837
+		$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
838
+		$throttlingUntil = $this->getThrottling($request);
839
+		if (!($throttlingUntil instanceof ConvertibleTimestamp)) {
840
+			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request);
844 841
 			$this->throttlingLock->lock(
845 842
 				self::EXPIRY_LOCK_ID,
846
-				$this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) )
843
+				$this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S'))
847 844
 			);
848 845
 		} else {
849
-			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request );
850
-			$this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil );
846
+			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request);
847
+			$this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil);
851 848
 		}
852 849
 		throw new TooManySparqlRequestsException();
853 850
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/DummySparqlHelper.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper;
6 6
 
@@ -28,15 +28,15 @@  discard block
 block discarded – undo
28 28
 		// no parent::__construct() call
29 29
 	}
30 30
 
31
-	public function hasType( string $id, array $classes ): CachedBool {
32
-		throw new LogicException( 'methods of this class should never be called' );
31
+	public function hasType(string $id, array $classes): CachedBool {
32
+		throw new LogicException('methods of this class should never be called');
33 33
 	}
34 34
 
35 35
 	public function findEntitiesWithSameStatement(
36 36
 		Statement $statement,
37 37
 		array $separators
38 38
 	): CachedEntityIds {
39
-		throw new LogicException( 'methods of this class should never be called' );
39
+		throw new LogicException('methods of this class should never be called');
40 40
 	}
41 41
 
42 42
 	public function findEntitiesWithSameQualifierOrReference(
@@ -45,15 +45,15 @@  discard block
 block discarded – undo
45 45
 		string $type,
46 46
 		bool $ignoreDeprecatedStatements
47 47
 	): CachedEntityIds {
48
-		throw new LogicException( 'methods of this class should never be called' );
48
+		throw new LogicException('methods of this class should never be called');
49 49
 	}
50 50
 
51
-	public function matchesRegularExpression( string $text, string $regex ): bool {
52
-		throw new LogicException( 'methods of this class should never be called' );
51
+	public function matchesRegularExpression(string $text, string $regex): bool {
52
+		throw new LogicException('methods of this class should never be called');
53 53
 	}
54 54
 
55
-	public function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults {
56
-		throw new LogicException( 'methods of this class should never be called' );
55
+	public function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults {
56
+		throw new LogicException('methods of this class should never be called');
57 57
 	}
58 58
 
59 59
 }
Please login to merge, or discard this patch.
src/WikibaseQualityConstraintsSchemaHooks.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@
 block discarded – undo
15 15
 	/**
16 16
 	 * @param DatabaseUpdater $updater
17 17
 	 */
18
-	public function onLoadExtensionSchemaUpdates( $updater ) {
19
-		$dir = dirname( __DIR__ ) . '/sql/';
18
+	public function onLoadExtensionSchemaUpdates($updater) {
19
+		$dir = dirname(__DIR__).'/sql/';
20 20
 
21 21
 		$updater->addExtensionTable(
22 22
 			'wbqc_constraints',
23
-			$dir . "/{$updater->getDB()->getType()}/tables-generated.sql"
23
+			$dir."/{$updater->getDB()->getType()}/tables-generated.sql"
24 24
 		);
25 25
 	}
26 26
 
Please login to merge, or discard this patch.