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

CitationNeededChecker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 44
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedContextTypes() 0 7 1
A getDefaultContextTypes() 0 3 1
A checkConstraint() 0 17 2
A checkConstraintParameters() 0 4 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