InProcessCachingDataTypeLookup   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getDataTypeIdForProperty() 0 8 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 PropertyDataTypeLookup $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