Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
CitationNeededChecker | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 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 | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
checkConstraintParameters | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker; |
4 | |
5 | use WikibaseQuality\ConstraintReport\Constraint; |
6 | use WikibaseQuality\ConstraintReport\ConstraintCheck\ConstraintChecker; |
7 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\Context; |
8 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessage; |
9 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult; |
10 | use WikibaseQuality\ConstraintReport\Role; |
11 | |
12 | /** |
13 | * @author Amir Sarabadani |
14 | * @license GPL-2.0-or-later |
15 | */ |
16 | class CitationNeededChecker implements ConstraintChecker { |
17 | |
18 | /** |
19 | * @codeCoverageIgnore This method is purely declarative. |
20 | */ |
21 | public function getSupportedContextTypes() { |
22 | return [ |
23 | Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, |
24 | Context::TYPE_QUALIFIER => CheckResult::STATUS_NOT_IN_SCOPE, |
25 | Context::TYPE_REFERENCE => CheckResult::STATUS_NOT_IN_SCOPE, |
26 | ]; |
27 | } |
28 | |
29 | /** |
30 | * @codeCoverageIgnore This method is purely declarative. |
31 | */ |
32 | public function getDefaultContextTypes() { |
33 | return [ Context::TYPE_STATEMENT ]; |
34 | } |
35 | |
36 | /** @codeCoverageIgnore This method is purely declarative. */ |
37 | public function getSupportedEntityTypes() { |
38 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
39 | } |
40 | |
41 | public function checkConstraint( Context $context, Constraint $constraint ) { |
42 | $referenceList = $context->getSnakStatement()->getReferences(); |
43 | |
44 | if ( $referenceList->isEmpty() ) { |
45 | $message = ( new ViolationMessage( 'wbqc-violation-message-citationNeeded' ) ) |
46 | ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
47 | return new CheckResult( |
48 | $context, |
49 | $constraint, |
50 | CheckResult::STATUS_VIOLATION, |
51 | $message |
52 | ); |
53 | } |
54 | |
55 | return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
56 | } |
57 | |
58 | public function checkConstraintParameters( Constraint $constraint ) { |
59 | // no parameters |
60 | return []; |
61 | } |
62 | |
63 | } |