LegacyAdapterItemLookup::getItemForId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Wikibase\DataModel\Services\Lookup;
4
5
use Wikibase\DataModel\Entity\Item;
6
use Wikibase\DataModel\Entity\ItemId;
7
8
/**
9
 * ItemLookup implementation providing a migration path away from
10
 * the EntityLookup interface.
11
 *
12
 * @license GPL-2.0-or-later
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class LegacyAdapterItemLookup implements ItemLookup {
16
17
	private EntityLookup $lookup;
18
19
	public function __construct( EntityLookup $lookup ) {
20
		$this->lookup = $lookup;
21
	}
22
23
	/**
24
	 * @param ItemId $itemId
25
	 *
26
	 * @return Item|null
27
	 * @throws ItemLookupException
28
	 */
29
	public function getItemForId( ItemId $itemId ) {
30
		try {
31
			return $this->lookup->getEntity( $itemId );
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->lookup->getEntity($itemId) also could return the type Wikibase\DataModel\Entity\EntityDocument which includes types incompatible with the return type mandated by Wikibase\DataModel\Servi...mLookup::getItemForId() of Wikibase\DataModel\Entity\Item|null. Consider adding a type-check to rule them out.
Loading history...
32
		} catch ( EntityLookupException $ex ) {
33
			throw new ItemLookupException( $itemId, $ex->getMessage(), $ex );
34
		}
35
	}
36
37
}
38