Completed
Push — master ( bbc60f...4a601d )
by
unknown
04:19
created

CitationNeededChecker::checkConstraintParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
	public function checkConstraint( Context $context, Constraint $constraint ) {
37
		$referenceList = $context->getSnakStatement()->getReferences();
38
39
		if ( $referenceList->isEmpty() ) {
40
			$message = ( new ViolationMessage( 'wbqc-violation-message-citationNeeded' ) )
41
				->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY );
42
			return new CheckResult(
43
				$context,
44
				$constraint,
45
				[],
46
				CheckResult::STATUS_VIOLATION,
47
				$message
48
			);
49
		}
50
51
		return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE );
52
	}
53
54
	public function checkConstraintParameters( Constraint $constraint ) {
55
		// no parameters
56
		return [];
57
	}
58
59
}
60