EntityApiLookup::hasEntity()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
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