Completed
Push — master ( aa4c74...3cf82e )
by
unknown
40s
created
src/ConstraintCheck/Helper/LoggingHelper.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
 		$this->dataFactory = $dataFactory;
54 54
 		$this->logger = $logger;
55 55
 		$this->constraintCheckDurationLimits = [
56
-			'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ),
57
-			'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ),
56
+			'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'),
57
+			'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'),
58 58
 		];
59 59
 		$this->constraintCheckOnEntityDurationLimits = [
60
-			'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ),
61
-			'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ),
60
+			'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'),
61
+			'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'),
62 62
 		];
63 63
 	}
64 64
 
@@ -69,23 +69,23 @@  discard block
 block discarded – undo
69 69
 	 * @param float $durationSeconds
70 70
 	 * @return array [ $limitSeconds, $logLevel ]
71 71
 	 */
72
-	private function findLimit( $limits, $durationSeconds ) {
72
+	private function findLimit($limits, $durationSeconds) {
73 73
 		$limitSeconds = null;
74 74
 		$logLevel = null;
75 75
 
76
-		foreach ( $limits as $level => $limit ) {
76
+		foreach ($limits as $level => $limit) {
77 77
 			if (
78 78
 				// duration exceeds this limit
79
-				isset( $limit ) && $durationSeconds > $limit &&
79
+				isset($limit) && $durationSeconds > $limit &&
80 80
 				// this limit is longer than previous longest limit
81
-				( $limitSeconds === null || $limit > $limitSeconds )
81
+				($limitSeconds === null || $limit > $limitSeconds)
82 82
 			) {
83 83
 				$limitSeconds = $limit;
84 84
 				$logLevel = $level;
85 85
 			}
86 86
 		}
87 87
 
88
-		return [ $limitSeconds, $logLevel ];
88
+		return [$limitSeconds, $logLevel];
89 89
 	}
90 90
 
91 91
 	/**
@@ -110,31 +110,31 @@  discard block
 block discarded – undo
110 110
 		$durationSeconds,
111 111
 		$method
112 112
 	) {
113
-		$constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 );
113
+		$constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1);
114 114
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
115 115
 
116 116
 		$this->dataFactory->timing(
117
-			'wikibase.quality.constraints.check.timing.' .
118
-				$constraintTypeItemId . '-' .
117
+			'wikibase.quality.constraints.check.timing.'.
118
+				$constraintTypeItemId.'-'.
119 119
 				$constraintCheckerClassShortName,
120 120
 			$durationSeconds * 1000
121 121
 		);
122 122
 
123 123
 		// find the longest limit (and associated log level) that the duration exceeds
124
-		list( $limitSeconds, $logLevel ) = $this->findLimit(
124
+		list($limitSeconds, $logLevel) = $this->findLimit(
125 125
 			$this->constraintCheckDurationLimits,
126 126
 			$durationSeconds
127 127
 		);
128
-		if ( $limitSeconds === null ) {
128
+		if ($limitSeconds === null) {
129 129
 			return;
130 130
 		}
131
-		if ( $context->getType() !== Context::TYPE_STATEMENT ) {
131
+		if ($context->getType() !== Context::TYPE_STATEMENT) {
132 132
 			// TODO log less details but still log something
133 133
 			return;
134 134
 		}
135 135
 
136 136
 		$resultMessage = $result->getMessage();
137
-		if ( $resultMessage !== null ) {
137
+		if ($resultMessage !== null) {
138 138
 			$resultMessageKey = $resultMessage->getMessageKey();
139 139
 		} else {
140 140
 			$resultMessageKey = null;
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 
143 143
 		$this->logger->log(
144 144
 			$logLevel,
145
-			'Constraint check with {constraintCheckerClassShortName} ' .
146
-			'took longer than {limitSeconds} second(s) ' .
145
+			'Constraint check with {constraintCheckerClassShortName} '.
146
+			'took longer than {limitSeconds} second(s) '.
147 147
 			'(duration: {durationSeconds} seconds).',
148 148
 			[
149 149
 				'method' => $method,
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 				'constraintId' => $constraint->getConstraintId(),
154 154
 				'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(),
155 155
 				'constraintTypeItemId' => $constraintTypeItemId,
156
-				'constraintParameters' => json_encode( $constraint->getConstraintParameters() ),
156
+				'constraintParameters' => json_encode($constraint->getConstraintParameters()),
157 157
 				'constraintCheckerClass' => $constraintCheckerClass,
158 158
 				'constraintCheckerClassShortName' => $constraintCheckerClassShortName,
159 159
 				'entityId' => $context->getEntity()->getId()->getSerialization(),
@@ -188,18 +188,18 @@  discard block
 block discarded – undo
188 188
 		);
189 189
 
190 190
 		// find the longest limit (and associated log level) that the duration exceeds
191
-		list( $limitSeconds, $logLevel ) = $this->findLimit(
191
+		list($limitSeconds, $logLevel) = $this->findLimit(
192 192
 			$this->constraintCheckOnEntityDurationLimits,
193 193
 			$durationSeconds
194 194
 		);
195
-		if ( $limitSeconds === null ) {
195
+		if ($limitSeconds === null) {
196 196
 			return;
197 197
 		}
198 198
 
199 199
 		$this->logger->log(
200 200
 			$logLevel,
201
-			'Full constraint check on {entityId} ' .
202
-			'took longer than {limitSeconds} second(s) ' .
201
+			'Full constraint check on {entityId} '.
202
+			'took longer than {limitSeconds} second(s) '.
203 203
 			'(duration: {durationSeconds} seconds).',
204 204
 			[
205 205
 				'method' => $method,
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @param EntityId $entityId
219 219
 	 */
220
-	public function logCheckConstraintsCacheHit( EntityId $entityId ) {
220
+	public function logCheckConstraintsCacheHit(EntityId $entityId) {
221 221
 		$this->dataFactory->increment(
222 222
 			'wikibase.quality.constraints.cache.entity.hit'
223 223
 		);
@@ -228,10 +228,10 @@  discard block
 block discarded – undo
228 228
 	 *
229 229
 	 * @param EntityId[] $entityIds
230 230
 	 */
231
-	public function logCheckConstraintsCacheMisses( array $entityIds ) {
231
+	public function logCheckConstraintsCacheMisses(array $entityIds) {
232 232
 		$this->dataFactory->updateCount(
233 233
 			'wikibase.quality.constraints.cache.entity.miss',
234
-			count( $entityIds )
234
+			count($entityIds)
235 235
 		);
236 236
 	}
237 237
 
@@ -258,17 +258,17 @@  discard block
 block discarded – undo
258 258
 	 * @param EntityId[] $entityIds
259 259
 	 * @param int $maxRevisionIds
260 260
 	 */
261
-	public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) {
261
+	public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) {
262 262
 		$this->logger->log(
263 263
 			'warning',
264
-			'Dependency metadata for constraint check result has huge set of entity IDs ' .
265
-			'(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' .
264
+			'Dependency metadata for constraint check result has huge set of entity IDs '.
265
+			'(count '.count($entityIds).', limit '.$maxRevisionIds.'); '.
266 266
 			'caching disabled for this check result.',
267 267
 			[
268 268
 				'loggingMethod' => __METHOD__,
269 269
 				'entityIds' => json_encode(
270 270
 					array_map(
271
-						static function ( EntityId $entityId ) {
271
+						static function(EntityId $entityId) {
272 272
 							return $entityId->getSerialization();
273 273
 						},
274 274
 						$entityIds
@@ -287,17 +287,17 @@  discard block
 block discarded – undo
287 287
 			'Sparql API replied with status 429 and a retry-after header. Requesting to retry after {retryAfterTime}',
288 288
 			[
289 289
 				'retryAfterTime' => $retryAfterTime,
290
-				'responseHeaders' => json_encode( $request->getResponseHeaders() ),
290
+				'responseHeaders' => json_encode($request->getResponseHeaders()),
291 291
 				'responseContent' => $request->getContent(),
292 292
 			]
293 293
 		);
294 294
 	}
295 295
 
296
-	public function logSparqlHelperTooManyRequestsRetryAfterInvalid( MWHttpRequest $request ) {
296
+	public function logSparqlHelperTooManyRequestsRetryAfterInvalid(MWHttpRequest $request) {
297 297
 		$this->logger->warning(
298 298
 			'Sparql API replied with status 429 and no valid retry-after header.',
299 299
 			[
300
-				'responseHeaders' => json_encode( $request->getResponseHeaders() ),
300
+				'responseHeaders' => json_encode($request->getResponseHeaders()),
301 301
 				'responseContent' => $request->getContent(),
302 302
 			]
303 303
 		);
Please login to merge, or discard this patch.
src/ConstraintCheck/DelegatingConstraintChecker.php 1 patch
Spacing   +169 added lines, -169 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,25 +201,25 @@  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 function ( $resultStatus ) {
206
+			static function($resultStatus) {
207 207
 				return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE;
208 208
 			}
209
-		) );
209
+		));
210 210
 	}
211 211
 
212
-	private function getValidEntityTypes( Constraint $constraint ): array {
213
-		if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
214
-			return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED );
212
+	private function getValidEntityTypes(Constraint $constraint): array {
213
+		if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
214
+			return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED);
215 215
 		}
216 216
 
217
-		return array_keys( array_filter(
217
+		return array_keys(array_filter(
218 218
 			$this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(),
219
-			static function ( $resultStatus ) {
219
+			static function($resultStatus) {
220 220
 				return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE;
221 221
 			}
222
-		) );
222
+		));
223 223
 	}
224 224
 
225 225
 	/**
@@ -230,38 +230,38 @@  discard block
 block discarded – undo
230 230
 	 *
231 231
 	 * @return ConstraintParameterException[]
232 232
 	 */
233
-	private function checkCommonConstraintParameters( Constraint $constraint ): array {
233
+	private function checkCommonConstraintParameters(Constraint $constraint): array {
234 234
 		$constraintParameters = $constraint->getConstraintParameters();
235 235
 		try {
236
-			$this->constraintParameterParser->checkError( $constraintParameters );
237
-		} catch ( ConstraintParameterException $e ) {
238
-			return [ $e ];
236
+			$this->constraintParameterParser->checkError($constraintParameters);
237
+		} catch (ConstraintParameterException $e) {
238
+			return [$e];
239 239
 		}
240 240
 
241 241
 		$problems = [];
242 242
 		try {
243
-			$this->constraintParameterParser->parseExceptionParameter( $constraintParameters );
244
-		} catch ( ConstraintParameterException $e ) {
243
+			$this->constraintParameterParser->parseExceptionParameter($constraintParameters);
244
+		} catch (ConstraintParameterException $e) {
245 245
 			$problems[] = $e;
246 246
 		}
247 247
 		try {
248
-			$this->constraintParameterParser->parseConstraintClarificationParameter( $constraintParameters );
249
-		} catch ( ConstraintParameterException $e ) {
248
+			$this->constraintParameterParser->parseConstraintClarificationParameter($constraintParameters);
249
+		} catch (ConstraintParameterException $e) {
250 250
 			$problems[] = $e;
251 251
 		}
252 252
 		try {
253
-			$this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters );
254
-		} catch ( ConstraintParameterException $e ) {
253
+			$this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters);
254
+		} catch (ConstraintParameterException $e) {
255 255
 			$problems[] = $e;
256 256
 		}
257 257
 		try {
258 258
 			$this->constraintParameterParser->parseConstraintScopeParameters(
259 259
 				$constraintParameters,
260 260
 				$constraint->getConstraintTypeItemId(),
261
-				$this->getValidContextTypes( $constraint ),
262
-				$this->getValidEntityTypes( $constraint )
261
+				$this->getValidContextTypes($constraint),
262
+				$this->getValidEntityTypes($constraint)
263 263
 			);
264
-		} catch ( ConstraintParameterException $e ) {
264
+		} catch (ConstraintParameterException $e) {
265 265
 			$problems[] = $e;
266 266
 		}
267 267
 		return $problems;
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
 	 * @return ConstraintParameterException[][] first level indexed by constraint ID,
275 275
 	 * second level like checkConstraintParametersOnConstraintId (but without possibility of null)
276 276
 	 */
277
-	public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ): array {
278
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
277
+	public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId): array {
278
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
279 279
 		$result = [];
280 280
 
281
-		foreach ( $constraints as $constraint ) {
282
-			$problems = $this->checkCommonConstraintParameters( $constraint );
281
+		foreach ($constraints as $constraint) {
282
+			$problems = $this->checkCommonConstraintParameters($constraint);
283 283
 
284
-			if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
284
+			if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
285 285
 				$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
286
-				$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
286
+				$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
287 287
 			}
288 288
 
289 289
 			$result[$constraint->getConstraintId()] = $problems;
@@ -300,18 +300,18 @@  discard block
 block discarded – undo
300 300
 	 * @return ConstraintParameterException[]|null list of constraint parameter exceptions
301 301
 	 * (empty means all parameters okay), or null if constraint is not found
302 302
 	 */
303
-	public function checkConstraintParametersOnConstraintId( string $constraintId ): ?array {
304
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
303
+	public function checkConstraintParametersOnConstraintId(string $constraintId): ?array {
304
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
305 305
 		'@phan-var NumericPropertyId $propertyId';
306
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
306
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
307 307
 
308
-		foreach ( $constraints as $constraint ) {
309
-			if ( $constraint->getConstraintId() === $constraintId ) {
310
-				$problems = $this->checkCommonConstraintParameters( $constraint );
308
+		foreach ($constraints as $constraint) {
309
+			if ($constraint->getConstraintId() === $constraintId) {
310
+				$problems = $this->checkCommonConstraintParameters($constraint);
311 311
 
312
-				if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
312
+				if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
313 313
 					$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
314
-					$problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) );
314
+					$problems = array_merge($problems, $checker->checkConstraintParameters($constraint));
315 315
 				}
316 316
 
317 317
 				return $problems;
@@ -336,14 +336,14 @@  discard block
 block discarded – undo
336 336
 		$result = [];
337 337
 
338 338
 		/** @var Statement $statement */
339
-		foreach ( $entity->getStatements() as $statement ) {
340
-			$result = array_merge( $result,
339
+		foreach ($entity->getStatements() as $statement) {
340
+			$result = array_merge($result,
341 341
 				$this->checkStatement(
342 342
 					$entity,
343 343
 					$statement,
344 344
 					$constraintIds,
345 345
 					$defaultResultsPerContext
346
-				) );
346
+				));
347 347
 		}
348 348
 
349 349
 		return $result;
@@ -365,32 +365,32 @@  discard block
 block discarded – undo
365 365
 	): array {
366 366
 		$result = [];
367 367
 
368
-		$result = array_merge( $result,
368
+		$result = array_merge($result,
369 369
 			$this->checkConstraintsForMainSnak(
370 370
 				$entity,
371 371
 				$statement,
372 372
 				$constraintIds,
373 373
 				$defaultResultsPerContext
374
-			) );
374
+			));
375 375
 
376
-		if ( $this->checkQualifiers ) {
377
-			$result = array_merge( $result,
376
+		if ($this->checkQualifiers) {
377
+			$result = array_merge($result,
378 378
 				$this->checkConstraintsForQualifiers(
379 379
 					$entity,
380 380
 					$statement,
381 381
 					$constraintIds,
382 382
 					$defaultResultsPerContext
383
-				) );
383
+				));
384 384
 		}
385 385
 
386
-		if ( $this->checkReferences ) {
387
-			$result = array_merge( $result,
386
+		if ($this->checkReferences) {
387
+			$result = array_merge($result,
388 388
 				$this->checkConstraintsForReferences(
389 389
 					$entity,
390 390
 					$statement,
391 391
 					$constraintIds,
392 392
 					$defaultResultsPerContext
393
-				) );
393
+				));
394 394
 		}
395 395
 
396 396
 		return $result;
@@ -405,17 +405,17 @@  discard block
 block discarded – undo
405 405
 	 * @param string[]|null $constraintIds
406 406
 	 * @return Constraint[]
407 407
 	 */
408
-	private function getConstraintsToUse( PropertyId $propertyId, ?array $constraintIds ): array {
409
-		if ( !( $propertyId instanceof NumericPropertyId ) ) {
408
+	private function getConstraintsToUse(PropertyId $propertyId, ?array $constraintIds): array {
409
+		if (!($propertyId instanceof NumericPropertyId)) {
410 410
 			throw new InvalidArgumentException(
411
-				'Non-numeric property ID not supported:' . $propertyId->getSerialization()
411
+				'Non-numeric property ID not supported:'.$propertyId->getSerialization()
412 412
 			);
413 413
 		}
414
-		$constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId );
415
-		if ( $constraintIds !== null ) {
414
+		$constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId);
415
+		if ($constraintIds !== null) {
416 416
 			$constraintsToUse = [];
417
-			foreach ( $constraints as $constraint ) {
418
-				if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) {
417
+			foreach ($constraints as $constraint) {
418
+				if (in_array($constraint->getConstraintId(), $constraintIds)) {
419 419
 					$constraintsToUse[] = $constraint;
420 420
 				}
421 421
 			}
@@ -439,18 +439,18 @@  discard block
 block discarded – undo
439 439
 		?array $constraintIds,
440 440
 		?callable $defaultResults
441 441
 	): array {
442
-		$context = new MainSnakContext( $entity, $statement );
442
+		$context = new MainSnakContext($entity, $statement);
443 443
 		$constraints = $this->getConstraintsToUse(
444 444
 			$statement->getPropertyId(),
445 445
 			$constraintIds
446 446
 		);
447
-		$result = $defaultResults !== null ? $defaultResults( $context ) : [];
447
+		$result = $defaultResults !== null ? $defaultResults($context) : [];
448 448
 
449
-		foreach ( $constraints as $constraint ) {
449
+		foreach ($constraints as $constraint) {
450 450
 			$parameters = $constraint->getConstraintParameters();
451 451
 			try {
452
-				$exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters );
453
-			} catch ( ConstraintParameterException $e ) {
452
+				$exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters);
453
+			} catch (ConstraintParameterException $e) {
454 454
 				$result[] = new CheckResult(
455 455
 					$context,
456 456
 					$constraint,
@@ -460,13 +460,13 @@  discard block
 block discarded – undo
460 460
 				continue;
461 461
 			}
462 462
 
463
-			if ( in_array( $entity->getId(), $exceptions ) ) {
464
-				$message = new ViolationMessage( 'wbqc-violation-message-exception' );
465
-				$result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message );
463
+			if (in_array($entity->getId(), $exceptions)) {
464
+				$message = new ViolationMessage('wbqc-violation-message-exception');
465
+				$result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message);
466 466
 				continue;
467 467
 			}
468 468
 
469
-			$result[] = $this->getCheckResultFor( $context, $constraint );
469
+			$result[] = $this->getCheckResultFor($context, $constraint);
470 470
 		}
471 471
 
472 472
 		return $result;
@@ -488,24 +488,24 @@  discard block
 block discarded – undo
488 488
 	): array {
489 489
 		$result = [];
490 490
 
491
-		if ( in_array(
491
+		if (in_array(
492 492
 			$statement->getPropertyId()->getSerialization(),
493 493
 			$this->propertiesWithViolatingQualifiers
494
-		) ) {
494
+		)) {
495 495
 			return $result;
496 496
 		}
497 497
 
498
-		foreach ( $statement->getQualifiers() as $qualifier ) {
499
-			$qualifierContext = new QualifierContext( $entity, $statement, $qualifier );
500
-			if ( $defaultResultsPerContext !== null ) {
501
-				$result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) );
498
+		foreach ($statement->getQualifiers() as $qualifier) {
499
+			$qualifierContext = new QualifierContext($entity, $statement, $qualifier);
500
+			if ($defaultResultsPerContext !== null) {
501
+				$result = array_merge($result, $defaultResultsPerContext($qualifierContext));
502 502
 			}
503 503
 			$qualifierConstraints = $this->getConstraintsToUse(
504 504
 				$qualifierContext->getSnak()->getPropertyId(),
505 505
 				$constraintIds
506 506
 			);
507
-			foreach ( $qualifierConstraints as $qualifierConstraint ) {
508
-				$result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint );
507
+			foreach ($qualifierConstraints as $qualifierConstraint) {
508
+				$result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint);
509 509
 			}
510 510
 		}
511 511
 
@@ -529,19 +529,19 @@  discard block
 block discarded – undo
529 529
 		$result = [];
530 530
 
531 531
 		/** @var Reference $reference */
532
-		foreach ( $statement->getReferences() as $reference ) {
533
-			foreach ( $reference->getSnaks() as $snak ) {
532
+		foreach ($statement->getReferences() as $reference) {
533
+			foreach ($reference->getSnaks() as $snak) {
534 534
 				$referenceContext = new ReferenceContext(
535 535
 					$entity, $statement, $reference, $snak
536 536
 				);
537
-				if ( $defaultResultsPerContext !== null ) {
538
-					$result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) );
537
+				if ($defaultResultsPerContext !== null) {
538
+					$result = array_merge($result, $defaultResultsPerContext($referenceContext));
539 539
 				}
540 540
 				$referenceConstraints = $this->getConstraintsToUse(
541 541
 					$referenceContext->getSnak()->getPropertyId(),
542 542
 					$constraintIds
543 543
 				);
544
-				foreach ( $referenceConstraints as $referenceConstraint ) {
544
+				foreach ($referenceConstraints as $referenceConstraint) {
545 545
 					$result[] = $this->getCheckResultFor(
546 546
 						$referenceContext,
547 547
 						$referenceConstraint
@@ -553,20 +553,20 @@  discard block
 block discarded – undo
553 553
 		return $result;
554 554
 	}
555 555
 
556
-	private function getCheckResultFor( Context $context, Constraint $constraint ): CheckResult {
557
-		if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) {
556
+	private function getCheckResultFor(Context $context, Constraint $constraint): CheckResult {
557
+		if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) {
558 558
 			$checker = $this->checkerMap[$constraint->getConstraintTypeItemId()];
559
-			$result = $this->handleScope( $checker, $context, $constraint );
559
+			$result = $this->handleScope($checker, $context, $constraint);
560 560
 
561
-			if ( $result !== null ) {
562
-				$this->addMetadata( $context, $result );
561
+			if ($result !== null) {
562
+				$this->addMetadata($context, $result);
563 563
 				return $result;
564 564
 			}
565 565
 
566
-			$startTime = microtime( true );
566
+			$startTime = microtime(true);
567 567
 			try {
568
-				$result = $checker->checkConstraint( $context, $constraint );
569
-			} catch ( ConstraintParameterException $e ) {
568
+				$result = $checker->checkConstraint($context, $constraint);
569
+			} catch (ConstraintParameterException $e) {
570 570
 				$result = new CheckResult(
571 571
 					$context,
572 572
 					$constraint,
@@ -574,30 +574,30 @@  discard block
 block discarded – undo
574 574
 					CheckResult::STATUS_BAD_PARAMETERS,
575 575
 					$e->getViolationMessage()
576 576
 				);
577
-			} catch ( SparqlHelperException $e ) {
578
-				$message = new ViolationMessage( 'wbqc-violation-message-sparql-error' );
579
-				$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message );
577
+			} catch (SparqlHelperException $e) {
578
+				$message = new ViolationMessage('wbqc-violation-message-sparql-error');
579
+				$result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message);
580 580
 			}
581
-			$endTime = microtime( true );
581
+			$endTime = microtime(true);
582 582
 
583
-			$this->addMetadata( $context, $result );
583
+			$this->addMetadata($context, $result);
584 584
 
585
-			$this->addConstraintClarification( $result );
585
+			$this->addConstraintClarification($result);
586 586
 
587
-			$this->downgradeResultStatus( $result );
587
+			$this->downgradeResultStatus($result);
588 588
 
589 589
 			$this->loggingHelper->logConstraintCheck(
590 590
 				$context,
591 591
 				$constraint,
592 592
 				$result,
593
-				get_class( $checker ),
593
+				get_class($checker),
594 594
 				$endTime - $startTime,
595 595
 				__METHOD__
596 596
 			);
597 597
 
598 598
 			return $result;
599 599
 		} else {
600
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
600
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
601 601
 		}
602 602
 	}
603 603
 
@@ -606,91 +606,91 @@  discard block
 block discarded – undo
606 606
 		Context $context,
607 607
 		Constraint $constraint
608 608
 	): ?CheckResult {
609
-		$validContextTypes = $this->getValidContextTypes( $constraint );
610
-		$validEntityTypes = $this->getValidEntityTypes( $constraint );
609
+		$validContextTypes = $this->getValidContextTypes($constraint);
610
+		$validEntityTypes = $this->getValidEntityTypes($constraint);
611 611
 		try {
612
-			[ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters(
612
+			[$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters(
613 613
 				$constraint->getConstraintParameters(),
614 614
 				$constraint->getConstraintTypeItemId(),
615 615
 				$validContextTypes,
616 616
 				$validEntityTypes
617 617
 			);
618
-		} catch ( ConstraintParameterException $e ) {
619
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
618
+		} catch (ConstraintParameterException $e) {
619
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage());
620 620
 		}
621 621
 
622
-		if ( $checkedContextTypes === null ) {
622
+		if ($checkedContextTypes === null) {
623 623
 			$checkedContextTypes = $checker->getDefaultContextTypes();
624 624
 		}
625 625
 		$contextType = $context->getType();
626
-		if ( !in_array( $contextType, $checkedContextTypes ) ) {
627
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null );
626
+		if (!in_array($contextType, $checkedContextTypes)) {
627
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null);
628 628
 		}
629
-		if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) {
630
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
629
+		if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) {
630
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
631 631
 		}
632 632
 
633
-		if ( $checkedEntityTypes === null ) {
633
+		if ($checkedEntityTypes === null) {
634 634
 			$checkedEntityTypes = $validEntityTypes;
635 635
 		}
636 636
 		$entityType = $context->getEntity()->getType();
637
-		if ( !in_array( $entityType, $checkedEntityTypes ) ) {
638
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null );
637
+		if (!in_array($entityType, $checkedEntityTypes)) {
638
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null);
639 639
 		}
640
-		if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) {
641
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null );
640
+		if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) {
641
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null);
642 642
 		}
643 643
 
644 644
 		return null;
645 645
 	}
646 646
 
647
-	private function addMetadata( Context $context, CheckResult $result ): void {
648
-		$result->withMetadata( Metadata::merge( [
647
+	private function addMetadata(Context $context, CheckResult $result): void {
648
+		$result->withMetadata(Metadata::merge([
649 649
 			$result->getMetadata(),
650
-			Metadata::ofDependencyMetadata( DependencyMetadata::merge( [
651
-				DependencyMetadata::ofEntityId( $context->getEntity()->getId() ),
652
-				DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ),
653
-			] ) ),
654
-		] ) );
650
+			Metadata::ofDependencyMetadata(DependencyMetadata::merge([
651
+				DependencyMetadata::ofEntityId($context->getEntity()->getId()),
652
+				DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()),
653
+			])),
654
+		]));
655 655
 	}
656 656
 
657
-	private function addConstraintClarification( CheckResult $result ): void {
657
+	private function addConstraintClarification(CheckResult $result): void {
658 658
 		$constraint = $result->getConstraint();
659 659
 		try {
660 660
 			$constraintClarification = $this->constraintParameterParser
661
-				->parseConstraintClarificationParameter( $constraint->getConstraintParameters() );
662
-			$result->setConstraintClarification( $constraintClarification );
663
-		} catch ( ConstraintParameterException $e ) {
664
-			$result->setStatus( CheckResult::STATUS_BAD_PARAMETERS );
665
-			$result->setMessage( $e->getViolationMessage() );
661
+				->parseConstraintClarificationParameter($constraint->getConstraintParameters());
662
+			$result->setConstraintClarification($constraintClarification);
663
+		} catch (ConstraintParameterException $e) {
664
+			$result->setStatus(CheckResult::STATUS_BAD_PARAMETERS);
665
+			$result->setMessage($e->getViolationMessage());
666 666
 		}
667 667
 	}
668 668
 
669
-	private function downgradeResultStatus( CheckResult $result ): void {
669
+	private function downgradeResultStatus(CheckResult $result): void {
670 670
 		$constraint = $result->getConstraint();
671 671
 		try {
672 672
 			$constraintStatus = $this->constraintParameterParser
673
-				->parseConstraintStatusParameter( $constraint->getConstraintParameters() );
674
-		} catch ( ConstraintParameterException $e ) {
675
-			$result->setStatus( CheckResult::STATUS_BAD_PARAMETERS );
676
-			$result->setMessage( $e->getViolationMessage() );
673
+				->parseConstraintStatusParameter($constraint->getConstraintParameters());
674
+		} catch (ConstraintParameterException $e) {
675
+			$result->setStatus(CheckResult::STATUS_BAD_PARAMETERS);
676
+			$result->setMessage($e->getViolationMessage());
677 677
 			return;
678 678
 		}
679
-		if ( $constraintStatus === null ) {
679
+		if ($constraintStatus === null) {
680 680
 			// downgrade violation to warning
681
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
682
-				$result->setStatus( CheckResult::STATUS_WARNING );
681
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
682
+				$result->setStatus(CheckResult::STATUS_WARNING);
683 683
 			}
684
-		} elseif ( $constraintStatus === 'suggestion' ) {
684
+		} elseif ($constraintStatus === 'suggestion') {
685 685
 			// downgrade violation to suggestion
686
-			if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) {
687
-				$result->setStatus( CheckResult::STATUS_SUGGESTION );
686
+			if ($result->getStatus() === CheckResult::STATUS_VIOLATION) {
687
+				$result->setStatus(CheckResult::STATUS_SUGGESTION);
688 688
 			}
689 689
 		} else {
690
-			if ( $constraintStatus !== 'mandatory' ) {
690
+			if ($constraintStatus !== 'mandatory') {
691 691
 				// @codeCoverageIgnoreStart
692 692
 				throw new LogicException(
693
-					"Unknown constraint status '$constraintStatus', " .
693
+					"Unknown constraint status '$constraintStatus', ".
694 694
 					"only known statuses are 'mandatory' and 'suggestion'"
695 695
 				);
696 696
 				// @codeCoverageIgnoreEnd
@@ -703,12 +703,12 @@  discard block
 block discarded – undo
703 703
 	 *
704 704
 	 * @return CheckResult[]
705 705
 	 */
706
-	private function sortResult( array $result ): array {
707
-		if ( count( $result ) < 2 ) {
706
+	private function sortResult(array $result): array {
707
+		if (count($result) < 2) {
708 708
 			return $result;
709 709
 		}
710 710
 
711
-		$sortFunction = static function ( CheckResult $a, CheckResult $b ) {
711
+		$sortFunction = static function(CheckResult $a, CheckResult $b) {
712 712
 			$orderNum = 0;
713 713
 			$order = [
714 714
 				CheckResult::STATUS_BAD_PARAMETERS => $orderNum++,
@@ -725,55 +725,55 @@  discard block
 block discarded – undo
725 725
 			$statusA = $a->getStatus();
726 726
 			$statusB = $b->getStatus();
727 727
 
728
-			$orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ];
729
-			$orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ];
728
+			$orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other'];
729
+			$orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other'];
730 730
 
731
-			if ( $orderA === $orderB ) {
731
+			if ($orderA === $orderB) {
732 732
 				$cursorA = $a->getContextCursor();
733 733
 				$cursorB = $b->getContextCursor();
734 734
 
735
-				if ( $cursorA instanceof EntityContextCursor ) {
735
+				if ($cursorA instanceof EntityContextCursor) {
736 736
 					return $cursorB instanceof EntityContextCursor ? 0 : -1;
737 737
 				}
738
-				if ( $cursorB instanceof EntityContextCursor ) {
738
+				if ($cursorB instanceof EntityContextCursor) {
739 739
 					return $cursorA instanceof EntityContextCursor ? 0 : 1;
740 740
 				}
741 741
 
742 742
 				$pidA = $cursorA->getSnakPropertyId();
743 743
 				$pidB = $cursorB->getSnakPropertyId();
744 744
 
745
-				if ( $pidA === $pidB ) {
745
+				if ($pidA === $pidB) {
746 746
 					$hashA = $cursorA->getSnakHash();
747 747
 					$hashB = $cursorB->getSnakHash();
748 748
 
749
-					if ( $hashA === $hashB ) {
750
-						if ( $a instanceof NullResult ) {
749
+					if ($hashA === $hashB) {
750
+						if ($a instanceof NullResult) {
751 751
 							return $b instanceof NullResult ? 0 : -1;
752 752
 						}
753
-						if ( $b instanceof NullResult ) {
753
+						if ($b instanceof NullResult) {
754 754
 							return $a instanceof NullResult ? 0 : 1;
755 755
 						}
756 756
 
757 757
 						$typeA = $a->getConstraint()->getConstraintTypeItemId();
758 758
 						$typeB = $b->getConstraint()->getConstraintTypeItemId();
759 759
 
760
-						if ( $typeA == $typeB ) {
760
+						if ($typeA == $typeB) {
761 761
 							return 0;
762 762
 						} else {
763
-							return ( $typeA > $typeB ) ? 1 : -1;
763
+							return ($typeA > $typeB) ? 1 : -1;
764 764
 						}
765 765
 					} else {
766
-						return ( $hashA > $hashB ) ? 1 : -1;
766
+						return ($hashA > $hashB) ? 1 : -1;
767 767
 					}
768 768
 				} else {
769
-					return ( $pidA > $pidB ) ? 1 : -1;
769
+					return ($pidA > $pidB) ? 1 : -1;
770 770
 				}
771 771
 			} else {
772
-				return ( $orderA > $orderB ) ? 1 : -1;
772
+				return ($orderA > $orderB) ? 1 : -1;
773 773
 			}
774 774
 		};
775 775
 
776
-		uasort( $result, $sortFunction );
776
+		uasort($result, $sortFunction);
777 777
 
778 778
 		return $result;
779 779
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Result/CheckResult.php 1 patch
Spacing   +8 added lines, -8 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\Result;
6 6
 
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 		string $status = self::STATUS_TODO,
111 111
 		ViolationMessage $message = null
112 112
 	) {
113
-		if ( $contextCursor instanceof Context ) {
113
+		if ($contextCursor instanceof Context) {
114 114
 			$context = $contextCursor;
115 115
 			$this->contextCursor = $context->getCursor();
116 116
 			$this->snakType = $context->getSnak()->getType();
117 117
 			$mainSnak = $context->getSnak();
118
-			if ( $mainSnak instanceof PropertyValueSnak ) {
118
+			if ($mainSnak instanceof PropertyValueSnak) {
119 119
 				$this->dataValue = $mainSnak->getDataValue();
120 120
 			} else {
121 121
 				$this->dataValue = null;
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$this->status = $status;
130 130
 		$this->message = $message;
131 131
 		$this->metadata = Metadata::blank();
132
-		$this->constraintClarification = new MultilingualTextValue( [] );
132
+		$this->constraintClarification = new MultilingualTextValue([]);
133 133
 	}
134 134
 
135 135
 	public function getContextCursor(): ContextCursor {
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		return $this->status;
166 166
 	}
167 167
 
168
-	public function setStatus( string $status ): void {
168
+	public function setStatus(string $status): void {
169 169
 		$this->status = $status;
170 170
 	}
171 171
 
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
 		return $this->message;
174 174
 	}
175 175
 
176
-	public function setMessage( ?ViolationMessage $message ) {
176
+	public function setMessage(?ViolationMessage $message) {
177 177
 		$this->message = $message;
178 178
 	}
179 179
 
180
-	public function withMetadata( Metadata $metadata ): self {
180
+	public function withMetadata(Metadata $metadata): self {
181 181
 		$this->metadata = $metadata;
182 182
 		return $this;
183 183
 	}
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		return $this->constraintClarification;
191 191
 	}
192 192
 
193
-	public function setConstraintClarification( MultilingualTextValue $constraintClarification ) {
193
+	public function setConstraintClarification(MultilingualTextValue $constraintClarification) {
194 194
 		$this->constraintClarification = $constraintClarification;
195 195
 	}
196 196
 
Please login to merge, or discard this patch.