@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
4 | - wfLoadExtension( 'WikibaseQualityConstraints', __DIR__ . '/extension.json' ); |
|
3 | +if (function_exists('wfLoadExtension')) { |
|
4 | + wfLoadExtension('WikibaseQualityConstraints', __DIR__.'/extension.json'); |
|
5 | 5 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
6 | - $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__ . '/i18n'; |
|
7 | - $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__ . '/WikibaseQualityConstraints.alias.php'; |
|
6 | + $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__.'/i18n'; |
|
7 | + $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__.'/WikibaseQualityConstraints.alias.php'; |
|
8 | 8 | /* wfWarn( |
9 | 9 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
10 | 10 | 'Please use wfLoadExtension instead, ' . |
@@ -12,5 +12,5 @@ discard block |
||
12 | 12 | ); */ |
13 | 13 | return; |
14 | 14 | } else { |
15 | - die( 'This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+' ); |
|
15 | + die('This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+'); |
|
16 | 16 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | |
11 | 11 | /** English (English) */ |
12 | 12 | $specialPageAliases['en'] = [ |
13 | - 'ConstraintReport' => [ 'ConstraintReport', 'Constraint Report' ], |
|
13 | + 'ConstraintReport' => ['ConstraintReport', 'Constraint Report'], |
|
14 | 14 | ]; |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | use WikibaseQuality\ConstraintReport\UpdateConstraintsTableJob; |
9 | 9 | use Wikibase\Repo\WikibaseRepo; |
10 | 10 | |
11 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
12 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
11 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
12 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
13 | 13 | |
14 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
14 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Runs {@link UpdateConstraintsTableJob} once for every property. |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | public function __construct() { |
24 | 24 | parent::__construct(); |
25 | 25 | |
26 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
26 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function execute() { |
30 | - if ( !MediaWikiServices::getInstance()->getMainConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
31 | - $this->error( 'Constraint statements are not enabled. Aborting.', 1 ); |
|
30 | + if (!MediaWikiServices::getInstance()->getMainConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
31 | + $this->error('Constraint statements are not enabled. Aborting.', 1); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $propertyInfoLookup = WikibaseRepo::getDefaultInstance()->getStore()->getPropertyInfoLookup(); |
35 | - foreach ( $propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
36 | - $this->output( sprintf( 'Importing constraint statements for % 6s... ', $propertyIdSerialization ), $propertyIdSerialization ); |
|
37 | - $startTime = microtime( true ); |
|
38 | - $job = UpdateConstraintsTableJob::newFromGlobalState( Title::newMainPage(), [ 'propertyId' => $propertyIdSerialization ] ); |
|
35 | + foreach ($propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
36 | + $this->output(sprintf('Importing constraint statements for % 6s... ', $propertyIdSerialization), $propertyIdSerialization); |
|
37 | + $startTime = microtime(true); |
|
38 | + $job = UpdateConstraintsTableJob::newFromGlobalState(Title::newMainPage(), ['propertyId' => $propertyIdSerialization]); |
|
39 | 39 | $job->run(); |
40 | - $endTime = microtime( true ); |
|
41 | - $millis = ( $endTime - $startTime ) * 1000; |
|
42 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
40 | + $endTime = microtime(true); |
|
41 | + $millis = ($endTime - $startTime) * 1000; |
|
42 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | - * @param EntityDocument|StatementListProvider $entity |
|
273 | + * @param EntityDocument $entity |
|
274 | 274 | * @param string[]|null $constraintIds list of constraints to check (if null: all constraints) |
275 | 275 | * @param callable|null $defaultResults optional function to pre-populate the check results |
276 | 276 | * |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
301 | - * @param EntityDocument|StatementListProvider $entity |
|
301 | + * @param EntityDocument $entity |
|
302 | 302 | * @param Statement $statement |
303 | 303 | * @param string[]|null $constraintIds list of constraints to check (if null: all constraints) |
304 | 304 | * @param callable|null $defaultResults optional function to pre-populate the check results |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | callable $defaultResults = null |
138 | 138 | ) { |
139 | 139 | |
140 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
141 | - if ( $entity instanceof StatementListProvider ) { |
|
140 | + $entity = $this->entityLookup->getEntity($entityId); |
|
141 | + if ($entity instanceof StatementListProvider) { |
|
142 | 142 | $result = $this->checkEveryStatement( |
143 | - $this->entityLookup->getEntity( $entityId ), |
|
143 | + $this->entityLookup->getEntity($entityId), |
|
144 | 144 | $constraintIds, |
145 | 145 | $defaultResults |
146 | 146 | ); |
147 | - $output = $this->sortResult( $result ); |
|
147 | + $output = $this->sortResult($result); |
|
148 | 148 | return $output; |
149 | 149 | } |
150 | 150 | |
@@ -170,19 +170,19 @@ discard block |
||
170 | 170 | callable $defaultResults = null |
171 | 171 | ) { |
172 | 172 | |
173 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
173 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
174 | 174 | $entityId = $parsedGuid->getEntityId(); |
175 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
176 | - if ( $entity instanceof StatementListProvider ) { |
|
177 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
178 | - if ( $statement ) { |
|
175 | + $entity = $this->entityLookup->getEntity($entityId); |
|
176 | + if ($entity instanceof StatementListProvider) { |
|
177 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
178 | + if ($statement) { |
|
179 | 179 | $result = $this->checkStatement( |
180 | 180 | $entity, |
181 | 181 | $statement, |
182 | 182 | $constraintIds, |
183 | 183 | $defaultResults |
184 | 184 | ); |
185 | - $output = $this->sortResult( $result ); |
|
185 | + $output = $this->sortResult($result); |
|
186 | 186 | return $output; |
187 | 187 | } |
188 | 188 | } |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | return []; |
191 | 191 | } |
192 | 192 | |
193 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
194 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
193 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
194 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
195 | 195 | return [ |
196 | 196 | Context::TYPE_STATEMENT, |
197 | 197 | Context::TYPE_QUALIFIER, |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | ]; |
200 | 200 | } |
201 | 201 | |
202 | - return array_keys( array_filter( |
|
202 | + return array_keys(array_filter( |
|
203 | 203 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
204 | - function ( $resultStatus ) { |
|
204 | + function($resultStatus) { |
|
205 | 205 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
206 | 206 | } |
207 | - ) ); |
|
207 | + )); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -215,32 +215,32 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return ConstraintParameterException[] |
217 | 217 | */ |
218 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
218 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
219 | 219 | $constraintParameters = $constraint->getConstraintParameters(); |
220 | 220 | try { |
221 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
222 | - } catch ( ConstraintParameterException $e ) { |
|
223 | - return [ $e ]; |
|
221 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
222 | + } catch (ConstraintParameterException $e) { |
|
223 | + return [$e]; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | $problems = []; |
227 | 227 | try { |
228 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
229 | - } catch ( ConstraintParameterException $e ) { |
|
228 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
229 | + } catch (ConstraintParameterException $e) { |
|
230 | 230 | $problems[] = $e; |
231 | 231 | } |
232 | 232 | try { |
233 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
234 | - } catch ( ConstraintParameterException $e ) { |
|
233 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
234 | + } catch (ConstraintParameterException $e) { |
|
235 | 235 | $problems[] = $e; |
236 | 236 | } |
237 | 237 | try { |
238 | 238 | $this->constraintParameterParser->parseConstraintScopeParameter( |
239 | 239 | $constraintParameters, |
240 | 240 | $constraint->getConstraintTypeItemId(), |
241 | - $this->getAllowedContextTypes( $constraint ) |
|
241 | + $this->getAllowedContextTypes($constraint) |
|
242 | 242 | ); |
243 | - } catch ( ConstraintParameterException $e ) { |
|
243 | + } catch (ConstraintParameterException $e) { |
|
244 | 244 | $problems[] = $e; |
245 | 245 | } |
246 | 246 | return $problems; |
@@ -253,16 +253,16 @@ discard block |
||
253 | 253 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
254 | 254 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
255 | 255 | */ |
256 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
257 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
256 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
257 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
258 | 258 | $result = []; |
259 | 259 | |
260 | - foreach ( $constraints as $constraint ) { |
|
261 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
260 | + foreach ($constraints as $constraint) { |
|
261 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
262 | 262 | |
263 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
263 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
264 | 264 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
265 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
265 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $result[$constraint->getConstraintId()] = $problems; |
@@ -279,17 +279,17 @@ discard block |
||
279 | 279 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
280 | 280 | * (empty means all parameters okay), or null if constraint is not found |
281 | 281 | */ |
282 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
283 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
284 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
282 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
283 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
284 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
285 | 285 | |
286 | - foreach ( $constraints as $constraint ) { |
|
287 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
288 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
286 | + foreach ($constraints as $constraint) { |
|
287 | + if ($constraint->getConstraintId() === $constraintId) { |
|
288 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
289 | 289 | |
290 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
290 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
291 | 291 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
292 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
292 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | return $problems; |
@@ -314,14 +314,14 @@ discard block |
||
314 | 314 | $result = []; |
315 | 315 | |
316 | 316 | /** @var Statement $statement */ |
317 | - foreach ( $entity->getStatements() as $statement ) { |
|
318 | - $result = array_merge( $result, |
|
317 | + foreach ($entity->getStatements() as $statement) { |
|
318 | + $result = array_merge($result, |
|
319 | 319 | $this->checkStatement( |
320 | 320 | $entity, |
321 | 321 | $statement, |
322 | 322 | $constraintIds, |
323 | 323 | $defaultResults |
324 | - ) ); |
|
324 | + )); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | return $result; |
@@ -343,32 +343,32 @@ discard block |
||
343 | 343 | ) { |
344 | 344 | $result = []; |
345 | 345 | |
346 | - $result = array_merge( $result, |
|
346 | + $result = array_merge($result, |
|
347 | 347 | $this->checkConstraintsForMainSnak( |
348 | 348 | $entity, |
349 | 349 | $statement, |
350 | 350 | $constraintIds, |
351 | 351 | $defaultResults |
352 | - ) ); |
|
352 | + )); |
|
353 | 353 | |
354 | - if ( $this->checkQualifiers ) { |
|
355 | - $result = array_merge( $result, |
|
354 | + if ($this->checkQualifiers) { |
|
355 | + $result = array_merge($result, |
|
356 | 356 | $this->checkConstraintsForQualifiers( |
357 | 357 | $entity, |
358 | 358 | $statement, |
359 | 359 | $constraintIds, |
360 | 360 | $defaultResults |
361 | - ) ); |
|
361 | + )); |
|
362 | 362 | } |
363 | 363 | |
364 | - if ( $this->checkReferences ) { |
|
365 | - $result = array_merge( $result, |
|
364 | + if ($this->checkReferences) { |
|
365 | + $result = array_merge($result, |
|
366 | 366 | $this->checkConstraintsForReferences( |
367 | 367 | $entity, |
368 | 368 | $statement, |
369 | 369 | $constraintIds, |
370 | 370 | $defaultResults |
371 | - ) ); |
|
371 | + )); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | return $result; |
@@ -383,12 +383,12 @@ discard block |
||
383 | 383 | * @param string[]|null $constraintIds |
384 | 384 | * @return Constraint[] |
385 | 385 | */ |
386 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
387 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
388 | - if ( $constraintIds !== null ) { |
|
386 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
387 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
388 | + if ($constraintIds !== null) { |
|
389 | 389 | $constraintsToUse = []; |
390 | - foreach ( $constraints as $constraint ) { |
|
391 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
390 | + foreach ($constraints as $constraint) { |
|
391 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
392 | 392 | $constraintsToUse[] = $constraint; |
393 | 393 | } |
394 | 394 | } |
@@ -412,29 +412,29 @@ discard block |
||
412 | 412 | array $constraintIds = null, |
413 | 413 | callable $defaultResults = null |
414 | 414 | ) { |
415 | - $context = new MainSnakContext( $entity, $statement ); |
|
415 | + $context = new MainSnakContext($entity, $statement); |
|
416 | 416 | $constraints = $this->getConstraintsToUse( |
417 | 417 | $statement->getPropertyId(), |
418 | 418 | $constraintIds |
419 | 419 | ); |
420 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
420 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
421 | 421 | |
422 | - foreach ( $constraints as $constraint ) { |
|
422 | + foreach ($constraints as $constraint) { |
|
423 | 423 | $parameters = $constraint->getConstraintParameters(); |
424 | 424 | try { |
425 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
426 | - } catch ( ConstraintParameterException $e ) { |
|
427 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
425 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
426 | + } catch (ConstraintParameterException $e) { |
|
427 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
428 | 428 | continue; |
429 | 429 | } |
430 | 430 | |
431 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
432 | - $message = wfMessage( 'wbqc-exception-message' )->escaped(); |
|
433 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
431 | + if (in_array($entity->getId(), $exceptions)) { |
|
432 | + $message = wfMessage('wbqc-exception-message')->escaped(); |
|
433 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
434 | 434 | continue; |
435 | 435 | } |
436 | 436 | |
437 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
437 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | return $result; |
@@ -456,24 +456,24 @@ discard block |
||
456 | 456 | ) { |
457 | 457 | $result = []; |
458 | 458 | |
459 | - if ( in_array( |
|
459 | + if (in_array( |
|
460 | 460 | $statement->getPropertyId()->getSerialization(), |
461 | 461 | $this->propertiesWithViolatingQualifiers |
462 | - ) ) { |
|
462 | + )) { |
|
463 | 463 | return $result; |
464 | 464 | } |
465 | 465 | |
466 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
467 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
468 | - if ( $defaultResults !== null ) { |
|
469 | - $result = array_merge( $result, $defaultResults( $qualifierContext ) ); |
|
466 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
467 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
468 | + if ($defaultResults !== null) { |
|
469 | + $result = array_merge($result, $defaultResults($qualifierContext)); |
|
470 | 470 | } |
471 | 471 | $qualifierConstraints = $this->getConstraintsToUse( |
472 | 472 | $qualifierContext->getSnak()->getPropertyId(), |
473 | 473 | $constraintIds |
474 | 474 | ); |
475 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
476 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
475 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
476 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
@@ -497,19 +497,19 @@ discard block |
||
497 | 497 | $result = []; |
498 | 498 | |
499 | 499 | /** @var Reference $reference */ |
500 | - foreach ( $statement->getReferences() as $reference ) { |
|
501 | - foreach ( $reference->getSnaks() as $snak ) { |
|
500 | + foreach ($statement->getReferences() as $reference) { |
|
501 | + foreach ($reference->getSnaks() as $snak) { |
|
502 | 502 | $referenceContext = new ReferenceContext( |
503 | 503 | $entity, $statement, $reference, $snak |
504 | 504 | ); |
505 | - if ( $defaultResults !== null ) { |
|
506 | - $result = array_merge( $result, $defaultResults( $referenceContext ) ); |
|
505 | + if ($defaultResults !== null) { |
|
506 | + $result = array_merge($result, $defaultResults($referenceContext)); |
|
507 | 507 | } |
508 | 508 | $referenceConstraints = $this->getConstraintsToUse( |
509 | 509 | $referenceContext->getSnak()->getPropertyId(), |
510 | 510 | $constraintIds |
511 | 511 | ); |
512 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
512 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
513 | 513 | $result[] = $this->getCheckResultFor( |
514 | 514 | $referenceContext, |
515 | 515 | $referenceConstraint |
@@ -528,65 +528,65 @@ discard block |
||
528 | 528 | * @throws InvalidArgumentException |
529 | 529 | * @return CheckResult |
530 | 530 | */ |
531 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
532 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
531 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
532 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
533 | 533 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
534 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
534 | + $result = $this->handleScope($checker, $context, $constraint); |
|
535 | 535 | |
536 | - if ( $result !== null ) { |
|
537 | - $this->addMetadata( $result ); |
|
536 | + if ($result !== null) { |
|
537 | + $this->addMetadata($result); |
|
538 | 538 | return $result; |
539 | 539 | } |
540 | 540 | |
541 | - $startTime = microtime( true ); |
|
541 | + $startTime = microtime(true); |
|
542 | 542 | try { |
543 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
544 | - } catch ( ConstraintParameterException $e ) { |
|
545 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
546 | - } catch ( SparqlHelperException $e ) { |
|
547 | - $message = wfMessage( 'wbqc-violation-message-sparql-error' )->escaped(); |
|
548 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
543 | + $result = $checker->checkConstraint($context, $constraint); |
|
544 | + } catch (ConstraintParameterException $e) { |
|
545 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
546 | + } catch (SparqlHelperException $e) { |
|
547 | + $message = wfMessage('wbqc-violation-message-sparql-error')->escaped(); |
|
548 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
549 | 549 | } |
550 | - $endTime = microtime( true ); |
|
550 | + $endTime = microtime(true); |
|
551 | 551 | |
552 | - $this->addMetadata( $result ); |
|
552 | + $this->addMetadata($result); |
|
553 | 553 | |
554 | 554 | try { |
555 | 555 | $constraintStatus = $this->constraintParameterParser |
556 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
557 | - } catch ( ConstraintParameterException $e ) { |
|
558 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
556 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
557 | + } catch (ConstraintParameterException $e) { |
|
558 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
559 | 559 | $constraintStatus = null; |
560 | 560 | } |
561 | - if ( $constraintStatus === null ) { |
|
561 | + if ($constraintStatus === null) { |
|
562 | 562 | // downgrade violation to warning |
563 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
564 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
563 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
564 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
565 | 565 | } |
566 | 566 | } else { |
567 | - if ( $constraintStatus !== 'mandatory' ) { |
|
567 | + if ($constraintStatus !== 'mandatory') { |
|
568 | 568 | // @codeCoverageIgnoreStart |
569 | 569 | throw new LogicException( |
570 | - "Unknown constraint status '$constraintStatus', " . |
|
570 | + "Unknown constraint status '$constraintStatus', ". |
|
571 | 571 | "only known status is 'mandatory'" |
572 | 572 | ); |
573 | 573 | // @codeCoverageIgnoreEnd |
574 | 574 | } |
575 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
575 | + $result->addParameter('constraint_status', $constraintStatus); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | $this->loggingHelper->logConstraintCheck( |
579 | 579 | $context, |
580 | 580 | $constraint, |
581 | 581 | $result, |
582 | - get_class( $checker ), |
|
582 | + get_class($checker), |
|
583 | 583 | $endTime - $startTime, |
584 | 584 | __METHOD__ |
585 | 585 | ); |
586 | 586 | |
587 | 587 | return $result; |
588 | 588 | } else { |
589 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
589 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
590 | 590 | } |
591 | 591 | } |
592 | 592 | |
@@ -600,29 +600,29 @@ discard block |
||
600 | 600 | $constraint->getConstraintParameters(), |
601 | 601 | $constraint->getConstraintTypeItemId() |
602 | 602 | ); |
603 | - } catch ( ConstraintParameterException $e ) { |
|
604 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
603 | + } catch (ConstraintParameterException $e) { |
|
604 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
605 | 605 | } |
606 | - if ( $checkedContextTypes === null ) { |
|
606 | + if ($checkedContextTypes === null) { |
|
607 | 607 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
608 | 608 | } |
609 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
610 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
609 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
610 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
611 | 611 | } |
612 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
613 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
612 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
613 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
614 | 614 | } |
615 | 615 | return null; |
616 | 616 | } |
617 | 617 | |
618 | - private function addMetadata( CheckResult $result ) { |
|
619 | - $result->withMetadata( Metadata::merge( [ |
|
618 | + private function addMetadata(CheckResult $result) { |
|
619 | + $result->withMetadata(Metadata::merge([ |
|
620 | 620 | $result->getMetadata(), |
621 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
622 | - DependencyMetadata::ofEntityId( $result->getEntityId() ), |
|
623 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
624 | - ] ) ), |
|
625 | - ] ) ); |
|
621 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
622 | + DependencyMetadata::ofEntityId($result->getEntityId()), |
|
623 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
624 | + ])), |
|
625 | + ])); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | /** |
@@ -630,12 +630,12 @@ discard block |
||
630 | 630 | * |
631 | 631 | * @return CheckResult[] |
632 | 632 | */ |
633 | - private function sortResult( array $result ) { |
|
634 | - if ( count( $result ) < 2 ) { |
|
633 | + private function sortResult(array $result) { |
|
634 | + if (count($result) < 2) { |
|
635 | 635 | return $result; |
636 | 636 | } |
637 | 637 | |
638 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
638 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
639 | 639 | $orderNum = 0; |
640 | 640 | $order = [ |
641 | 641 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -651,45 +651,45 @@ discard block |
||
651 | 651 | $statusA = $a->getStatus(); |
652 | 652 | $statusB = $b->getStatus(); |
653 | 653 | |
654 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
655 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
654 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
655 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
656 | 656 | |
657 | - if ( $orderA === $orderB ) { |
|
657 | + if ($orderA === $orderB) { |
|
658 | 658 | $pidA = $a->getContext()->getSnak()->getPropertyId()->getSerialization(); |
659 | 659 | $pidB = $b->getContext()->getSnak()->getPropertyId()->getSerialization(); |
660 | 660 | |
661 | - if ( $pidA === $pidB ) { |
|
661 | + if ($pidA === $pidB) { |
|
662 | 662 | $hashA = $a->getContext()->getSnak()->getHash(); |
663 | 663 | $hashB = $b->getContext()->getSnak()->getHash(); |
664 | 664 | |
665 | - if ( $hashA === $hashB ) { |
|
666 | - if ( $a instanceof NullResult ) { |
|
665 | + if ($hashA === $hashB) { |
|
666 | + if ($a instanceof NullResult) { |
|
667 | 667 | return $b instanceof NullResult ? 0 : -1; |
668 | 668 | } |
669 | - if ( $b instanceof NullResult ) { |
|
669 | + if ($b instanceof NullResult) { |
|
670 | 670 | return $a instanceof NullResult ? 0 : 1; |
671 | 671 | } |
672 | 672 | |
673 | 673 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
674 | 674 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
675 | 675 | |
676 | - if ( $typeA == $typeB ) { |
|
676 | + if ($typeA == $typeB) { |
|
677 | 677 | return 0; |
678 | 678 | } else { |
679 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
679 | + return ($typeA > $typeB) ? 1 : -1; |
|
680 | 680 | } |
681 | 681 | } else { |
682 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
682 | + return ($hashA > $hashB) ? 1 : -1; |
|
683 | 683 | } |
684 | 684 | } else { |
685 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
685 | + return ($pidA > $pidB) ? 1 : -1; |
|
686 | 686 | } |
687 | 687 | } else { |
688 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
688 | + return ($orderA > $orderB) ? 1 : -1; |
|
689 | 689 | } |
690 | 690 | }; |
691 | 691 | |
692 | - uasort( $result, $sortFunction ); |
|
692 | + uasort($result, $sortFunction); |
|
693 | 693 | |
694 | 694 | return $result; |
695 | 695 | } |
@@ -119,8 +119,8 @@ |
||
119 | 119 | * for quantity values, the difference is the numerical difference between the quantities, |
120 | 120 | * after attempting normalization of each side. |
121 | 121 | * |
122 | - * @param TimeValue|QuantityValue|UnboundedQuantityValue $minuend |
|
123 | - * @param TimeValue|QuantityValue|UnboundedQuantityValue $subtrahend |
|
122 | + * @param DataValue $minuend |
|
123 | + * @param DataValue $subtrahend |
|
124 | 124 | * |
125 | 125 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
126 | 126 | * @return UnboundedQuantityValue |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | UnitConverter $unitConverter = null |
48 | 48 | ) { |
49 | 49 | $this->config = $config; |
50 | - $this->timeParser = ( new TimeParserFactory() )->getTimeParser(); |
|
50 | + $this->timeParser = (new TimeParserFactory())->getTimeParser(); |
|
51 | 51 | $this->timeCalculator = new TimeValueCalculator(); |
52 | 52 | $this->unitConverter = $unitConverter; |
53 | 53 | } |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | * @param UnboundedQuantityValue $value |
57 | 57 | * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value. |
58 | 58 | */ |
59 | - private function standardize( UnboundedQuantityValue $value ) { |
|
60 | - if ( $this->unitConverter !== null ) { |
|
61 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
62 | - if ( $standard !== null ) { |
|
59 | + private function standardize(UnboundedQuantityValue $value) { |
|
60 | + if ($this->unitConverter !== null) { |
|
61 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
62 | + if ($standard !== null) { |
|
63 | 63 | return $standard; |
64 | 64 | } else { |
65 | 65 | return $value; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | * when $lhs is respectively less than, equal to, or greater than $rhs. |
82 | 82 | * (In other words, just like the “spaceship” operator <=>.) |
83 | 83 | */ |
84 | - public function getComparison( DataValue $lhs = null, DataValue $rhs = null ) { |
|
85 | - if ( $lhs === null || $rhs === null ) { |
|
84 | + public function getComparison(DataValue $lhs = null, DataValue $rhs = null) { |
|
85 | + if ($lhs === null || $rhs === null) { |
|
86 | 86 | return 0; |
87 | 87 | } |
88 | 88 | |
89 | - if ( $lhs->getType() !== $rhs->getType() ) { |
|
90 | - throw new InvalidArgumentException( 'Different data value types' ); |
|
89 | + if ($lhs->getType() !== $rhs->getType()) { |
|
90 | + throw new InvalidArgumentException('Different data value types'); |
|
91 | 91 | } |
92 | 92 | |
93 | - switch ( $lhs->getType() ) { |
|
93 | + switch ($lhs->getType()) { |
|
94 | 94 | case 'time': |
95 | 95 | /** @var TimeValue $lhs */ |
96 | 96 | /** @var TimeValue $rhs */ |
97 | - $lhsTimestamp = $this->timeCalculator->getTimestamp( $lhs ); |
|
98 | - $rhsTimestamp = $this->timeCalculator->getTimestamp( $rhs ); |
|
97 | + $lhsTimestamp = $this->timeCalculator->getTimestamp($lhs); |
|
98 | + $rhsTimestamp = $this->timeCalculator->getTimestamp($rhs); |
|
99 | 99 | |
100 | - if ( $lhsTimestamp === $rhsTimestamp ) { |
|
100 | + if ($lhsTimestamp === $rhsTimestamp) { |
|
101 | 101 | return 0; |
102 | 102 | } |
103 | 103 | |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | case 'quantity': |
106 | 106 | /** @var QuantityValue|UnboundedQuantityValue $lhs */ |
107 | 107 | /** @var QuantityValue|UnboundedQuantityValue $rhs */ |
108 | - $lhsStandard = $this->standardize( $lhs ); |
|
109 | - $rhsStandard = $this->standardize( $rhs ); |
|
110 | - return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() ); |
|
108 | + $lhsStandard = $this->standardize($lhs); |
|
109 | + $rhsStandard = $this->standardize($rhs); |
|
110 | + return $lhsStandard->getAmount()->compare($rhsStandard->getAmount()); |
|
111 | 111 | } |
112 | 112 | |
113 | - throw new InvalidArgumentException( 'Unsupported data value type' ); |
|
113 | + throw new InvalidArgumentException('Unsupported data value type'); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -125,83 +125,83 @@ discard block |
||
125 | 125 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
126 | 126 | * @return UnboundedQuantityValue |
127 | 127 | */ |
128 | - public function getDifference( DataValue $minuend, DataValue $subtrahend ) { |
|
129 | - if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) { |
|
130 | - $minuendSeconds = $this->timeCalculator->getTimestamp( $minuend ); |
|
131 | - $subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend ); |
|
128 | + public function getDifference(DataValue $minuend, DataValue $subtrahend) { |
|
129 | + if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') { |
|
130 | + $minuendSeconds = $this->timeCalculator->getTimestamp($minuend); |
|
131 | + $subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend); |
|
132 | 132 | return UnboundedQuantityValue::newFromNumber( |
133 | 133 | $minuendSeconds - $subtrahendSeconds, |
134 | - $this->config->get( 'WBQualityConstraintsSecondUnit' ) |
|
134 | + $this->config->get('WBQualityConstraintsSecondUnit') |
|
135 | 135 | ); |
136 | 136 | } |
137 | - if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) { |
|
138 | - $minuendStandard = $this->standardize( $minuend ); |
|
139 | - $subtrahendStandard = $this->standardize( $subtrahend ); |
|
137 | + if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') { |
|
138 | + $minuendStandard = $this->standardize($minuend); |
|
139 | + $subtrahendStandard = $this->standardize($subtrahend); |
|
140 | 140 | $minuendValue = $minuendStandard->getAmount()->getValueFloat(); |
141 | 141 | $subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat(); |
142 | 142 | $diff = $minuendValue - $subtrahendValue; |
143 | 143 | // we don’t check whether both quantities have the same standard unit – |
144 | 144 | // that’s the job of a different constraint type, Units (T164372) |
145 | - return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() ); |
|
145 | + return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit()); |
|
146 | 146 | } |
147 | 147 | |
148 | - throw new InvalidArgumentException( 'Unsupported or different data value types' ); |
|
148 | + throw new InvalidArgumentException('Unsupported or different data value types'); |
|
149 | 149 | } |
150 | 150 | |
151 | - public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ) { |
|
152 | - if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) || |
|
153 | - !preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches ) |
|
151 | + public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend) { |
|
152 | + if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) || |
|
153 | + !preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches) |
|
154 | 154 | ) { |
155 | - throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' ); |
|
155 | + throw new InvalidArgumentException('TimeValue::getTime() did not match expected format'); |
|
156 | 156 | } |
157 | - $minuendYear = (float)$minuendMatches[1]; |
|
158 | - $subtrahendYear = (float)$subtrahendMatches[1]; |
|
157 | + $minuendYear = (float) $minuendMatches[1]; |
|
158 | + $subtrahendYear = (float) $subtrahendMatches[1]; |
|
159 | 159 | $minuendRest = $minuendMatches[2]; |
160 | 160 | $subtrahendRest = $subtrahendMatches[2]; |
161 | 161 | |
162 | 162 | // calculate difference of years |
163 | 163 | $diff = $minuendYear - $subtrahendYear; |
164 | - if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) { |
|
164 | + if ($minuendYear > 0.0 && $subtrahendYear < 0.0) { |
|
165 | 165 | $diff -= 1.0; // there is no year 0, remove it from difference |
166 | - } elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) { |
|
166 | + } elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) { |
|
167 | 167 | $diff -= -1.0; // there is no year 0, remove it from negative difference |
168 | 168 | } |
169 | 169 | |
170 | 170 | // adjust for date within year by parsing the month-day part within the same year |
171 | - $minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest ); |
|
172 | - $subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest ); |
|
173 | - $minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue ); |
|
174 | - $subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue ); |
|
175 | - if ( $minuendDateSeconds < $subtrahendDateSeconds ) { |
|
171 | + $minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest); |
|
172 | + $subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest); |
|
173 | + $minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue); |
|
174 | + $subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue); |
|
175 | + if ($minuendDateSeconds < $subtrahendDateSeconds) { |
|
176 | 176 | // difference in the last year is actually less than one full year |
177 | 177 | // e. g. 1975-03-01 - 1974-09-01 is just six months |
178 | 178 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
179 | 179 | $diff -= 0.5; |
180 | - } elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) { |
|
180 | + } elseif ($minuendDateSeconds > $subtrahendDateSeconds) { |
|
181 | 181 | // difference in the last year is actually more than one full year |
182 | 182 | // e. g. 1975-09-01 - 1974-03-01 is 18 months |
183 | 183 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
184 | 184 | $diff += 0.5; |
185 | 185 | } |
186 | 186 | |
187 | - $unit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
188 | - return UnboundedQuantityValue::newFromNumber( $diff, $unit ); |
|
187 | + $unit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
188 | + return UnboundedQuantityValue::newFromNumber($diff, $unit); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param string $timeString |
193 | 193 | * @return TimeValue |
194 | 194 | */ |
195 | - public function parseTime( $timeString ) { |
|
196 | - return $this->timeParser->parse( $timeString ); |
|
195 | + public function parseTime($timeString) { |
|
196 | + return $this->timeParser->parse($timeString); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
200 | 200 | * @param string $quantityString |
201 | 201 | * @return QuantityValue|UnboundedQuantityValue |
202 | 202 | */ |
203 | - public function parseQuantity( $quantityString ) { |
|
204 | - return UnboundedQuantityValue::newFromNumber( $quantityString ); |
|
203 | + public function parseQuantity($quantityString) { |
|
204 | + return UnboundedQuantityValue::newFromNumber($quantityString); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | } |
@@ -162,7 +162,7 @@ |
||
162 | 162 | /** |
163 | 163 | * Returns array of modules that should be added |
164 | 164 | * |
165 | - * @return array |
|
165 | + * @return string[] |
|
166 | 166 | */ |
167 | 167 | private function getModules() { |
168 | 168 | return [ 'SpecialConstraintReportPage' ]; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | Config $config, |
140 | 140 | IBufferingStatsdDataFactory $dataFactory |
141 | 141 | ) { |
142 | - parent::__construct( 'ConstraintReport' ); |
|
142 | + parent::__construct('ConstraintReport'); |
|
143 | 143 | |
144 | 144 | $this->entityLookup = $entityLookup; |
145 | 145 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | $language = $this->getLanguage(); |
149 | 149 | |
150 | 150 | $formatterOptions = new FormatterOptions(); |
151 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
151 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
152 | 152 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
153 | 153 | SnakFormatter::FORMAT_HTML, |
154 | 154 | $formatterOptions |
155 | 155 | ); |
156 | 156 | |
157 | - $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup( $language ); |
|
157 | + $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup($language); |
|
158 | 158 | |
159 | 159 | $this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( |
160 | 160 | $labelLookup |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return array |
183 | 183 | */ |
184 | 184 | private function getModules() { |
185 | - return [ 'SpecialConstraintReportPage' ]; |
|
185 | + return ['SpecialConstraintReportPage']; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @return string |
201 | 201 | */ |
202 | 202 | public function getDescription() { |
203 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
203 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -212,42 +212,42 @@ discard block |
||
212 | 212 | * @throws EntityIdParsingException |
213 | 213 | * @throws UnexpectedValueException |
214 | 214 | */ |
215 | - public function execute( $subPage ) { |
|
215 | + public function execute($subPage) { |
|
216 | 216 | $out = $this->getOutput(); |
217 | 217 | |
218 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
219 | - if ( $postRequest ) { |
|
220 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
218 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
219 | + if ($postRequest) { |
|
220 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
221 | 221 | return; |
222 | 222 | } |
223 | 223 | |
224 | - $out->addModules( $this->getModules() ); |
|
224 | + $out->addModules($this->getModules()); |
|
225 | 225 | |
226 | 226 | $this->setHeaders(); |
227 | 227 | |
228 | - $out->addHTML( $this->getExplanationText() ); |
|
228 | + $out->addHTML($this->getExplanationText()); |
|
229 | 229 | $this->buildEntityIdForm(); |
230 | 230 | |
231 | - if ( !$subPage ) { |
|
231 | + if (!$subPage) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - if ( !is_string( $subPage ) ) { |
|
236 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
235 | + if (!is_string($subPage)) { |
|
236 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | try { |
240 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
241 | - } catch ( EntityIdParsingException $e ) { |
|
240 | + $entityId = $this->entityIdParser->parse($subPage); |
|
241 | + } catch (EntityIdParsingException $e) { |
|
242 | 242 | $out->addHTML( |
243 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
243 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
244 | 244 | ); |
245 | 245 | return; |
246 | 246 | } |
247 | 247 | |
248 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
248 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
249 | 249 | $out->addHTML( |
250 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
250 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
251 | 251 | ); |
252 | 252 | return; |
253 | 253 | } |
@@ -255,18 +255,18 @@ discard block |
||
255 | 255 | $this->dataFactory->increment( |
256 | 256 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
257 | 257 | ); |
258 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
258 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
259 | 259 | |
260 | - if ( count( $results ) > 0 ) { |
|
260 | + if (count($results) > 0) { |
|
261 | 261 | $out->addHTML( |
262 | - $this->buildResultHeader( $entityId ) |
|
263 | - . $this->buildSummary( $results ) |
|
264 | - . $this->buildResultTable( $entityId, $results ) |
|
262 | + $this->buildResultHeader($entityId) |
|
263 | + . $this->buildSummary($results) |
|
264 | + . $this->buildResultTable($entityId, $results) |
|
265 | 265 | ); |
266 | 266 | } else { |
267 | 267 | $out->addHTML( |
268 | - $this->buildResultHeader( $entityId ) |
|
269 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
268 | + $this->buildResultHeader($entityId) |
|
269 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
270 | 270 | ); |
271 | 271 | } |
272 | 272 | } |
@@ -282,15 +282,15 @@ discard block |
||
282 | 282 | 'name' => 'entityid', |
283 | 283 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
284 | 284 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
285 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
285 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
286 | 286 | ] |
287 | 287 | ]; |
288 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
289 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
290 | - $htmlForm->setSubmitCallback( function() { |
|
288 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
289 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
290 | + $htmlForm->setSubmitCallback(function() { |
|
291 | 291 | return false; |
292 | 292 | } ); |
293 | - $htmlForm->setMethod( 'post' ); |
|
293 | + $htmlForm->setMethod('post'); |
|
294 | 294 | $htmlForm->show(); |
295 | 295 | } |
296 | 296 | |
@@ -304,16 +304,16 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return string HTML |
306 | 306 | */ |
307 | - private function buildNotice( $messageKey, $error = false ) { |
|
308 | - if ( !is_string( $messageKey ) ) { |
|
309 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
307 | + private function buildNotice($messageKey, $error = false) { |
|
308 | + if (!is_string($messageKey)) { |
|
309 | + throw new InvalidArgumentException('$message must be string.'); |
|
310 | 310 | } |
311 | - if ( !is_bool( $error ) ) { |
|
312 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
311 | + if (!is_bool($error)) { |
|
312 | + throw new InvalidArgumentException('$error must be bool.'); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | $cssClasses = 'wbqc-constraintreport-notice'; |
316 | - if ( $error ) { |
|
316 | + if ($error) { |
|
317 | 317 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
318 | 318 | } |
319 | 319 | |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | [ |
323 | 323 | 'class' => $cssClasses |
324 | 324 | ], |
325 | - $this->msg( $messageKey )->escaped() |
|
325 | + $this->msg($messageKey)->escaped() |
|
326 | 326 | ); |
327 | 327 | } |
328 | 328 | |
@@ -332,16 +332,16 @@ discard block |
||
332 | 332 | private function getExplanationText() { |
333 | 333 | return Html::rawElement( |
334 | 334 | 'div', |
335 | - [ 'class' => 'wbqc-explanation' ], |
|
335 | + ['class' => 'wbqc-explanation'], |
|
336 | 336 | Html::rawElement( |
337 | 337 | 'p', |
338 | 338 | [], |
339 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
339 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
340 | 340 | ) |
341 | 341 | . Html::rawElement( |
342 | 342 | 'p', |
343 | 343 | [], |
344 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
344 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
345 | 345 | ) |
346 | 346 | ); |
347 | 347 | } |
@@ -352,69 +352,69 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @return string HTML |
354 | 354 | */ |
355 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
355 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
356 | 356 | // Set table headers |
357 | 357 | $table = new HtmlTableBuilder( |
358 | 358 | [ |
359 | 359 | new HtmlTableHeaderBuilder( |
360 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
360 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
361 | 361 | true |
362 | 362 | ), |
363 | 363 | new HtmlTableHeaderBuilder( |
364 | - $this->msg( 'wbqc-constraintreport-result-table-header-claim' )->escaped(), |
|
364 | + $this->msg('wbqc-constraintreport-result-table-header-claim')->escaped(), |
|
365 | 365 | true |
366 | 366 | ), |
367 | 367 | new HtmlTableHeaderBuilder( |
368 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
368 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
369 | 369 | true |
370 | 370 | ) |
371 | 371 | ] |
372 | 372 | ); |
373 | 373 | |
374 | - foreach ( $results as $result ) { |
|
375 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
374 | + foreach ($results as $result) { |
|
375 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | return $table->toHtml(); |
379 | 379 | } |
380 | 380 | |
381 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
381 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
382 | 382 | // Status column |
383 | 383 | $statusColumn = $this->buildTooltipElement( |
384 | - $this->formatStatus( $result->getStatus() ), |
|
384 | + $this->formatStatus($result->getStatus()), |
|
385 | 385 | $result->getMessage(), |
386 | 386 | '[?]' |
387 | 387 | ); |
388 | 388 | |
389 | 389 | // Claim column |
390 | - $property = $this->entityIdLabelFormatter->formatEntityId( $result->getContext()->getSnak()->getPropertyId() ); |
|
391 | - if ( $result->getSnakType() === 'value' ) { |
|
392 | - $value = $this->constraintParameterRenderer->formatValue( $result->getDataValue() ); |
|
390 | + $property = $this->entityIdLabelFormatter->formatEntityId($result->getContext()->getSnak()->getPropertyId()); |
|
391 | + if ($result->getSnakType() === 'value') { |
|
392 | + $value = $this->constraintParameterRenderer->formatValue($result->getDataValue()); |
|
393 | 393 | } else { |
394 | - $value = htmlspecialchars( $result->getSnakType() ); |
|
394 | + $value = htmlspecialchars($result->getSnakType()); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | $claimColumn = $this->getClaimLink( |
398 | 398 | $entityId, |
399 | 399 | $result->getContext()->getSnak()->getPropertyId(), |
400 | - $property . ': ' . $value |
|
400 | + $property.': '.$value |
|
401 | 401 | ); |
402 | 402 | |
403 | 403 | // Constraint column |
404 | 404 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
405 | 405 | try { |
406 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
407 | - } catch ( InvalidArgumentException $e ) { |
|
408 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
406 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
407 | + } catch (InvalidArgumentException $e) { |
|
408 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
409 | 409 | } |
410 | 410 | $constraintLink = $this->getClaimLink( |
411 | 411 | $result->getContext()->getSnak()->getPropertyId(), |
412 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
412 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
413 | 413 | $constraintTypeLabel |
414 | 414 | ); |
415 | 415 | $constraintColumn = $this->buildExpandableElement( |
416 | 416 | $constraintLink, |
417 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
417 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
418 | 418 | '[...]' |
419 | 419 | ); |
420 | 420 | |
@@ -449,15 +449,15 @@ discard block |
||
449 | 449 | * |
450 | 450 | * @return string HTML |
451 | 451 | */ |
452 | - protected function buildResultHeader( EntityId $entityId ) { |
|
453 | - $entityLink = sprintf( '%s (%s)', |
|
454 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
455 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
452 | + protected function buildResultHeader(EntityId $entityId) { |
|
453 | + $entityLink = sprintf('%s (%s)', |
|
454 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
455 | + htmlspecialchars($entityId->getSerialization())); |
|
456 | 456 | |
457 | 457 | return Html::rawElement( |
458 | 458 | 'h3', |
459 | 459 | [], |
460 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
460 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
461 | 461 | ); |
462 | 462 | } |
463 | 463 | |
@@ -468,24 +468,24 @@ discard block |
||
468 | 468 | * |
469 | 469 | * @return string HTML |
470 | 470 | */ |
471 | - protected function buildSummary( array $results ) { |
|
471 | + protected function buildSummary(array $results) { |
|
472 | 472 | $statuses = []; |
473 | - foreach ( $results as $result ) { |
|
474 | - $status = strtolower( $result->getStatus() ); |
|
475 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
473 | + foreach ($results as $result) { |
|
474 | + $status = strtolower($result->getStatus()); |
|
475 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | $statusElements = []; |
479 | - foreach ( $statuses as $status => $count ) { |
|
480 | - if ( $count > 0 ) { |
|
479 | + foreach ($statuses as $status => $count) { |
|
480 | + if ($count > 0) { |
|
481 | 481 | $statusElements[] = |
482 | - $this->formatStatus( $status ) |
|
482 | + $this->formatStatus($status) |
|
483 | 483 | . ': ' |
484 | 484 | . $count; |
485 | 485 | } |
486 | 486 | } |
487 | 487 | |
488 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
488 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | /** |
@@ -500,15 +500,15 @@ discard block |
||
500 | 500 | * |
501 | 501 | * @return string HTML |
502 | 502 | */ |
503 | - protected function buildTooltipElement( $content, $tooltipContent, $indicator ) { |
|
504 | - if ( !is_string( $content ) ) { |
|
505 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
503 | + protected function buildTooltipElement($content, $tooltipContent, $indicator) { |
|
504 | + if (!is_string($content)) { |
|
505 | + throw new InvalidArgumentException('$content has to be string.'); |
|
506 | 506 | } |
507 | - if ( $tooltipContent && ( !is_string( $tooltipContent ) ) ) { |
|
508 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
507 | + if ($tooltipContent && (!is_string($tooltipContent))) { |
|
508 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
509 | 509 | } |
510 | 510 | |
511 | - if ( empty( $tooltipContent ) ) { |
|
511 | + if (empty($tooltipContent)) { |
|
512 | 512 | return $content; |
513 | 513 | } |
514 | 514 | |
@@ -525,13 +525,13 @@ discard block |
||
525 | 525 | [ |
526 | 526 | 'class' => 'wbqc-indicator' |
527 | 527 | ], |
528 | - htmlspecialchars( $indicator ) . $tooltip |
|
528 | + htmlspecialchars($indicator).$tooltip |
|
529 | 529 | ); |
530 | 530 | |
531 | 531 | return Html::rawElement( |
532 | 532 | 'span', |
533 | 533 | [], |
534 | - sprintf( '%s %s', $content, $tooltipIndicator ) |
|
534 | + sprintf('%s %s', $content, $tooltipIndicator) |
|
535 | 535 | ); |
536 | 536 | } |
537 | 537 | |
@@ -547,15 +547,15 @@ discard block |
||
547 | 547 | * |
548 | 548 | * @return string HTML |
549 | 549 | */ |
550 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
551 | - if ( !is_string( $content ) ) { |
|
552 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
550 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
551 | + if (!is_string($content)) { |
|
552 | + throw new InvalidArgumentException('$content has to be string.'); |
|
553 | 553 | } |
554 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
555 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
554 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
555 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
556 | 556 | } |
557 | 557 | |
558 | - if ( empty( $expandableContent ) ) { |
|
558 | + if (empty($expandableContent)) { |
|
559 | 559 | return $content; |
560 | 560 | } |
561 | 561 | |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | ); |
577 | 577 | |
578 | 578 | return |
579 | - sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent ); |
|
579 | + sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | /** |
@@ -588,16 +588,16 @@ discard block |
||
588 | 588 | * |
589 | 589 | * @return string HTML |
590 | 590 | */ |
591 | - private function formatStatus( $status ) { |
|
592 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
591 | + private function formatStatus($status) { |
|
592 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
593 | 593 | |
594 | 594 | $formattedStatus = |
595 | 595 | Html::element( |
596 | 596 | 'span', |
597 | 597 | [ |
598 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
598 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
599 | 599 | ], |
600 | - $this->msg( $messageName )->text() |
|
600 | + $this->msg($messageName)->text() |
|
601 | 601 | ); |
602 | 602 | |
603 | 603 | return $formattedStatus; |
@@ -613,26 +613,26 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @return string HTML |
615 | 615 | */ |
616 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
617 | - if ( $dataValues instanceof DataValue ) { |
|
618 | - $dataValues = [ $dataValues ]; |
|
619 | - } elseif ( !is_array( $dataValues ) ) { |
|
620 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
616 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
617 | + if ($dataValues instanceof DataValue) { |
|
618 | + $dataValues = [$dataValues]; |
|
619 | + } elseif (!is_array($dataValues)) { |
|
620 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | $formattedDataValues = []; |
624 | - foreach ( $dataValues as $dataValue ) { |
|
625 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
626 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
624 | + foreach ($dataValues as $dataValue) { |
|
625 | + if (!($dataValue instanceof DataValue)) { |
|
626 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
627 | 627 | } |
628 | - if ( $dataValue instanceof EntityIdValue ) { |
|
629 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
628 | + if ($dataValue instanceof EntityIdValue) { |
|
629 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
630 | 630 | } else { |
631 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
631 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
632 | 632 | } |
633 | 633 | } |
634 | 634 | |
635 | - return implode( $separator, $formattedDataValues ); |
|
635 | + return implode($separator, $formattedDataValues); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
@@ -644,12 +644,12 @@ discard block |
||
644 | 644 | * |
645 | 645 | * @return string HTML |
646 | 646 | */ |
647 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
647 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
648 | 648 | return |
649 | 649 | Html::rawElement( |
650 | 650 | 'a', |
651 | 651 | [ |
652 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
652 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
653 | 653 | 'target' => '_blank' |
654 | 654 | ], |
655 | 655 | $text |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | * |
665 | 665 | * @return string |
666 | 666 | */ |
667 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
668 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
669 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
667 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
668 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
669 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
670 | 670 | |
671 | 671 | return $entityUrl; |
672 | 672 | } |
@@ -14,6 +14,6 @@ |
||
14 | 14 | * |
15 | 15 | * @return Constraint[] |
16 | 16 | */ |
17 | - public function queryConstraintsForProperty( PropertyId $propertyId ); |
|
17 | + public function queryConstraintsForProperty(PropertyId $propertyId); |
|
18 | 18 | |
19 | 19 | } |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return Constraint[] |
22 | 22 | */ |
23 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
24 | - $db = wfGetDB( DB_REPLICA ); |
|
23 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
24 | + $db = wfGetDB(DB_REPLICA); |
|
25 | 25 | |
26 | 26 | $results = $db->select( |
27 | 27 | 'wbqc_constraints', |
28 | 28 | '*', |
29 | - [ 'pid' => $propertyId->getNumericId() ] |
|
29 | + ['pid' => $propertyId->getNumericId()] |
|
30 | 30 | ); |
31 | 31 | |
32 | - return $this->convertToConstraints( $results ); |
|
32 | + return $this->convertToConstraints($results); |
|
33 | 33 | } |
34 | 34 | |
35 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
36 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
35 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
36 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
37 | 37 | |
38 | - if ( strlen( $json ) > 50000 ) { |
|
39 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
38 | + if (strlen($json) > 50000) { |
|
39 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | return $json; |
@@ -48,21 +48,21 @@ discard block |
||
48 | 48 | * @throws DBUnexpectedError |
49 | 49 | * @return bool |
50 | 50 | */ |
51 | - public function insertBatch( array $constraints ) { |
|
51 | + public function insertBatch(array $constraints) { |
|
52 | 52 | $accumulator = array_map( |
53 | - function ( Constraint $constraint ) { |
|
53 | + function(Constraint $constraint) { |
|
54 | 54 | return [ |
55 | 55 | 'constraint_guid' => $constraint->getConstraintId(), |
56 | 56 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
57 | 57 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
58 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
58 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
59 | 59 | ]; |
60 | 60 | }, |
61 | 61 | $constraints |
62 | 62 | ); |
63 | 63 | |
64 | - $db = wfGetDB( DB_MASTER ); |
|
65 | - return $db->insert( 'wbqc_constraints', $accumulator ); |
|
64 | + $db = wfGetDB(DB_MASTER); |
|
65 | + return $db->insert('wbqc_constraints', $accumulator); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return array |
72 | 72 | */ |
73 | - private function uuidPattern( LikeMatch $any ) { |
|
73 | + private function uuidPattern(LikeMatch $any) { |
|
74 | 74 | return array_merge( |
75 | - array_fill( 0, 8, $any ), [ '-' ], |
|
76 | - array_fill( 0, 4, $any ), [ '-' ], |
|
77 | - array_fill( 0, 4, $any ), [ '-' ], |
|
78 | - array_fill( 0, 4, $any ), [ '-' ], |
|
79 | - array_fill( 0, 12, $any ) |
|
75 | + array_fill(0, 8, $any), ['-'], |
|
76 | + array_fill(0, 4, $any), ['-'], |
|
77 | + array_fill(0, 4, $any), ['-'], |
|
78 | + array_fill(0, 4, $any), ['-'], |
|
79 | + array_fill(0, 12, $any) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | * @throws DBUnexpectedError |
88 | 88 | */ |
89 | 89 | public function deleteWhereConstraintIdIsUuid() { |
90 | - $db = wfGetDB( DB_MASTER ); |
|
90 | + $db = wfGetDB(DB_MASTER); |
|
91 | 91 | $db->delete( |
92 | 92 | 'wbqc_constraints', |
93 | 93 | // WHERE constraint_guid LIKE ________-____-____-____-____________ |
94 | - 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) |
|
94 | + 'constraint_guid '.$db->buildLike($this->uuidPattern($db->anyChar())) |
|
95 | 95 | ); |
96 | 96 | } |
97 | 97 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @throws DBUnexpectedError |
103 | 103 | */ |
104 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
105 | - $db = wfGetDB( DB_MASTER ); |
|
104 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
105 | + $db = wfGetDB(DB_MASTER); |
|
106 | 106 | $db->delete( |
107 | 107 | 'wbqc_constraints', |
108 | 108 | [ |
109 | 109 | 'pid' => $propertyId->getNumericId(), |
110 | 110 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
111 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
111 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
112 | 112 | ] |
113 | 113 | ); |
114 | 114 | } |
@@ -119,20 +119,20 @@ discard block |
||
119 | 119 | * @throws InvalidArgumentException |
120 | 120 | * @throws DBUnexpectedError |
121 | 121 | */ |
122 | - public function deleteAll( $batchSize = 1000 ) { |
|
123 | - if ( !is_int( $batchSize ) ) { |
|
122 | + public function deleteAll($batchSize = 1000) { |
|
123 | + if (!is_int($batchSize)) { |
|
124 | 124 | throw new InvalidArgumentException(); |
125 | 125 | } |
126 | - $db = wfGetDB( DB_MASTER ); |
|
127 | - if ( $db->getType() === 'sqlite' ) { |
|
128 | - $db->delete( 'wbqc_constraints', '*' ); |
|
126 | + $db = wfGetDB(DB_MASTER); |
|
127 | + if ($db->getType() === 'sqlite') { |
|
128 | + $db->delete('wbqc_constraints', '*'); |
|
129 | 129 | } else { |
130 | 130 | do { |
131 | - $db->commit( __METHOD__, 'flush' ); |
|
131 | + $db->commit(__METHOD__, 'flush'); |
|
132 | 132 | wfGetLBFactory()->waitForReplication(); |
133 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
134 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
135 | - } while ( $db->affectedRows() > 0 ); |
|
133 | + $table = $db->tableName('wbqc_constraints'); |
|
134 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
135 | + } while ($db->affectedRows() > 0); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -141,26 +141,26 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return Constraint[] |
143 | 143 | */ |
144 | - private function convertToConstraints( ResultWrapper $results ) { |
|
144 | + private function convertToConstraints(ResultWrapper $results) { |
|
145 | 145 | $constraints = []; |
146 | - foreach ( $results as $result ) { |
|
146 | + foreach ($results as $result) { |
|
147 | 147 | $constraintTypeItemId = $result->constraint_type_qid; |
148 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
148 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
149 | 149 | |
150 | - if ( $constraintParameters === null ) { |
|
150 | + if ($constraintParameters === null) { |
|
151 | 151 | // T171295 |
152 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
153 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
152 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
153 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
154 | 154 | 'method' => __METHOD__, |
155 | 155 | 'constraintId' => $result->constraint_guid, |
156 | 156 | 'constraintParameters' => $result->constraint_parameters, |
157 | - ] ); |
|
158 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
157 | + ]); |
|
158 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | $constraints[] = new Constraint( |
162 | 162 | $result->constraint_guid, |
163 | - PropertyId::newFromNumber( $result->pid ), |
|
163 | + PropertyId::newFromNumber($result->pid), |
|
164 | 164 | $constraintTypeItemId, |
165 | 165 | $constraintParameters |
166 | 166 | ); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @var ConstraintLookup $lookup The lookup to which all queries are delegated. |
28 | 28 | */ |
29 | - public function __construct( ConstraintLookup $lookup ) { |
|
29 | + public function __construct(ConstraintLookup $lookup) { |
|
30 | 30 | $this->lookup = $lookup; |
31 | 31 | } |
32 | 32 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | 39 | $id = $propertyId->getSerialization(); |
40 | - if ( !array_key_exists( $id, $this->cache ) ) { |
|
41 | - $this->cache[$id] = $this->lookup->queryConstraintsForProperty( $propertyId ); |
|
40 | + if (!array_key_exists($id, $this->cache)) { |
|
41 | + $this->cache[$id] = $this->lookup->queryConstraintsForProperty($propertyId); |
|
42 | 42 | } |
43 | 43 | return $this->cache[$id]; |
44 | 44 | } |