Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.86% |
13 / 14 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
NoBoundsChecker | |
92.86% |
13 / 14 |
|
50.00% |
1 / 2 |
7.02 | |
0.00% |
0 / 1 |
getSupportedContextTypes | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
getDefaultContextTypes | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
getSupportedEntityTypes | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
checkConstraint | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
3.00 | |||
checkConstraintParameters | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker; |
4 | |
5 | use DataValues\QuantityValue; |
6 | use Wikibase\DataModel\Snak\PropertyValueSnak; |
7 | use WikibaseQuality\ConstraintReport\Constraint; |
8 | use WikibaseQuality\ConstraintReport\ConstraintCheck\ConstraintChecker; |
9 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\Context; |
10 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessage; |
11 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult; |
12 | use WikibaseQuality\ConstraintReport\Role; |
13 | |
14 | /** |
15 | * @author Amir Sarabadani |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | class NoBoundsChecker implements ConstraintChecker { |
19 | |
20 | /** |
21 | * @codeCoverageIgnore This method is purely declarative. |
22 | */ |
23 | public function getSupportedContextTypes() { |
24 | return self::ALL_CONTEXT_TYPES_SUPPORTED; |
25 | } |
26 | |
27 | /** |
28 | * @codeCoverageIgnore This method is purely declarative. |
29 | */ |
30 | public function getDefaultContextTypes() { |
31 | return Context::ALL_CONTEXT_TYPES; |
32 | } |
33 | |
34 | /** @codeCoverageIgnore This method is purely declarative. */ |
35 | public function getSupportedEntityTypes() { |
36 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
37 | } |
38 | |
39 | public function checkConstraint( Context $context, Constraint $constraint ) { |
40 | $snak = $context->getSnak(); |
41 | |
42 | if ( !$snak instanceof PropertyValueSnak ) { |
43 | // nothing to check |
44 | return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
45 | } |
46 | |
47 | if ( $snak->getDataValue() instanceof QuantityValue ) { |
48 | $message = ( new ViolationMessage( 'wbqc-violation-message-noBounds' ) ) |
49 | ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
50 | return new CheckResult( |
51 | $context, |
52 | $constraint, |
53 | CheckResult::STATUS_VIOLATION, |
54 | $message |
55 | ); |
56 | } |
57 | |
58 | return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
59 | } |
60 | |
61 | public function checkConstraintParameters( Constraint $constraint ) { |
62 | // no parameters |
63 | return []; |
64 | } |
65 | |
66 | } |