PropertyDataTypeMatcher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 35
ccs 7
cts 7
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isMatchingDataType() 0 5 2
A __construct() 0 2 1
A findDataTypeIdForProperty() 0 2 1
1
<?php
2
3
namespace Wikibase\DataModel\Services\Entity;
4
5
use Wikibase\DataModel\Entity\PropertyId;
6
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
7
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookupException;
8
9
/**
10
 * Check if a PropertyId is for a Property with a specific data type.
11
 *
12
 * @since 3.1
13
 *
14
 * @license GPL-2.0-or-later
15
 * @author Katie Filbert < [email protected] >
16
 */
17
class PropertyDataTypeMatcher {
18
19
	/**
20
	 * @var PropertyDataTypeLookup
21
	 */
22
	private $propertyDataTypeLookup;
23
24
	public function __construct( PropertyDataTypeLookup $propertyDataTypeLookup ) {
25
		$this->propertyDataTypeLookup = $propertyDataTypeLookup;
26
	}
27 3
28 3
	/**
29 3
	 * Returns if the property with the specified property id has the provided data type.
30
	 *
31
	 * @param PropertyId $propertyId
32
	 * @param string $dataType
33
	 *
34
	 * @return bool
35
	 */
36
	public function isMatchingDataType( PropertyId $propertyId, $dataType ) {
37
		try {
38
			return $this->findDataTypeIdForProperty( $propertyId ) === $dataType;
39 3
		} catch ( PropertyDataTypeLookupException ) {
40
			return false;
41 3
		}
42 1
	}
43 1
44
	/**
45
	 * @param PropertyId $propertyId
46
	 *
47
	 * @return string
48
	 * @throws PropertyDataTypeLookupException
49
	 */
50
	private function findDataTypeIdForProperty( PropertyId $propertyId ) {
51
		return $this->propertyDataTypeLookup->getDataTypeIdForProperty( $propertyId );
52
	}
53 3
54
}
55