CachedPropertyLookup   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 37
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPropertyForId() 0 12 3
1
<?php
2
3
namespace Wikibase\EntityStore\Cache;
4
5
use Wikibase\DataModel\Entity\PropertyId;
6
use Wikibase\DataModel\Services\Lookup\PropertyLookup;
7
8
/**
9
 * Internal class
10
 *
11
 * @licence GPLv2+
12
 * @author Thomas Pellissier Tanon
13
 */
14
class CachedPropertyLookup implements PropertyLookup {
15
16
	/**
17
	 * @var PropertyLookup
18
	 */
19
	private $propertyLookup;
20
21
	/**
22
	 * @var EntityDocumentCache
23
	 */
24
	private $entityCache;
25
26
	/**
27
	 * @param PropertyLookup $propertyLookup
28
	 * @param EntityDocumentCache $entityCache
29
	 */
30 4
	public function __construct( PropertyLookup $propertyLookup, EntityDocumentCache $entityCache ) {
31 4
		$this->propertyLookup = $propertyLookup;
32 4
		$this->entityCache = $entityCache;
33 4
	}
34
35
	/**
36
	 * @see PropertyLookup::getPropertyForId
37
	 */
38 4
	public function getPropertyForId( PropertyId $propertyId ) {
39 4
		$property = $this->entityCache->fetch( $propertyId );
40
41 4
		if( $property === null ) {
42 3
			$property = $this->propertyLookup->getPropertyForId( $propertyId );
43 3
			if( $property !== null ) {
44 2
				$this->entityCache->save( $property );
45 2
			}
46 3
		}
47
48 4
		return $property;
49
	}
50
}
51