EntityApiLookup   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getEntity() 0 9 2
A hasEntity() 0 9 2
1
<?php
2
3
namespace Wikibase\Api\Lookup;
4
5
use Wikibase\Api\Service\RevisionGetter;
6
use Wikibase\DataModel\Entity\EntityId;
7
use Wikibase\DataModel\Services\Lookup\EntityLookup;
8
9
/**
10
 * @author Addshore
11
 *
12
 * @access private
13
 */
14
class EntityApiLookup implements EntityLookup {
15
16
	/**
17
	 * @var RevisionGetter
18
	 */
19
	private $revisionGetter;
20
21
	/**
22
	 * @param RevisionGetter $revisionGetter
23
	 */
24
	public function __construct( RevisionGetter $revisionGetter ) {
25
		$this->revisionGetter = $revisionGetter;
26
	}
27
28
	/**
29
	 * @see EntityLookup::getEntity
30
	 */
31
	public function getEntity( EntityId $entityId ) {
32
		$revision = $this->revisionGetter->getFromId( $entityId );
33
34
		if( !$revision ) {
35
			return null;
36
		}
37
38
		return $revision->getContent()->getData();
39
	}
40
41
	/**
42
	 * @see EntityLookup::hasEntity
43
	 */
44
	public function hasEntity( EntityId $entityId ) {
45
		$revision = $this->revisionGetter->getFromId( $entityId );
46
47
		if( !$revision ) {
48
			return false;
49
		}
50
51
		return true;
52
	}
53
}
54