CachedItemIdForTermLookup::getItemIdsForTerm()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Wikibase\EntityStore\Cache;
4
5
use OutOfBoundsException;
6
use Wikibase\DataModel\Term\Term;
7
use Wikibase\EntityStore\ItemIdForTermLookup;
8
9
/**
10
 * Internal class
11
 *
12
 * @licence GPLv2+
13
 * @author Thomas Pellissier Tanon
14
 */
15
class CachedItemIdForTermLookup implements ItemIdForTermLookup {
16
17
	/**
18
	 * @var ItemIdForTermLookup
19
	 */
20
	private $itemIdForTermLookup;
21
22
	/**
23
	 * @var EntityIdForTermCache
24
	 */
25
	private $entityIdForTermCache;
26
27
	/**
28
	 * @param ItemIdForTermLookup $itemIdForTermLookup
29
	 * @param EntityIdForTermCache $entityIdForTermCache
30
	 */
31 3
	public function __construct(
32
		ItemIdForTermLookup $itemIdForTermLookup,
33
		EntityIdForTermCache $entityIdForTermCache
34
	) {
35 3
		$this->itemIdForTermLookup = $itemIdForTermLookup;
36 3
		$this->entityIdForTermCache = $entityIdForTermCache;
37 3
	}
38
39
	/**
40
	 * @see ItemIdForTermLookup::getItemIdsForTerm
41
	 */
42 3
	public function getItemIdsForTerm( Term $term ) {
43
		try {
44 3
			return $this->entityIdForTermCache->fetch( $term, 'item' );
45 2
		} catch( OutOfBoundsException $e ) {
46 2
			$itemIds = $this->itemIdForTermLookup->getItemIdsForTerm( $term );
47 2
			$this->entityIdForTermCache->save( $term, 'item', $itemIds );
48 2
			return $itemIds;
49
		}
50
	}
51
}
52