getDataTypeIdForProperty()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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