CachedItemLookup   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 getItemForId() 0 12 3
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