@@ -1,6 +1,6 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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,33 +230,33 @@ discard block |
||
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->parseConstraintStatusParameter( $constraintParameters ); |
|
249 | - } catch ( ConstraintParameterException $e ) { |
|
248 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
249 | + } catch (ConstraintParameterException $e) { |
|
250 | 250 | $problems[] = $e; |
251 | 251 | } |
252 | 252 | try { |
253 | 253 | $this->constraintParameterParser->parseConstraintScopeParameters( |
254 | 254 | $constraintParameters, |
255 | 255 | $constraint->getConstraintTypeItemId(), |
256 | - $this->getValidContextTypes( $constraint ), |
|
257 | - $this->getValidEntityTypes( $constraint ) |
|
256 | + $this->getValidContextTypes($constraint), |
|
257 | + $this->getValidEntityTypes($constraint) |
|
258 | 258 | ); |
259 | - } catch ( ConstraintParameterException $e ) { |
|
259 | + } catch (ConstraintParameterException $e) { |
|
260 | 260 | $problems[] = $e; |
261 | 261 | } |
262 | 262 | return $problems; |
@@ -269,16 +269,16 @@ discard block |
||
269 | 269 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
270 | 270 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
271 | 271 | */ |
272 | - public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ): array { |
|
273 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
272 | + public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId): array { |
|
273 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
274 | 274 | $result = []; |
275 | 275 | |
276 | - foreach ( $constraints as $constraint ) { |
|
277 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
276 | + foreach ($constraints as $constraint) { |
|
277 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
278 | 278 | |
279 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
279 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
280 | 280 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
281 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
281 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | $result[$constraint->getConstraintId()] = $problems; |
@@ -295,18 +295,18 @@ discard block |
||
295 | 295 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
296 | 296 | * (empty means all parameters okay), or null if constraint is not found |
297 | 297 | */ |
298 | - public function checkConstraintParametersOnConstraintId( string $constraintId ): ?array { |
|
299 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
298 | + public function checkConstraintParametersOnConstraintId(string $constraintId): ?array { |
|
299 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
300 | 300 | '@phan-var NumericPropertyId $propertyId'; |
301 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
301 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
302 | 302 | |
303 | - foreach ( $constraints as $constraint ) { |
|
304 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
305 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
303 | + foreach ($constraints as $constraint) { |
|
304 | + if ($constraint->getConstraintId() === $constraintId) { |
|
305 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
306 | 306 | |
307 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
307 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
308 | 308 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
309 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
309 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | return $problems; |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | $result = []; |
332 | 332 | |
333 | 333 | /** @var Statement $statement */ |
334 | - foreach ( $entity->getStatements() as $statement ) { |
|
335 | - $result = array_merge( $result, |
|
334 | + foreach ($entity->getStatements() as $statement) { |
|
335 | + $result = array_merge($result, |
|
336 | 336 | $this->checkStatement( |
337 | 337 | $entity, |
338 | 338 | $statement, |
339 | 339 | $constraintIds, |
340 | 340 | $defaultResultsPerContext |
341 | - ) ); |
|
341 | + )); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return $result; |
@@ -360,32 +360,32 @@ discard block |
||
360 | 360 | ): array { |
361 | 361 | $result = []; |
362 | 362 | |
363 | - $result = array_merge( $result, |
|
363 | + $result = array_merge($result, |
|
364 | 364 | $this->checkConstraintsForMainSnak( |
365 | 365 | $entity, |
366 | 366 | $statement, |
367 | 367 | $constraintIds, |
368 | 368 | $defaultResultsPerContext |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | |
371 | - if ( $this->checkQualifiers ) { |
|
372 | - $result = array_merge( $result, |
|
371 | + if ($this->checkQualifiers) { |
|
372 | + $result = array_merge($result, |
|
373 | 373 | $this->checkConstraintsForQualifiers( |
374 | 374 | $entity, |
375 | 375 | $statement, |
376 | 376 | $constraintIds, |
377 | 377 | $defaultResultsPerContext |
378 | - ) ); |
|
378 | + )); |
|
379 | 379 | } |
380 | 380 | |
381 | - if ( $this->checkReferences ) { |
|
382 | - $result = array_merge( $result, |
|
381 | + if ($this->checkReferences) { |
|
382 | + $result = array_merge($result, |
|
383 | 383 | $this->checkConstraintsForReferences( |
384 | 384 | $entity, |
385 | 385 | $statement, |
386 | 386 | $constraintIds, |
387 | 387 | $defaultResultsPerContext |
388 | - ) ); |
|
388 | + )); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | return $result; |
@@ -400,17 +400,17 @@ discard block |
||
400 | 400 | * @param string[]|null $constraintIds |
401 | 401 | * @return Constraint[] |
402 | 402 | */ |
403 | - private function getConstraintsToUse( PropertyId $propertyId, ?array $constraintIds ): array { |
|
404 | - if ( !( $propertyId instanceof NumericPropertyId ) ) { |
|
403 | + private function getConstraintsToUse(PropertyId $propertyId, ?array $constraintIds): array { |
|
404 | + if (!($propertyId instanceof NumericPropertyId)) { |
|
405 | 405 | throw new InvalidArgumentException( |
406 | - 'Non-numeric property ID not supported:' . $propertyId->getSerialization() |
|
406 | + 'Non-numeric property ID not supported:'.$propertyId->getSerialization() |
|
407 | 407 | ); |
408 | 408 | } |
409 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
410 | - if ( $constraintIds !== null ) { |
|
409 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
410 | + if ($constraintIds !== null) { |
|
411 | 411 | $constraintsToUse = []; |
412 | - foreach ( $constraints as $constraint ) { |
|
413 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
412 | + foreach ($constraints as $constraint) { |
|
413 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
414 | 414 | $constraintsToUse[] = $constraint; |
415 | 415 | } |
416 | 416 | } |
@@ -434,18 +434,18 @@ discard block |
||
434 | 434 | ?array $constraintIds, |
435 | 435 | ?callable $defaultResults |
436 | 436 | ): array { |
437 | - $context = new MainSnakContext( $entity, $statement ); |
|
437 | + $context = new MainSnakContext($entity, $statement); |
|
438 | 438 | $constraints = $this->getConstraintsToUse( |
439 | 439 | $statement->getPropertyId(), |
440 | 440 | $constraintIds |
441 | 441 | ); |
442 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
442 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
443 | 443 | |
444 | - foreach ( $constraints as $constraint ) { |
|
444 | + foreach ($constraints as $constraint) { |
|
445 | 445 | $parameters = $constraint->getConstraintParameters(); |
446 | 446 | try { |
447 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
448 | - } catch ( ConstraintParameterException $e ) { |
|
447 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
448 | + } catch (ConstraintParameterException $e) { |
|
449 | 449 | $result[] = new CheckResult( |
450 | 450 | $context, |
451 | 451 | $constraint, |
@@ -455,13 +455,13 @@ discard block |
||
455 | 455 | continue; |
456 | 456 | } |
457 | 457 | |
458 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
459 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
460 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
458 | + if (in_array($entity->getId(), $exceptions)) { |
|
459 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
460 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
461 | 461 | continue; |
462 | 462 | } |
463 | 463 | |
464 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
464 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | return $result; |
@@ -483,24 +483,24 @@ discard block |
||
483 | 483 | ): array { |
484 | 484 | $result = []; |
485 | 485 | |
486 | - if ( in_array( |
|
486 | + if (in_array( |
|
487 | 487 | $statement->getPropertyId()->getSerialization(), |
488 | 488 | $this->propertiesWithViolatingQualifiers |
489 | - ) ) { |
|
489 | + )) { |
|
490 | 490 | return $result; |
491 | 491 | } |
492 | 492 | |
493 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
494 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
495 | - if ( $defaultResultsPerContext !== null ) { |
|
496 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
493 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
494 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
495 | + if ($defaultResultsPerContext !== null) { |
|
496 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
497 | 497 | } |
498 | 498 | $qualifierConstraints = $this->getConstraintsToUse( |
499 | 499 | $qualifierContext->getSnak()->getPropertyId(), |
500 | 500 | $constraintIds |
501 | 501 | ); |
502 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
503 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
502 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
503 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
@@ -524,19 +524,19 @@ discard block |
||
524 | 524 | $result = []; |
525 | 525 | |
526 | 526 | /** @var Reference $reference */ |
527 | - foreach ( $statement->getReferences() as $reference ) { |
|
528 | - foreach ( $reference->getSnaks() as $snak ) { |
|
527 | + foreach ($statement->getReferences() as $reference) { |
|
528 | + foreach ($reference->getSnaks() as $snak) { |
|
529 | 529 | $referenceContext = new ReferenceContext( |
530 | 530 | $entity, $statement, $reference, $snak |
531 | 531 | ); |
532 | - if ( $defaultResultsPerContext !== null ) { |
|
533 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
532 | + if ($defaultResultsPerContext !== null) { |
|
533 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
534 | 534 | } |
535 | 535 | $referenceConstraints = $this->getConstraintsToUse( |
536 | 536 | $referenceContext->getSnak()->getPropertyId(), |
537 | 537 | $constraintIds |
538 | 538 | ); |
539 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
539 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
540 | 540 | $result[] = $this->getCheckResultFor( |
541 | 541 | $referenceContext, |
542 | 542 | $referenceConstraint |
@@ -548,20 +548,20 @@ discard block |
||
548 | 548 | return $result; |
549 | 549 | } |
550 | 550 | |
551 | - private function getCheckResultFor( Context $context, Constraint $constraint ): CheckResult { |
|
552 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
551 | + private function getCheckResultFor(Context $context, Constraint $constraint): CheckResult { |
|
552 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
553 | 553 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
554 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
554 | + $result = $this->handleScope($checker, $context, $constraint); |
|
555 | 555 | |
556 | - if ( $result !== null ) { |
|
557 | - $this->addMetadata( $context, $result ); |
|
556 | + if ($result !== null) { |
|
557 | + $this->addMetadata($context, $result); |
|
558 | 558 | return $result; |
559 | 559 | } |
560 | 560 | |
561 | - $startTime = microtime( true ); |
|
561 | + $startTime = microtime(true); |
|
562 | 562 | try { |
563 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
564 | - } catch ( ConstraintParameterException $e ) { |
|
563 | + $result = $checker->checkConstraint($context, $constraint); |
|
564 | + } catch (ConstraintParameterException $e) { |
|
565 | 565 | $result = new CheckResult( |
566 | 566 | $context, |
567 | 567 | $constraint, |
@@ -569,28 +569,28 @@ discard block |
||
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->downgradeResultStatus( $result ); |
|
580 | + $this->downgradeResultStatus($result); |
|
581 | 581 | |
582 | 582 | $this->loggingHelper->logConstraintCheck( |
583 | 583 | $context, |
584 | 584 | $constraint, |
585 | 585 | $result, |
586 | - get_class( $checker ), |
|
586 | + get_class($checker), |
|
587 | 587 | $endTime - $startTime, |
588 | 588 | __METHOD__ |
589 | 589 | ); |
590 | 590 | |
591 | 591 | return $result; |
592 | 592 | } else { |
593 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
593 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
594 | 594 | } |
595 | 595 | } |
596 | 596 | |
@@ -599,85 +599,85 @@ discard block |
||
599 | 599 | Context $context, |
600 | 600 | Constraint $constraint |
601 | 601 | ): ?CheckResult { |
602 | - $validContextTypes = $this->getValidContextTypes( $constraint ); |
|
603 | - $validEntityTypes = $this->getValidEntityTypes( $constraint ); |
|
602 | + $validContextTypes = $this->getValidContextTypes($constraint); |
|
603 | + $validEntityTypes = $this->getValidEntityTypes($constraint); |
|
604 | 604 | try { |
605 | - [ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
605 | + [$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
606 | 606 | $constraint->getConstraintParameters(), |
607 | 607 | $constraint->getConstraintTypeItemId(), |
608 | 608 | $validContextTypes, |
609 | 609 | $validEntityTypes |
610 | 610 | ); |
611 | - } catch ( ConstraintParameterException $e ) { |
|
612 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
611 | + } catch (ConstraintParameterException $e) { |
|
612 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
613 | 613 | } |
614 | 614 | |
615 | - if ( $checkedContextTypes === null ) { |
|
615 | + if ($checkedContextTypes === null) { |
|
616 | 616 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
617 | 617 | } |
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 | - if ( $checkedEntityTypes === null ) { |
|
626 | + if ($checkedEntityTypes === null) { |
|
627 | 627 | $checkedEntityTypes = $validEntityTypes; |
628 | 628 | } |
629 | 629 | $entityType = $context->getEntity()->getType(); |
630 | - if ( !in_array( $entityType, $checkedEntityTypes ) ) { |
|
631 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
630 | + if (!in_array($entityType, $checkedEntityTypes)) { |
|
631 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
632 | 632 | } |
633 | - if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) { |
|
634 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
633 | + if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) { |
|
634 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | return null; |
638 | 638 | } |
639 | 639 | |
640 | - private function addMetadata( Context $context, CheckResult $result ): void { |
|
641 | - $result->withMetadata( Metadata::merge( [ |
|
640 | + private function addMetadata(Context $context, CheckResult $result): void { |
|
641 | + $result->withMetadata(Metadata::merge([ |
|
642 | 642 | $result->getMetadata(), |
643 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
644 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
645 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
646 | - ] ) ), |
|
647 | - ] ) ); |
|
643 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
644 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
645 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
646 | + ])), |
|
647 | + ])); |
|
648 | 648 | } |
649 | 649 | |
650 | - private function downgradeResultStatus( CheckResult $result ): void { |
|
650 | + private function downgradeResultStatus(CheckResult $result): void { |
|
651 | 651 | $constraint = $result->getConstraint(); |
652 | 652 | try { |
653 | 653 | $constraintStatus = $this->constraintParameterParser |
654 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
655 | - } catch ( ConstraintParameterException $e ) { |
|
656 | - $result->setStatus( CheckResult::STATUS_BAD_PARAMETERS ); |
|
657 | - $result->setMessage( $e->getViolationMessage() ); |
|
654 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
655 | + } catch (ConstraintParameterException $e) { |
|
656 | + $result->setStatus(CheckResult::STATUS_BAD_PARAMETERS); |
|
657 | + $result->setMessage($e->getViolationMessage()); |
|
658 | 658 | return; |
659 | 659 | } |
660 | - if ( $constraintStatus === null ) { |
|
660 | + if ($constraintStatus === null) { |
|
661 | 661 | // downgrade violation to warning |
662 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
663 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
662 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
663 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
664 | 664 | } |
665 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
665 | + } elseif ($constraintStatus === 'suggestion') { |
|
666 | 666 | // downgrade violation to suggestion |
667 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
668 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
667 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
668 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
669 | 669 | } |
670 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
670 | + $result->addParameter('constraint_status', $constraintStatus); |
|
671 | 671 | } else { |
672 | - if ( $constraintStatus !== 'mandatory' ) { |
|
672 | + if ($constraintStatus !== 'mandatory') { |
|
673 | 673 | // @codeCoverageIgnoreStart |
674 | 674 | throw new LogicException( |
675 | - "Unknown constraint status '$constraintStatus', " . |
|
675 | + "Unknown constraint status '$constraintStatus', ". |
|
676 | 676 | "only known statuses are 'mandatory' and 'suggestion'" |
677 | 677 | ); |
678 | 678 | // @codeCoverageIgnoreEnd |
679 | 679 | } |
680 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
680 | + $result->addParameter('constraint_status', $constraintStatus); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 | |
@@ -686,12 +686,12 @@ discard block |
||
686 | 686 | * |
687 | 687 | * @return CheckResult[] |
688 | 688 | */ |
689 | - private function sortResult( array $result ): array { |
|
690 | - if ( count( $result ) < 2 ) { |
|
689 | + private function sortResult(array $result): array { |
|
690 | + if (count($result) < 2) { |
|
691 | 691 | return $result; |
692 | 692 | } |
693 | 693 | |
694 | - $sortFunction = static function ( CheckResult $a, CheckResult $b ) { |
|
694 | + $sortFunction = static function(CheckResult $a, CheckResult $b) { |
|
695 | 695 | $orderNum = 0; |
696 | 696 | $order = [ |
697 | 697 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -708,55 +708,55 @@ discard block |
||
708 | 708 | $statusA = $a->getStatus(); |
709 | 709 | $statusB = $b->getStatus(); |
710 | 710 | |
711 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
712 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
711 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
712 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
713 | 713 | |
714 | - if ( $orderA === $orderB ) { |
|
714 | + if ($orderA === $orderB) { |
|
715 | 715 | $cursorA = $a->getContextCursor(); |
716 | 716 | $cursorB = $b->getContextCursor(); |
717 | 717 | |
718 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
718 | + if ($cursorA instanceof EntityContextCursor) { |
|
719 | 719 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
720 | 720 | } |
721 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
721 | + if ($cursorB instanceof EntityContextCursor) { |
|
722 | 722 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
723 | 723 | } |
724 | 724 | |
725 | 725 | $pidA = $cursorA->getSnakPropertyId(); |
726 | 726 | $pidB = $cursorB->getSnakPropertyId(); |
727 | 727 | |
728 | - if ( $pidA === $pidB ) { |
|
728 | + if ($pidA === $pidB) { |
|
729 | 729 | $hashA = $cursorA->getSnakHash(); |
730 | 730 | $hashB = $cursorB->getSnakHash(); |
731 | 731 | |
732 | - if ( $hashA === $hashB ) { |
|
733 | - if ( $a instanceof NullResult ) { |
|
732 | + if ($hashA === $hashB) { |
|
733 | + if ($a instanceof NullResult) { |
|
734 | 734 | return $b instanceof NullResult ? 0 : -1; |
735 | 735 | } |
736 | - if ( $b instanceof NullResult ) { |
|
736 | + if ($b instanceof NullResult) { |
|
737 | 737 | return $a instanceof NullResult ? 0 : 1; |
738 | 738 | } |
739 | 739 | |
740 | 740 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
741 | 741 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
742 | 742 | |
743 | - if ( $typeA == $typeB ) { |
|
743 | + if ($typeA == $typeB) { |
|
744 | 744 | return 0; |
745 | 745 | } else { |
746 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
746 | + return ($typeA > $typeB) ? 1 : -1; |
|
747 | 747 | } |
748 | 748 | } else { |
749 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
749 | + return ($hashA > $hashB) ? 1 : -1; |
|
750 | 750 | } |
751 | 751 | } else { |
752 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
752 | + return ($pidA > $pidB) ? 1 : -1; |
|
753 | 753 | } |
754 | 754 | } else { |
755 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
755 | + return ($orderA > $orderB) ? 1 : -1; |
|
756 | 756 | } |
757 | 757 | }; |
758 | 758 | |
759 | - uasort( $result, $sortFunction ); |
|
759 | + uasort($result, $sortFunction); |
|
760 | 760 | |
761 | 761 | return $result; |
762 | 762 | } |
@@ -1,6 +1,6 @@ discard block |
||
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 | |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | string $status = self::STATUS_TODO, |
115 | 115 | ViolationMessage $message = null |
116 | 116 | ) { |
117 | - if ( $contextCursor instanceof Context ) { |
|
117 | + if ($contextCursor instanceof Context) { |
|
118 | 118 | $context = $contextCursor; |
119 | 119 | $this->contextCursor = $context->getCursor(); |
120 | 120 | $this->snakType = $context->getSnak()->getType(); |
121 | 121 | $mainSnak = $context->getSnak(); |
122 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
122 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
123 | 123 | $this->dataValue = $mainSnak->getDataValue(); |
124 | 124 | } else { |
125 | 125 | $this->dataValue = null; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | return $this->parameters; |
170 | 170 | } |
171 | 171 | |
172 | - public function addParameter( string $key, string $value ): void { |
|
172 | + public function addParameter(string $key, string $value): void { |
|
173 | 173 | $this->parameters[$key][] = $value; |
174 | 174 | } |
175 | 175 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | return $this->status; |
181 | 181 | } |
182 | 182 | |
183 | - public function setStatus( string $status ): void { |
|
183 | + public function setStatus(string $status): void { |
|
184 | 184 | $this->status = $status; |
185 | 185 | } |
186 | 186 | |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | return $this->message; |
189 | 189 | } |
190 | 190 | |
191 | - public function setMessage( ?ViolationMessage $message ) { |
|
191 | + public function setMessage(?ViolationMessage $message) { |
|
192 | 192 | $this->message = $message; |
193 | 193 | } |
194 | 194 | |
195 | - public function withMetadata( Metadata $metadata ): self { |
|
195 | + public function withMetadata(Metadata $metadata): self { |
|
196 | 196 | $this->metadata = $metadata; |
197 | 197 | return $this; |
198 | 198 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Specials; |
6 | 6 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | Config $config, |
98 | 98 | IBufferingStatsdDataFactory $dataFactory |
99 | 99 | ) { |
100 | - parent::__construct( 'ConstraintReport' ); |
|
100 | + parent::__construct('ConstraintReport'); |
|
101 | 101 | |
102 | 102 | $this->entityLookup = $entityLookup; |
103 | 103 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $language = $this->getLanguage(); |
107 | 107 | |
108 | 108 | $formatterOptions = new FormatterOptions(); |
109 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
109 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
110 | 110 | $dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
111 | 111 | SnakFormatter::FORMAT_HTML, |
112 | 112 | $formatterOptions |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | ); |
131 | 131 | $this->violationMessageRenderer = $violationMessageRendererFactory->getViolationMessageRenderer( |
132 | 132 | $language, |
133 | - $languageFallbackChainFactory->newFromLanguage( $language ), |
|
133 | + $languageFallbackChainFactory->newFromLanguage($language), |
|
134 | 134 | $this->getContext() |
135 | 135 | ); |
136 | 136 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @return string |
166 | 166 | */ |
167 | 167 | public function getDescription() { |
168 | - return $this->msg( 'wbqc-constraintreport' )->text(); |
|
168 | + return $this->msg('wbqc-constraintreport')->text(); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -177,43 +177,43 @@ discard block |
||
177 | 177 | * @throws EntityIdParsingException |
178 | 178 | * @throws UnexpectedValueException |
179 | 179 | */ |
180 | - public function execute( $subPage ) { |
|
180 | + public function execute($subPage) { |
|
181 | 181 | $out = $this->getOutput(); |
182 | 182 | |
183 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
184 | - if ( $postRequest ) { |
|
185 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
183 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
184 | + if ($postRequest) { |
|
185 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | 189 | $out->enableOOUI(); |
190 | - $out->addModules( $this->getModules() ); |
|
190 | + $out->addModules($this->getModules()); |
|
191 | 191 | |
192 | 192 | $this->setHeaders(); |
193 | 193 | |
194 | - $out->addHTML( $this->getExplanationText() ); |
|
194 | + $out->addHTML($this->getExplanationText()); |
|
195 | 195 | $this->buildEntityIdForm(); |
196 | 196 | |
197 | - if ( !$subPage ) { |
|
197 | + if (!$subPage) { |
|
198 | 198 | return; |
199 | 199 | } |
200 | 200 | |
201 | - if ( !is_string( $subPage ) ) { |
|
202 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
201 | + if (!is_string($subPage)) { |
|
202 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | try { |
206 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
207 | - } catch ( EntityIdParsingException $e ) { |
|
206 | + $entityId = $this->entityIdParser->parse($subPage); |
|
207 | + } catch (EntityIdParsingException $e) { |
|
208 | 208 | $out->addHTML( |
209 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
209 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
210 | 210 | ); |
211 | 211 | return; |
212 | 212 | } |
213 | 213 | |
214 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
214 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
215 | 215 | $out->addHTML( |
216 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
216 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
217 | 217 | ); |
218 | 218 | return; |
219 | 219 | } |
@@ -221,18 +221,18 @@ discard block |
||
221 | 221 | $this->dataFactory->increment( |
222 | 222 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
223 | 223 | ); |
224 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
224 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
225 | 225 | |
226 | - if ( $results !== [] ) { |
|
226 | + if ($results !== []) { |
|
227 | 227 | $out->addHTML( |
228 | - $this->buildResultHeader( $entityId ) |
|
229 | - . $this->buildSummary( $results ) |
|
230 | - . $this->buildResultTable( $entityId, $results ) |
|
228 | + $this->buildResultHeader($entityId) |
|
229 | + . $this->buildSummary($results) |
|
230 | + . $this->buildResultTable($entityId, $results) |
|
231 | 231 | ); |
232 | 232 | } else { |
233 | 233 | $out->addHTML( |
234 | - $this->buildResultHeader( $entityId ) |
|
235 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
234 | + $this->buildResultHeader($entityId) |
|
235 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
236 | 236 | ); |
237 | 237 | } |
238 | 238 | } |
@@ -248,15 +248,15 @@ discard block |
||
248 | 248 | 'name' => 'entityid', |
249 | 249 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
250 | 250 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
251 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
251 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
252 | 252 | ] |
253 | 253 | ]; |
254 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
255 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
256 | - $htmlForm->setSubmitCallback( static function () { |
|
254 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
255 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
256 | + $htmlForm->setSubmitCallback(static function() { |
|
257 | 257 | return false; |
258 | 258 | } ); |
259 | - $htmlForm->setMethod( 'post' ); |
|
259 | + $htmlForm->setMethod('post'); |
|
260 | 260 | $htmlForm->show(); |
261 | 261 | } |
262 | 262 | |
@@ -270,9 +270,9 @@ discard block |
||
270 | 270 | * |
271 | 271 | * @return string HTML |
272 | 272 | */ |
273 | - private function buildNotice( string $messageKey, bool $error = false ): string { |
|
273 | + private function buildNotice(string $messageKey, bool $error = false): string { |
|
274 | 274 | $cssClasses = 'wbqc-constraintreport-notice'; |
275 | - if ( $error ) { |
|
275 | + if ($error) { |
|
276 | 276 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
277 | 277 | } |
278 | 278 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | [ |
282 | 282 | 'class' => $cssClasses |
283 | 283 | ], |
284 | - $this->msg( $messageKey )->escaped() |
|
284 | + $this->msg($messageKey)->escaped() |
|
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
@@ -291,16 +291,16 @@ discard block |
||
291 | 291 | private function getExplanationText(): string { |
292 | 292 | return Html::rawElement( |
293 | 293 | 'div', |
294 | - [ 'class' => 'wbqc-explanation' ], |
|
294 | + ['class' => 'wbqc-explanation'], |
|
295 | 295 | Html::rawElement( |
296 | 296 | 'p', |
297 | 297 | [], |
298 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
298 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
299 | 299 | ) |
300 | 300 | . Html::rawElement( |
301 | 301 | 'p', |
302 | 302 | [], |
303 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
303 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
304 | 304 | ) |
305 | 305 | ); |
306 | 306 | } |
@@ -312,31 +312,31 @@ discard block |
||
312 | 312 | * @return string HTML |
313 | 313 | * @suppress SecurityCheck-DoubleEscaped |
314 | 314 | */ |
315 | - private function buildResultTable( EntityId $entityId, array $results ): string { |
|
315 | + private function buildResultTable(EntityId $entityId, array $results): string { |
|
316 | 316 | // Set table headers |
317 | 317 | $table = new HtmlTableBuilder( |
318 | 318 | [ |
319 | 319 | new HtmlTableHeaderBuilder( |
320 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
320 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
321 | 321 | true |
322 | 322 | ), |
323 | 323 | new HtmlTableHeaderBuilder( |
324 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(), |
|
324 | + $this->msg('wbqc-constraintreport-result-table-header-property')->escaped(), |
|
325 | 325 | true |
326 | 326 | ), |
327 | 327 | new HtmlTableHeaderBuilder( |
328 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(), |
|
328 | + $this->msg('wbqc-constraintreport-result-table-header-message')->escaped(), |
|
329 | 329 | true |
330 | 330 | ), |
331 | 331 | new HtmlTableHeaderBuilder( |
332 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
332 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
333 | 333 | true |
334 | 334 | ) |
335 | 335 | ] |
336 | 336 | ); |
337 | 337 | |
338 | - foreach ( $results as $result ) { |
|
339 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
338 | + foreach ($results as $result) { |
|
339 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | return $table->toHtml(); |
@@ -348,40 +348,40 @@ discard block |
||
348 | 348 | CheckResult $result |
349 | 349 | ): HtmlTableBuilder { |
350 | 350 | $message = $result->getMessage(); |
351 | - if ( $message === null ) { |
|
351 | + if ($message === null) { |
|
352 | 352 | // no row for this result |
353 | 353 | return $table; |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Status column |
357 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
357 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
358 | 358 | |
359 | 359 | // Property column |
360 | - $propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
360 | + $propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
361 | 361 | $propertyColumn = $this->getClaimLink( |
362 | 362 | $entityId, |
363 | 363 | $propertyId, |
364 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
364 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
365 | 365 | ); |
366 | 366 | |
367 | 367 | // Message column |
368 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
368 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
369 | 369 | |
370 | 370 | // Constraint column |
371 | 371 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
372 | 372 | try { |
373 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
374 | - } catch ( InvalidArgumentException $e ) { |
|
375 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
373 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
374 | + } catch (InvalidArgumentException $e) { |
|
375 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
376 | 376 | } |
377 | 377 | $constraintLink = $this->getClaimLink( |
378 | 378 | $propertyId, |
379 | - new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
379 | + new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
380 | 380 | $constraintTypeLabel |
381 | 381 | ); |
382 | 382 | $constraintColumn = $this->buildExpandableElement( |
383 | 383 | $constraintLink, |
384 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
384 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
385 | 385 | '[...]' |
386 | 386 | ); |
387 | 387 | |
@@ -421,15 +421,15 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @return string HTML |
423 | 423 | */ |
424 | - protected function buildResultHeader( EntityId $entityId ): string { |
|
425 | - $entityLink = sprintf( '%s (%s)', |
|
426 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
427 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
424 | + protected function buildResultHeader(EntityId $entityId): string { |
|
425 | + $entityLink = sprintf('%s (%s)', |
|
426 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
427 | + htmlspecialchars($entityId->getSerialization())); |
|
428 | 428 | |
429 | 429 | return Html::rawElement( |
430 | 430 | 'h3', |
431 | 431 | [], |
432 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
432 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
433 | 433 | ); |
434 | 434 | } |
435 | 435 | |
@@ -440,24 +440,24 @@ discard block |
||
440 | 440 | * |
441 | 441 | * @return string HTML |
442 | 442 | */ |
443 | - protected function buildSummary( array $results ): string { |
|
443 | + protected function buildSummary(array $results): string { |
|
444 | 444 | $statuses = []; |
445 | - foreach ( $results as $result ) { |
|
446 | - $status = strtolower( $result->getStatus() ); |
|
447 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
445 | + foreach ($results as $result) { |
|
446 | + $status = strtolower($result->getStatus()); |
|
447 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | $statusElements = []; |
451 | - foreach ( $statuses as $status => $count ) { |
|
452 | - if ( $count > 0 ) { |
|
451 | + foreach ($statuses as $status => $count) { |
|
452 | + if ($count > 0) { |
|
453 | 453 | $statusElements[] = |
454 | - $this->formatStatus( $status ) |
|
454 | + $this->formatStatus($status) |
|
455 | 455 | . ': ' |
456 | 456 | . $count; |
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
460 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | ?string $expandableContent, |
478 | 478 | string $indicator |
479 | 479 | ): string { |
480 | - if ( empty( $expandableContent ) ) { |
|
480 | + if (empty($expandableContent)) { |
|
481 | 481 | return $content; |
482 | 482 | } |
483 | 483 | |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | $expandableContent |
498 | 498 | ); |
499 | 499 | |
500 | - return sprintf( '%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent ); |
|
500 | + return sprintf('%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | * |
510 | 510 | * @return string HTML |
511 | 511 | */ |
512 | - private function formatStatus( string $status ): string { |
|
513 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
512 | + private function formatStatus(string $status): string { |
|
513 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
514 | 514 | $statusIcons = [ |
515 | 515 | CheckResult::STATUS_SUGGESTION => [ |
516 | 516 | 'icon' => 'suggestion-constraint-violation', |
@@ -527,25 +527,25 @@ discard block |
||
527 | 527 | ], |
528 | 528 | ]; |
529 | 529 | |
530 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
531 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
532 | - $iconHtml = $iconWidget->toString() . ' '; |
|
530 | + if (array_key_exists($status, $statusIcons)) { |
|
531 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
532 | + $iconHtml = $iconWidget->toString().' '; |
|
533 | 533 | } else { |
534 | 534 | $iconHtml = ''; |
535 | 535 | } |
536 | 536 | |
537 | - $labelWidget = new LabelWidget( [ |
|
538 | - 'label' => $this->msg( $messageName )->text(), |
|
539 | - ] ); |
|
537 | + $labelWidget = new LabelWidget([ |
|
538 | + 'label' => $this->msg($messageName)->text(), |
|
539 | + ]); |
|
540 | 540 | $labelHtml = $labelWidget->toString(); |
541 | 541 | |
542 | 542 | $formattedStatus = |
543 | 543 | Html::rawElement( |
544 | 544 | 'span', |
545 | 545 | [ |
546 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
546 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
547 | 547 | ], |
548 | - $iconHtml . $labelHtml |
|
548 | + $iconHtml.$labelHtml |
|
549 | 549 | ); |
550 | 550 | |
551 | 551 | return $formattedStatus; |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | return Html::rawElement( |
569 | 569 | 'a', |
570 | 570 | [ |
571 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
571 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
572 | 572 | 'target' => '_blank' |
573 | 573 | ], |
574 | 574 | $text |
@@ -582,8 +582,8 @@ discard block |
||
582 | 582 | EntityId $entityId, |
583 | 583 | NumericPropertyId $propertyId |
584 | 584 | ): string { |
585 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
586 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
585 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
586 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
587 | 587 | |
588 | 588 | return $entityUrl; |
589 | 589 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Api; |
6 | 6 | |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | return new CheckResultsRenderer( |
41 | 41 | $this->entityTitleLookup, |
42 | 42 | $this->entityIdLabelFormatterFactory |
43 | - ->getEntityIdFormatter( $userLanguage ), |
|
43 | + ->getEntityIdFormatter($userLanguage), |
|
44 | 44 | $this->violationMessageRendererFactory |
45 | 45 | ->getViolationMessageRenderer( |
46 | 46 | $userLanguage, |
47 | - $this->languageFallbackChainFactory->newFromLanguage( $userLanguage ), |
|
47 | + $this->languageFallbackChainFactory->newFromLanguage($userLanguage), |
|
48 | 48 | $messageLocalizer |
49 | 49 | ) |
50 | 50 | ); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Api; |
6 | 6 | |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | StatementGuidParser $statementGuidParser, |
80 | 80 | IBufferingStatsdDataFactory $dataFactory |
81 | 81 | ) { |
82 | - parent::__construct( $main, $name ); |
|
82 | + parent::__construct($main, $name); |
|
83 | 83 | |
84 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
84 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
85 | 85 | $this->languageFallbackChainFactory = $languageFallbackChainFactory; |
86 | 86 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
87 | 87 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
@@ -97,39 +97,39 @@ discard block |
||
97 | 97 | $params = $this->extractRequestParams(); |
98 | 98 | $result = $this->getResult(); |
99 | 99 | |
100 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
101 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
100 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
101 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
102 | 102 | |
103 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
104 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
103 | + $this->checkPropertyIds($propertyIds, $result); |
|
104 | + $this->checkConstraintIds($constraintIds, $result); |
|
105 | 105 | |
106 | - $result->addValue( null, 'success', 1 ); |
|
106 | + $result->addValue(null, 'success', 1); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * @param array|null $propertyIdSerializations |
111 | 111 | * @return NumericPropertyId[] |
112 | 112 | */ |
113 | - private function parsePropertyIds( ?array $propertyIdSerializations ): array { |
|
114 | - if ( $propertyIdSerializations === null ) { |
|
113 | + private function parsePropertyIds(?array $propertyIdSerializations): array { |
|
114 | + if ($propertyIdSerializations === null) { |
|
115 | 115 | return []; |
116 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
116 | + } elseif (empty($propertyIdSerializations)) { |
|
117 | 117 | $this->apiErrorReporter->dieError( |
118 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
118 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
119 | 119 | 'no-data' |
120 | 120 | ); |
121 | 121 | } |
122 | 122 | |
123 | 123 | return array_map( |
124 | - function ( $propertyIdSerialization ) { |
|
124 | + function($propertyIdSerialization) { |
|
125 | 125 | try { |
126 | - return new NumericPropertyId( $propertyIdSerialization ); |
|
127 | - } catch ( InvalidArgumentException $e ) { |
|
126 | + return new NumericPropertyId($propertyIdSerialization); |
|
127 | + } catch (InvalidArgumentException $e) { |
|
128 | 128 | $this->apiErrorReporter->dieError( |
129 | 129 | "Invalid id: $propertyIdSerialization", |
130 | 130 | 'invalid-property-id', |
131 | 131 | 0, // default argument |
132 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
132 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
133 | 133 | ); |
134 | 134 | } |
135 | 135 | }, |
@@ -141,35 +141,35 @@ discard block |
||
141 | 141 | * @param array|null $constraintIds |
142 | 142 | * @return string[] |
143 | 143 | */ |
144 | - private function parseConstraintIds( ?array $constraintIds ): array { |
|
145 | - if ( $constraintIds === null ) { |
|
144 | + private function parseConstraintIds(?array $constraintIds): array { |
|
145 | + if ($constraintIds === null) { |
|
146 | 146 | return []; |
147 | - } elseif ( empty( $constraintIds ) ) { |
|
147 | + } elseif (empty($constraintIds)) { |
|
148 | 148 | $this->apiErrorReporter->dieError( |
149 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
149 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
150 | 150 | 'no-data' |
151 | 151 | ); |
152 | 152 | } |
153 | 153 | |
154 | 154 | return array_map( |
155 | - function ( $constraintId ) { |
|
155 | + function($constraintId) { |
|
156 | 156 | try { |
157 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
158 | - if ( !$propertyId instanceof NumericPropertyId ) { |
|
157 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
158 | + if (!$propertyId instanceof NumericPropertyId) { |
|
159 | 159 | $this->apiErrorReporter->dieError( |
160 | 160 | "Invalid property ID: {$propertyId->getSerialization()}", |
161 | 161 | 'invalid-property-id', |
162 | 162 | 0, // default argument |
163 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
163 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
164 | 164 | ); |
165 | 165 | } |
166 | 166 | return $constraintId; |
167 | - } catch ( StatementGuidParsingException $e ) { |
|
167 | + } catch (StatementGuidParsingException $e) { |
|
168 | 168 | $this->apiErrorReporter->dieError( |
169 | 169 | "Invalid statement GUID: $constraintId", |
170 | 170 | 'invalid-guid', |
171 | 171 | 0, // default argument |
172 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
172 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
173 | 173 | ); |
174 | 174 | } |
175 | 175 | }, |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | * @param NumericPropertyId[] $propertyIds |
182 | 182 | * @param ApiResult $result |
183 | 183 | */ |
184 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ): void { |
|
185 | - foreach ( $propertyIds as $propertyId ) { |
|
186 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
184 | + private function checkPropertyIds(array $propertyIds, ApiResult $result): void { |
|
185 | + foreach ($propertyIds as $propertyId) { |
|
186 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
187 | 187 | $allConstraintExceptions = $this->delegatingConstraintChecker |
188 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
189 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
188 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
189 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
190 | 190 | $this->addConstraintParameterExceptionsToResult( |
191 | 191 | $constraintId, |
192 | 192 | $constraintParameterExceptions, |
@@ -200,15 +200,15 @@ discard block |
||
200 | 200 | * @param string[] $constraintIds |
201 | 201 | * @param ApiResult $result |
202 | 202 | */ |
203 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ): void { |
|
204 | - foreach ( $constraintIds as $constraintId ) { |
|
205 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
203 | + private function checkConstraintIds(array $constraintIds, ApiResult $result): void { |
|
204 | + foreach ($constraintIds as $constraintId) { |
|
205 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
206 | 206 | // already checked as part of checkPropertyIds() |
207 | 207 | continue; |
208 | 208 | } |
209 | 209 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
210 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
211 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
210 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
211 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
@@ -216,18 +216,18 @@ discard block |
||
216 | 216 | * @param NumericPropertyId $propertyId |
217 | 217 | * @return string[] |
218 | 218 | */ |
219 | - private function getResultPathForPropertyId( NumericPropertyId $propertyId ): array { |
|
220 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
219 | + private function getResultPathForPropertyId(NumericPropertyId $propertyId): array { |
|
220 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | 224 | * @param string $constraintId |
225 | 225 | * @return string[] |
226 | 226 | */ |
227 | - private function getResultPathForConstraintId( string $constraintId ): array { |
|
228 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
227 | + private function getResultPathForConstraintId(string $constraintId): array { |
|
228 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
229 | 229 | '@phan-var NumericPropertyId $propertyId'; |
230 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
230 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | ?array $constraintParameterExceptions, |
243 | 243 | ApiResult $result |
244 | 244 | ): void { |
245 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
246 | - if ( $constraintParameterExceptions === null ) { |
|
245 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
246 | + if ($constraintParameterExceptions === null) { |
|
247 | 247 | $result->addValue( |
248 | 248 | $path, |
249 | 249 | self::KEY_STATUS, |
@@ -253,18 +253,18 @@ discard block |
||
253 | 253 | $result->addValue( |
254 | 254 | $path, |
255 | 255 | self::KEY_STATUS, |
256 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
256 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
257 | 257 | ); |
258 | 258 | |
259 | 259 | $language = $this->getLanguage(); |
260 | 260 | $violationMessageRenderer = $this->violationMessageRendererFactory |
261 | 261 | ->getViolationMessageRenderer( |
262 | 262 | $language, |
263 | - $this->languageFallbackChainFactory->newFromLanguage( $language ), |
|
263 | + $this->languageFallbackChainFactory->newFromLanguage($language), |
|
264 | 264 | $this |
265 | 265 | ); |
266 | 266 | $problems = []; |
267 | - foreach ( $constraintParameterExceptions as $constraintParameterException ) { |
|
267 | + foreach ($constraintParameterExceptions as $constraintParameterException) { |
|
268 | 268 | $problems[] = [ |
269 | 269 | self::KEY_MESSAGE_HTML => $violationMessageRenderer->render( |
270 | 270 | $constraintParameterException->getViolationMessage() ), |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | return [ |
304 | 304 | 'action=wbcheckconstraintparameters&propertyid=P247' |
305 | 305 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
306 | - 'action=wbcheckconstraintparameters&' . |
|
307 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
306 | + 'action=wbcheckconstraintparameters&'. |
|
307 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
308 | 308 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
309 | 309 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
310 | 310 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message; |
6 | 6 | |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | 'wbqc-violation-message-format-clarification' => 'wbqc-violation-message-format', |
28 | 28 | ]; |
29 | 29 | |
30 | - public function render( ViolationMessage $violationMessage ): string { |
|
31 | - if ( !array_key_exists( $violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS ) ) { |
|
32 | - return parent::render( $violationMessage ); |
|
30 | + public function render(ViolationMessage $violationMessage): string { |
|
31 | + if (!array_key_exists($violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS)) { |
|
32 | + return parent::render($violationMessage); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | $arguments = $violationMessage->getArguments(); |
36 | - $multilingualTextArgument = array_pop( $arguments ); |
|
36 | + $multilingualTextArgument = array_pop($arguments); |
|
37 | 37 | $multilingualTextParams = $this->renderMultilingualText( |
38 | 38 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue |
39 | 39 | $multilingualTextArgument['value'], |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | $multilingualTextArgument['role'] |
42 | 42 | ); |
43 | 43 | |
44 | - $paramsLists = [ [] ]; |
|
45 | - foreach ( $arguments as $argument ) { |
|
46 | - $paramsLists[] = $this->renderArgument( $argument ); |
|
44 | + $paramsLists = [[]]; |
|
45 | + foreach ($arguments as $argument) { |
|
46 | + $paramsLists[] = $this->renderArgument($argument); |
|
47 | 47 | } |
48 | - $regularParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
48 | + $regularParams = call_user_func_array('array_merge', $paramsLists); |
|
49 | 49 | |
50 | - if ( $multilingualTextParams === null ) { |
|
50 | + if ($multilingualTextParams === null) { |
|
51 | 51 | return $this->messageLocalizer |
52 | - ->msg( self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()] ) |
|
53 | - ->params( $regularParams ) |
|
52 | + ->msg(self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()]) |
|
53 | + ->params($regularParams) |
|
54 | 54 | ->escaped(); |
55 | 55 | } else { |
56 | 56 | return $this->messageLocalizer |
57 | - ->msg( $violationMessage->getMessageKey() ) |
|
58 | - ->params( $regularParams ) |
|
59 | - ->params( $multilingualTextParams ) |
|
57 | + ->msg($violationMessage->getMessageKey()) |
|
58 | + ->params($regularParams) |
|
59 | + ->params($multilingualTextParams) |
|
60 | 60 | ->escaped(); |
61 | 61 | } |
62 | 62 | } |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | * @return array[]|null list of parameters as accepted by Message::params(), |
68 | 68 | * or null if the text is not available in the user’s language |
69 | 69 | */ |
70 | - protected function renderMultilingualText( MultilingualTextValue $text, ?string $role ): ?array { |
|
70 | + protected function renderMultilingualText(MultilingualTextValue $text, ?string $role): ?array { |
|
71 | 71 | $texts = $text->getTexts(); |
72 | - foreach ( $this->languageFallbackChain->getFetchLanguageCodes() as $languageCode ) { |
|
73 | - if ( array_key_exists( $languageCode, $texts ) ) { |
|
74 | - return [ Message::rawParam( $this->addRole( |
|
75 | - htmlspecialchars( $texts[$languageCode]->getText() ), |
|
72 | + foreach ($this->languageFallbackChain->getFetchLanguageCodes() as $languageCode) { |
|
73 | + if (array_key_exists($languageCode, $texts)) { |
|
74 | + return [Message::rawParam($this->addRole( |
|
75 | + htmlspecialchars($texts[$languageCode]->getText()), |
|
76 | 76 | $role |
77 | - ) ) ]; |
|
77 | + ))]; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message; |
6 | 6 | |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | ): ViolationMessageRenderer { |
44 | 44 | $userLanguageCode = $userLanguage->getCode(); |
45 | 45 | $formatterOptions = new FormatterOptions(); |
46 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $userLanguageCode ); |
|
46 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $userLanguageCode); |
|
47 | 47 | return new MultilingualTextViolationMessageRenderer( |
48 | 48 | $this->entityIdHtmlLinkFormatterFactory |
49 | - ->getEntityIdFormatter( $userLanguage ), |
|
49 | + ->getEntityIdFormatter($userLanguage), |
|
50 | 50 | $this->valueFormatterFactory |
51 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ), |
|
51 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions), |
|
52 | 52 | $this->languageNameUtils, |
53 | 53 | $userLanguageCode, |
54 | 54 | $languageFallbackChain, |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | ) { |
144 | 144 | $results = []; |
145 | 145 | $metadatas = []; |
146 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
146 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
147 | 147 | $storedEntityIds = []; |
148 | - foreach ( $entityIds as $entityId ) { |
|
149 | - $storedResults = $this->getStoredResults( $entityId ); |
|
150 | - if ( $storedResults !== null ) { |
|
151 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
152 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
153 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
148 | + foreach ($entityIds as $entityId) { |
|
149 | + $storedResults = $this->getStoredResults($entityId); |
|
150 | + if ($storedResults !== null) { |
|
151 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
152 | + foreach ($storedResults->getArray() as $checkResult) { |
|
153 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
154 | 154 | $results[] = $checkResult; |
155 | 155 | } |
156 | 156 | } |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | $storedEntityIds[] = $entityId; |
159 | 159 | } |
160 | 160 | } |
161 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
161 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
162 | 162 | } |
163 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
164 | - if ( $entityIds !== [] ) { |
|
165 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
163 | + if ($entityIds !== [] || $claimIds !== []) { |
|
164 | + if ($entityIds !== []) { |
|
165 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
166 | 166 | } |
167 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
168 | - $results = array_merge( $results, $response->getArray() ); |
|
167 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
168 | + $results = array_merge($results, $response->getArray()); |
|
169 | 169 | $metadatas[] = $response->getMetadata(); |
170 | 170 | } |
171 | 171 | return new CachedCheckResults( |
172 | 172 | $results, |
173 | - Metadata::merge( $metadatas ) |
|
173 | + Metadata::merge($metadatas) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | ?array $constraintIds, |
194 | 194 | array $statuses |
195 | 195 | ) { |
196 | - if ( $claimIds !== [] ) { |
|
196 | + if ($claimIds !== []) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | - if ( $constraintIds !== null ) { |
|
199 | + if ($constraintIds !== null) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
202 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
203 | 203 | return false; |
204 | 204 | } |
205 | 205 | return true; |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param CheckResult $result |
215 | 215 | * @return bool |
216 | 216 | */ |
217 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
218 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
217 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
218 | + return in_array($result->getStatus(), $statuses, true) || |
|
219 | 219 | $result instanceof NullResult; |
220 | 220 | } |
221 | 221 | |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | ?array $constraintIds, |
233 | 233 | array $statuses |
234 | 234 | ) { |
235 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
235 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
236 | 236 | |
237 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
238 | - foreach ( $entityIds as $entityId ) { |
|
239 | - $this->storeResults( $entityId, $results ); |
|
237 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
238 | + foreach ($entityIds as $entityId) { |
|
239 | + $this->storeResults($entityId, $results); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | ?array $constraintIds, |
268 | 268 | array $statuses |
269 | 269 | ) { |
270 | - if ( $constraintIds !== null ) { |
|
270 | + if ($constraintIds !== null) { |
|
271 | 271 | return false; |
272 | 272 | } |
273 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
273 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | return true; |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * May include check results for other entity IDs as well, |
285 | 285 | * or check results with statuses that we’re not interested in caching. |
286 | 286 | */ |
287 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
287 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
288 | 288 | $latestRevisionIds = $this->getLatestRevisionIds( |
289 | 289 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
290 | 290 | ); |
291 | - if ( $latestRevisionIds === null ) { |
|
291 | + if ($latestRevisionIds === null) { |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $resultSerializations = []; |
296 | - foreach ( $results->getArray() as $checkResult ) { |
|
297 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
296 | + foreach ($results->getArray() as $checkResult) { |
|
297 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
298 | 298 | continue; |
299 | 299 | } |
300 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
301 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
300 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
301 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | 'latestRevisionIds' => $latestRevisionIds, |
308 | 308 | ]; |
309 | 309 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
310 | - if ( $futureTime !== null ) { |
|
310 | + if ($futureTime !== null) { |
|
311 | 311 | $value['futureTime'] = $futureTime->getArrayValue(); |
312 | 312 | } |
313 | 313 | |
314 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
314 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -326,33 +326,32 @@ discard block |
||
326 | 326 | $forRevision = 0 |
327 | 327 | ) { |
328 | 328 | $cacheInfo = WANObjectCache::PASS_BY_REF; |
329 | - $value = $this->cache->get( $entityId, $curTTL, [], $cacheInfo ); |
|
330 | - $now = call_user_func( $this->microtime, true ); |
|
329 | + $value = $this->cache->get($entityId, $curTTL, [], $cacheInfo); |
|
330 | + $now = call_user_func($this->microtime, true); |
|
331 | 331 | |
332 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
333 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
334 | - if ( $dependencyMetadata === null ) { |
|
332 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
333 | + [$entityId->getSerialization() => $forRevision]); |
|
334 | + if ($dependencyMetadata === null) { |
|
335 | 335 | return null; |
336 | 336 | } |
337 | 337 | |
338 | 338 | // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive |
339 | 339 | $asOf = $cacheInfo[WANObjectCache::KEY_AS_OF]; |
340 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
340 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
341 | 341 | $cachingMetadata = $ageInSeconds > 0 ? |
342 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
343 | - CachingMetadata::fresh(); |
|
342 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
344 | 343 | |
345 | 344 | $results = []; |
346 | - foreach ( $value['results'] as $resultSerialization ) { |
|
347 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
345 | + foreach ($value['results'] as $resultSerialization) { |
|
346 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
348 | 347 | } |
349 | 348 | |
350 | 349 | return new CachedCheckResults( |
351 | 350 | $results, |
352 | - Metadata::merge( [ |
|
353 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
354 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
355 | - ] ) |
|
351 | + Metadata::merge([ |
|
352 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
353 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
354 | + ]) |
|
356 | 355 | ); |
357 | 356 | } |
358 | 357 | |
@@ -368,43 +367,43 @@ discard block |
||
368 | 367 | * @return DependencyMetadata|null the dependency metadata, |
369 | 368 | * or null if $value should no longer be used |
370 | 369 | */ |
371 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
372 | - if ( $value === false ) { |
|
370 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
371 | + if ($value === false) { |
|
373 | 372 | return null; |
374 | 373 | } |
375 | 374 | |
376 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
377 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
378 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
375 | + if (array_key_exists('futureTime', $value)) { |
|
376 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
377 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
379 | 378 | return null; |
380 | 379 | } |
381 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
380 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
382 | 381 | } else { |
383 | 382 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
384 | 383 | } |
385 | 384 | |
386 | - foreach ( $paramRevs as $id => $revision ) { |
|
387 | - if ( $revision > 0 ) { |
|
388 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
385 | + foreach ($paramRevs as $id => $revision) { |
|
386 | + if ($revision > 0) { |
|
387 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
389 | 388 | } |
390 | 389 | } |
391 | 390 | |
392 | 391 | $dependedEntityIds = array_map( |
393 | - [ $this->entityIdParser, "parse" ], |
|
394 | - array_keys( $value['latestRevisionIds'] ) |
|
392 | + [$this->entityIdParser, "parse"], |
|
393 | + array_keys($value['latestRevisionIds']) |
|
395 | 394 | ); |
396 | 395 | |
397 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
396 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
398 | 397 | return null; |
399 | 398 | } |
400 | 399 | |
401 | 400 | return array_reduce( |
402 | 401 | $dependedEntityIds, |
403 | - static function ( DependencyMetadata $metadata, EntityId $entityId ) { |
|
404 | - return DependencyMetadata::merge( [ |
|
402 | + static function(DependencyMetadata $metadata, EntityId $entityId) { |
|
403 | + return DependencyMetadata::merge([ |
|
405 | 404 | $metadata, |
406 | - DependencyMetadata::ofEntityId( $entityId ) |
|
407 | - ] ); |
|
405 | + DependencyMetadata::ofEntityId($entityId) |
|
406 | + ]); |
|
408 | 407 | }, |
409 | 408 | $futureTimeDependencyMetadata |
410 | 409 | ); |
@@ -424,13 +423,13 @@ discard block |
||
424 | 423 | array $resultSerialization, |
425 | 424 | CachingMetadata $cachingMetadata |
426 | 425 | ) { |
427 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
428 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
426 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
427 | + if ($this->isPossiblyStaleResult($result)) { |
|
429 | 428 | $result->withMetadata( |
430 | - Metadata::merge( [ |
|
429 | + Metadata::merge([ |
|
431 | 430 | $result->getMetadata(), |
432 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
433 | - ] ) |
|
431 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
432 | + ]) |
|
434 | 433 | ); |
435 | 434 | } |
436 | 435 | return $result; |
@@ -440,8 +439,8 @@ discard block |
||
440 | 439 | * @param CheckResult $result |
441 | 440 | * @return bool |
442 | 441 | */ |
443 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
444 | - if ( $result instanceof NullResult ) { |
|
442 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
443 | + if ($result instanceof NullResult) { |
|
445 | 444 | return false; |
446 | 445 | } |
447 | 446 | |
@@ -456,14 +455,14 @@ discard block |
||
456 | 455 | * @return int[]|null array from entity ID serializations to revision ID, |
457 | 456 | * or null to indicate that not all revision IDs could be loaded |
458 | 457 | */ |
459 | - private function getLatestRevisionIds( array $entityIds ) { |
|
460 | - if ( $entityIds === [] ) { |
|
458 | + private function getLatestRevisionIds(array $entityIds) { |
|
459 | + if ($entityIds === []) { |
|
461 | 460 | $this->loggingHelper->logEmptyDependencyMetadata(); |
462 | 461 | return []; |
463 | 462 | } |
464 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
463 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
465 | 464 | // one of those entities will probably be edited soon, so might as well skip caching |
466 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
465 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
467 | 466 | return null; |
468 | 467 | } |
469 | 468 | |
@@ -471,7 +470,7 @@ discard block |
||
471 | 470 | $entityIds, |
472 | 471 | LookupConstants::LATEST_FROM_REPLICA |
473 | 472 | ); |
474 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
473 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
475 | 474 | return null; |
476 | 475 | } |
477 | 476 | return $latestRevisionIds; |
@@ -481,8 +480,8 @@ discard block |
||
481 | 480 | * @param array $array |
482 | 481 | * @return bool |
483 | 482 | */ |
484 | - private function hasFalseElements( array $array ) { |
|
485 | - return in_array( false, $array, true ); |
|
483 | + private function hasFalseElements(array $array) { |
|
484 | + return in_array(false, $array, true); |
|
486 | 485 | } |
487 | 486 | |
488 | 487 | /** |
@@ -490,7 +489,7 @@ discard block |
||
490 | 489 | * |
491 | 490 | * @param callable $microtime |
492 | 491 | */ |
493 | - public function setMicrotimeFunction( callable $microtime ) { |
|
492 | + public function setMicrotimeFunction(callable $microtime) { |
|
494 | 493 | $this->microtime = $microtime; |
495 | 494 | } |
496 | 495 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param WANObjectCache $cache |
37 | 37 | * @param string $formatVersion The version of the API response format. |
38 | 38 | */ |
39 | - public function __construct( WANObjectCache $cache, $formatVersion ) { |
|
39 | + public function __construct(WANObjectCache $cache, $formatVersion) { |
|
40 | 40 | $this->cache = $cache; |
41 | 41 | $this->formatVersion = $formatVersion; |
42 | 42 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param EntityId $entityId |
46 | 46 | * @return string cache key |
47 | 47 | */ |
48 | - public function makeKey( EntityId $entityId ) { |
|
48 | + public function makeKey(EntityId $entityId) { |
|
49 | 49 | return $this->cache->makeKey( |
50 | 50 | 'WikibaseQualityConstraints', // extension |
51 | 51 | 'checkConstraints', // action |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param array &$info |
62 | 62 | * @return mixed |
63 | 63 | */ |
64 | - public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], array &$info = [] ) { |
|
65 | - return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $info ); |
|
64 | + public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], array &$info = []) { |
|
65 | + return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $info); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | * @param array $opts |
73 | 73 | * @return bool |
74 | 74 | */ |
75 | - public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) { |
|
76 | - return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts ); |
|
75 | + public function set(EntityId $key, $value, $ttl = 0, array $opts = []) { |
|
76 | + return $this->cache->set($this->makeKey($key), $value, $ttl, $opts); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @param EntityId $key |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public function delete( EntityId $key ) { |
|
84 | - return $this->cache->delete( $this->makeKey( $key ) ); |
|
83 | + public function delete(EntityId $key) { |
|
84 | + return $this->cache->delete($this->makeKey($key)); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | } |