CachedPropertyLookup::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
cc 1
eloc 3
nc 1
nop 2
crap 1
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