InProcessCachingDataTypeLookup   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getDataTypeIdForProperty() 0 9 2
1
<?php
2
3
namespace Wikibase\DataModel\Services\Lookup;
4
5
use Wikibase\DataModel\Entity\PropertyId;
6
7
/**
8
 * PropertyDataTypeLookup that provides in-process caching.
9
 *
10
 * @since 3.1
11
 *
12
 * @license GPL-2.0-or-later
13
 * @author Katie Filbert < [email protected] >
14
 */
15
class InProcessCachingDataTypeLookup implements PropertyDataTypeLookup {
16
17
	/**
18
	 * @var string[] Indexed by serialized PropertyId
19
	 */
20
	private $propertyIds = [];
21
22
	private $lookup;
23
24 2
	public function __construct( PropertyDataTypeLookup $propertyDataTypeLookup ) {
25 2
		$this->lookup = $propertyDataTypeLookup;
26 2
	}
27
28
	/**
29
	 * @param PropertyId $propertyId
30
	 *
31
	 * @return string
32
	 * @throws PropertyDataTypeLookupException
33
	 */
34 2
	public function getDataTypeIdForProperty( PropertyId $propertyId ) {
35 2
		$serializedId = $propertyId->getSerialization();
36
37 2
		if ( !array_key_exists( $serializedId, $this->propertyIds ) ) {
38 2
			$this->propertyIds[$serializedId] = $this->lookup->getDataTypeIdForProperty( $propertyId );
39 2
		}
40
41 2
		return $this->propertyIds[$serializedId];
42
	}
43
44
}
45