@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @throws ConstraintParameterException |
76 | 76 | * @return CheckResult |
77 | 77 | */ |
78 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
78 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | $unitsParameter = $this->constraintParameterParser |
@@ -85,45 +85,44 @@ discard block |
||
85 | 85 | ); |
86 | 86 | |
87 | 87 | $snak = $context->getSnak(); |
88 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
88 | + if (!$snak instanceof PropertyValueSnak) { |
|
89 | 89 | // nothing to check |
90 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
90 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $dataValue = $snak->getDataValue(); |
94 | - if ( !$dataValue instanceof UnboundedQuantityValue ) { |
|
95 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
96 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
97 | - ->withDataValueType( 'quantity' ); |
|
98 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
94 | + if (!$dataValue instanceof UnboundedQuantityValue) { |
|
95 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
96 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
97 | + ->withDataValueType('quantity'); |
|
98 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
99 | 99 | } |
100 | 100 | |
101 | - if ( $dataValue->getUnit() === '1' ) { |
|
102 | - return $this->checkUnitless( $context, $constraint, $unitsParameter, $snak ); |
|
101 | + if ($dataValue->getUnit() === '1') { |
|
102 | + return $this->checkUnitless($context, $constraint, $unitsParameter, $snak); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | $status = CheckResult::STATUS_VIOLATION; |
106 | - $actualUnit = $this->standardize( $dataValue )->getUnit(); |
|
107 | - foreach ( $unitsParameter->getUnitQuantities() as $unitQuantity ) { |
|
108 | - $allowedUnit = $this->standardize( $unitQuantity )->getUnit(); |
|
109 | - if ( $actualUnit === $allowedUnit ) { |
|
106 | + $actualUnit = $this->standardize($dataValue)->getUnit(); |
|
107 | + foreach ($unitsParameter->getUnitQuantities() as $unitQuantity) { |
|
108 | + $allowedUnit = $this->standardize($unitQuantity)->getUnit(); |
|
109 | + if ($actualUnit === $allowedUnit) { |
|
110 | 110 | $status = CheckResult::STATUS_COMPLIANCE; |
111 | 111 | break; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | - if ( $status === CheckResult::STATUS_VIOLATION ) { |
|
115 | + if ($status === CheckResult::STATUS_VIOLATION) { |
|
116 | 116 | $messageKey = $unitsParameter->getUnitlessAllowed() ? |
117 | - 'wbqc-violation-message-units-or-none' : |
|
118 | - 'wbqc-violation-message-units'; |
|
119 | - $message = ( new ViolationMessage( $messageKey ) ) |
|
120 | - ->withEntityId( $snak->getPropertyId() ) |
|
121 | - ->withEntityIdList( $unitsParameter->getUnitItemIds() ); |
|
117 | + 'wbqc-violation-message-units-or-none' : 'wbqc-violation-message-units'; |
|
118 | + $message = (new ViolationMessage($messageKey)) |
|
119 | + ->withEntityId($snak->getPropertyId()) |
|
120 | + ->withEntityIdList($unitsParameter->getUnitItemIds()); |
|
122 | 121 | } else { |
123 | 122 | $message = null; |
124 | 123 | } |
125 | 124 | |
126 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
125 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
127 | 126 | } |
128 | 127 | |
129 | 128 | /** |
@@ -139,17 +138,17 @@ discard block |
||
139 | 138 | UnitsParameter $unitsParameter, |
140 | 139 | PropertyValueSnak $snak |
141 | 140 | ) { |
142 | - if ( $unitsParameter->getUnitlessAllowed() ) { |
|
141 | + if ($unitsParameter->getUnitlessAllowed()) { |
|
143 | 142 | $message = null; |
144 | 143 | $status = CheckResult::STATUS_COMPLIANCE; |
145 | 144 | } else { |
146 | - $message = ( new ViolationMessage( 'wbqc-violation-message-units' ) ) |
|
147 | - ->withEntityId( $snak->getPropertyId() ) |
|
148 | - ->withEntityIdList( $unitsParameter->getUnitItemIds() ); |
|
145 | + $message = (new ViolationMessage('wbqc-violation-message-units')) |
|
146 | + ->withEntityId($snak->getPropertyId()) |
|
147 | + ->withEntityIdList($unitsParameter->getUnitItemIds()); |
|
149 | 148 | $status = CheckResult::STATUS_VIOLATION; |
150 | 149 | } |
151 | 150 | |
152 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
151 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
153 | 152 | } |
154 | 153 | |
155 | 154 | /** |
@@ -158,20 +157,20 @@ discard block |
||
158 | 157 | * @param UnboundedQuantityValue $value |
159 | 158 | * @return UnboundedQuantityValue |
160 | 159 | */ |
161 | - private function standardize( UnboundedQuantityValue $value ) { |
|
162 | - if ( $this->unitConverter === null ) { |
|
160 | + private function standardize(UnboundedQuantityValue $value) { |
|
161 | + if ($this->unitConverter === null) { |
|
163 | 162 | return $value; |
164 | 163 | } |
165 | 164 | |
166 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
167 | - if ( $standard !== null ) { |
|
165 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
166 | + if ($standard !== null) { |
|
168 | 167 | return $standard; |
169 | 168 | } else { |
170 | 169 | return $value; |
171 | 170 | } |
172 | 171 | } |
173 | 172 | |
174 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
173 | + public function checkConstraintParameters(Constraint $constraint) { |
|
175 | 174 | $constraintParameters = $constraint->getConstraintParameters(); |
176 | 175 | $exceptions = []; |
177 | 176 | try { |
@@ -180,7 +179,7 @@ discard block |
||
180 | 179 | $constraint->getConstraintTypeItemId(), |
181 | 180 | true |
182 | 181 | ); |
183 | - } catch ( ConstraintParameterException $e ) { |
|
182 | + } catch (ConstraintParameterException $e) { |
|
184 | 183 | $exceptions[] = $e; |
185 | 184 | } |
186 | 185 | return $exceptions; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | public static function getDefaultInstance() { |
153 | 153 | static $instance = null; |
154 | 154 | |
155 | - if ( $instance === null ) { |
|
155 | + if ($instance === null) { |
|
156 | 156 | $wikibaseRepo = WikibaseRepo::getDefaultInstance(); |
157 | 157 | $entityIdFormatter = $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory()->getEntityIdFormatter( |
158 | 158 | $wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory()->newLabelDescriptionLookup( |
@@ -233,21 +233,21 @@ discard block |
||
233 | 233 | * @return DelegatingConstraintChecker |
234 | 234 | */ |
235 | 235 | public function getConstraintChecker() { |
236 | - if ( $this->delegatingConstraintChecker === null ) { |
|
236 | + if ($this->delegatingConstraintChecker === null) { |
|
237 | 237 | $this->delegatingConstraintChecker = new DelegatingConstraintChecker( |
238 | 238 | $this->lookup, |
239 | 239 | $this->getConstraintCheckerMap(), |
240 | - new CachingConstraintLookup( $this->getConstraintRepository() ), |
|
240 | + new CachingConstraintLookup($this->getConstraintRepository()), |
|
241 | 241 | $this->constraintParameterParser, |
242 | 242 | $this->statementGuidParser, |
243 | 243 | new LoggingHelper( |
244 | 244 | $this->dataFactory, |
245 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
245 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
246 | 246 | $this->config |
247 | 247 | ), |
248 | - $this->config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
249 | - $this->config->get( 'WBQualityConstraintsCheckReferences' ), |
|
250 | - $this->config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
248 | + $this->config->get('WBQualityConstraintsCheckQualifiers'), |
|
249 | + $this->config->get('WBQualityConstraintsCheckReferences'), |
|
250 | + $this->config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
251 | 251 | ); |
252 | 252 | } |
253 | 253 | |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | * @return ConstraintChecker[] |
259 | 259 | */ |
260 | 260 | private function getConstraintCheckerMap() { |
261 | - if ( $this->constraintCheckerMap === null ) { |
|
261 | + if ($this->constraintCheckerMap === null) { |
|
262 | 262 | $connectionCheckerHelper = new ConnectionCheckerHelper(); |
263 | - $rangeCheckerHelper = new RangeCheckerHelper( $this->config, $this->unitConverter ); |
|
264 | - if ( $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ) !== '' ) { |
|
263 | + $rangeCheckerHelper = new RangeCheckerHelper($this->config, $this->unitConverter); |
|
264 | + if ($this->config->get('WBQualityConstraintsSparqlEndpoint') !== '') { |
|
265 | 265 | $sparqlHelper = new SparqlHelper( |
266 | 266 | $this->config, |
267 | 267 | $this->rdfVocabulary, |
@@ -284,74 +284,74 @@ discard block |
||
284 | 284 | ); |
285 | 285 | |
286 | 286 | $this->constraintCheckerMap = [ |
287 | - $this->config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
287 | + $this->config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
288 | 288 | => new ConflictsWithChecker( |
289 | 289 | $this->lookup, |
290 | 290 | $this->constraintParameterParser, |
291 | 291 | $connectionCheckerHelper, |
292 | 292 | $this->constraintParameterRenderer |
293 | 293 | ), |
294 | - $this->config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
294 | + $this->config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
295 | 295 | => new ItemChecker( |
296 | 296 | $this->lookup, |
297 | 297 | $this->constraintParameterParser, |
298 | 298 | $connectionCheckerHelper, |
299 | 299 | $this->constraintParameterRenderer |
300 | 300 | ), |
301 | - $this->config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
301 | + $this->config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
302 | 302 | => new TargetRequiredClaimChecker( |
303 | 303 | $this->lookup, |
304 | 304 | $this->constraintParameterParser, |
305 | 305 | $connectionCheckerHelper, |
306 | 306 | $this->constraintParameterRenderer |
307 | 307 | ), |
308 | - $this->config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
308 | + $this->config->get('WBQualityConstraintsSymmetricConstraintId') |
|
309 | 309 | => new SymmetricChecker( |
310 | 310 | $this->lookup, |
311 | 311 | $connectionCheckerHelper, |
312 | 312 | $this->constraintParameterRenderer |
313 | 313 | ), |
314 | - $this->config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
314 | + $this->config->get('WBQualityConstraintsInverseConstraintId') |
|
315 | 315 | => new InverseChecker( |
316 | 316 | $this->lookup, |
317 | 317 | $this->constraintParameterParser, |
318 | 318 | $connectionCheckerHelper, |
319 | 319 | $this->constraintParameterRenderer |
320 | 320 | ), |
321 | - $this->config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
321 | + $this->config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
322 | 322 | => new QualifierChecker(), |
323 | - $this->config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
323 | + $this->config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
324 | 324 | => new QualifiersChecker( |
325 | 325 | $this->constraintParameterParser, |
326 | 326 | $this->constraintParameterRenderer |
327 | 327 | ), |
328 | - $this->config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
328 | + $this->config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
329 | 329 | => new MandatoryQualifiersChecker( |
330 | 330 | $this->constraintParameterParser, |
331 | 331 | $this->constraintParameterRenderer |
332 | 332 | ), |
333 | - $this->config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
333 | + $this->config->get('WBQualityConstraintsRangeConstraintId') |
|
334 | 334 | => new RangeChecker( |
335 | 335 | $this->propertyDataTypeLookup, |
336 | 336 | $this->constraintParameterParser, |
337 | 337 | $rangeCheckerHelper, |
338 | 338 | $this->constraintParameterRenderer |
339 | 339 | ), |
340 | - $this->config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
340 | + $this->config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
341 | 341 | => new DiffWithinRangeChecker( |
342 | 342 | $this->constraintParameterParser, |
343 | 343 | $rangeCheckerHelper, |
344 | 344 | $this->constraintParameterRenderer, |
345 | 345 | $this->config |
346 | 346 | ), |
347 | - $this->config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
347 | + $this->config->get('WBQualityConstraintsTypeConstraintId') |
|
348 | 348 | => new TypeChecker( |
349 | 349 | $this->lookup, |
350 | 350 | $this->constraintParameterParser, |
351 | 351 | $typeCheckerHelper, |
352 | 352 | $this->config |
353 | 353 | ), |
354 | - $this->config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
354 | + $this->config->get('WBQualityConstraintsValueTypeConstraintId') |
|
355 | 355 | => new ValueTypeChecker( |
356 | 356 | $this->lookup, |
357 | 357 | $this->constraintParameterParser, |
@@ -359,40 +359,40 @@ discard block |
||
359 | 359 | $typeCheckerHelper, |
360 | 360 | $this->config |
361 | 361 | ), |
362 | - $this->config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
362 | + $this->config->get('WBQualityConstraintsSingleValueConstraintId') |
|
363 | 363 | => new SingleValueChecker(), |
364 | - $this->config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
364 | + $this->config->get('WBQualityConstraintsMultiValueConstraintId') |
|
365 | 365 | => new MultiValueChecker(), |
366 | - $this->config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
366 | + $this->config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
367 | 367 | => new UniqueValueChecker( |
368 | 368 | $this->constraintParameterRenderer, |
369 | 369 | $sparqlHelper |
370 | 370 | ), |
371 | - $this->config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
371 | + $this->config->get('WBQualityConstraintsFormatConstraintId') |
|
372 | 372 | => new FormatChecker( |
373 | 373 | $this->constraintParameterParser, |
374 | 374 | $this->constraintParameterRenderer, |
375 | 375 | $this->config, |
376 | 376 | $sparqlHelper |
377 | 377 | ), |
378 | - $this->config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
378 | + $this->config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
379 | 379 | => new CommonsLinkChecker( |
380 | 380 | $this->constraintParameterParser, |
381 | 381 | $this->constraintParameterRenderer, |
382 | 382 | $this->titleParser |
383 | 383 | ), |
384 | - $this->config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
384 | + $this->config->get('WBQualityConstraintsOneOfConstraintId') |
|
385 | 385 | => new OneOfChecker( |
386 | 386 | $this->constraintParameterParser, |
387 | 387 | $this->constraintParameterRenderer |
388 | 388 | ), |
389 | - $this->config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
389 | + $this->config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
390 | 390 | => new ValueOnlyChecker(), |
391 | - $this->config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
391 | + $this->config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
392 | 392 | => new ReferenceChecker(), |
393 | - $this->config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
393 | + $this->config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
394 | 394 | => new NoBoundsChecker(), |
395 | - $this->config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
395 | + $this->config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
396 | 396 | => new AllowedUnitsChecker( |
397 | 397 | $this->constraintParameterParser, |
398 | 398 | $this->unitConverter |
@@ -407,26 +407,26 @@ discard block |
||
407 | 407 | * @return array[] |
408 | 408 | */ |
409 | 409 | public function getConstraintParameterMap() { |
410 | - if ( $this->constraintParameterMap === null ) { |
|
410 | + if ($this->constraintParameterMap === null) { |
|
411 | 411 | $this->constraintParameterMap = [ |
412 | - 'Commons link' => [ 'namespace' ], |
|
413 | - 'Conflicts with' => [ 'property', 'item' ], |
|
414 | - 'Diff within range' => [ 'property', 'minimum_quantity', 'maximum_quantity' ], |
|
415 | - 'Format' => [ 'pattern' ], |
|
416 | - 'Inverse' => [ 'property' ], |
|
417 | - 'Item' => [ 'property', 'item' ], |
|
418 | - 'Mandatory qualifiers' => [ 'property' ], |
|
412 | + 'Commons link' => ['namespace'], |
|
413 | + 'Conflicts with' => ['property', 'item'], |
|
414 | + 'Diff within range' => ['property', 'minimum_quantity', 'maximum_quantity'], |
|
415 | + 'Format' => ['pattern'], |
|
416 | + 'Inverse' => ['property'], |
|
417 | + 'Item' => ['property', 'item'], |
|
418 | + 'Mandatory qualifiers' => ['property'], |
|
419 | 419 | 'Multi value' => [], |
420 | - 'One of' => [ 'item' ], |
|
420 | + 'One of' => ['item'], |
|
421 | 421 | 'Qualifier' => [], |
422 | - 'Qualifiers' => [ 'property' ], |
|
423 | - 'Range' => [ 'minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date' ], |
|
422 | + 'Qualifiers' => ['property'], |
|
423 | + 'Range' => ['minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date'], |
|
424 | 424 | 'Single value' => [], |
425 | 425 | 'Symmetric' => [], |
426 | - 'Target required claim' => [ 'property', 'item' ], |
|
427 | - 'Type' => [ 'class', 'relation' ], |
|
426 | + 'Target required claim' => ['property', 'item'], |
|
427 | + 'Type' => ['class', 'relation'], |
|
428 | 428 | 'Unique value' => [], |
429 | - 'Value type' => [ 'class', 'relation' ] |
|
429 | + 'Value type' => ['class', 'relation'] |
|
430 | 430 | ]; |
431 | 431 | } |
432 | 432 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | * @return ConstraintRepository |
438 | 438 | */ |
439 | 439 | public function getConstraintRepository() { |
440 | - if ( $this->constraintRepository === null ) { |
|
440 | + if ($this->constraintRepository === null) { |
|
441 | 441 | $this->constraintRepository = new ConstraintRepository(); |
442 | 442 | } |
443 | 443 |