CachedItemLookup::__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 1
Bugs 0 Features 1
Metric Value
c 1
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\ItemId;
6
use Wikibase\DataModel\Services\Lookup\ItemLookup;
7
8
/**
9
 * Internal class
10
 *
11
 * @licence GPLv2+
12
 * @author Thomas Pellissier Tanon
13
 */
14
class CachedItemLookup implements ItemLookup {
15
16
	/**
17
	 * @var ItemLookup
18
	 */
19
	private $itemLookup;
20
21
	/**
22
	 * @var EntityDocumentCache
23
	 */
24
	private $entityCache;
25
26
	/**
27
	 * @param ItemLookup $itemLookup
28
	 * @param EntityDocumentCache $entityCache
29
	 */
30 4
	public function __construct( ItemLookup $itemLookup, EntityDocumentCache $entityCache ) {
31 4
		$this->itemLookup = $itemLookup;
32 4
		$this->entityCache = $entityCache;
33 4
	}
34
35
	/**
36
	 * @see ItemLookup::getItemForId
37
	 */
38 4
	public function getItemForId( ItemId $itemId ) {
39 4
		$item = $this->entityCache->fetch( $itemId );
40
41 4
		if( $item === null ) {
42 3
			$item = $this->itemLookup->getItemForId( $itemId );
43 3
			if( $item !== null ) {
44 2
				$this->entityCache->save( $item );
45 2
			}
46 3
		}
47
48 4
		return $item;
49
	}
50
}
51