Completed
Push — master ( 1789e0...532791 )
by
unknown
03:08
created

NoBoundsChecker::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 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 [
25
			Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE,
26
			Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE,
27
			Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE,
28
		];
29
	}
30
31
	/**
32
	 * @codeCoverageIgnore This method is purely declarative.
33
	 */
34
	public function getDefaultContextTypes() {
35
		return [
36
			Context::TYPE_STATEMENT,
37
			Context::TYPE_QUALIFIER,
38
			Context::TYPE_REFERENCE,
39
		];
40
	}
41
42
	public function checkConstraint( Context $context, Constraint $constraint ) {
43
		if ( $context->getSnak()->getType() !== 'value' ) {
44
			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE );
45
		}
46
47
		/** @var PropertyValueSnak $snak */
48
		$snak = $context->getSnak();
49
50
		if ( $snak->getDataValue() instanceof QuantityValue ) {
0 ignored issues
show
Bug introduced by
The class DataValues\QuantityValue does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
51
			$message = ( new ViolationMessage( 'wbqc-violation-message-noBounds' ) )
52
				->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY );
53
			return new CheckResult(
54
				$context,
55
				$constraint,
56
				[],
57
				CheckResult::STATUS_VIOLATION,
58
				$message
59
			);
60
		}
61
62
		return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE );
63
	}
64
65
	public function checkConstraintParameters( Constraint $constraint ) {
66
		// no parameters
67
		return [];
68
	}
69
70
}
71