Completed
Push — main ( b55b92...e8d442 )
by
unknown
05:41
created

EntityApiLookup   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Addwiki\Wikibase\Api\Lookup;
4
5
use Addwiki\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
	private RevisionGetter $revisionGetter;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
17
18
	/**
19
	 * @param RevisionGetter $revisionGetter
20
	 */
21
	public function __construct( RevisionGetter $revisionGetter ) {
22
		$this->revisionGetter = $revisionGetter;
23
	}
24
25
	/**
26
	 * @see EntityLookup::getEntity
27
	 * @return null|mixed
28
	 */
29
	public function getEntity( EntityId $entityId ) {
30
		$revision = $this->revisionGetter->getFromId( $entityId );
31
32
		if ( !$revision ) {
33
			return null;
34
		}
35
36
		return $revision->getContent()->getData();
37
	}
38
39
	/**
40
	 * @see EntityLookup::hasEntity
41
	 * @return bool
42
	 */
43
	public function hasEntity( EntityId $entityId ) {
44
		$revision = $this->revisionGetter->getFromId( $entityId );
45
		return (bool)$revision;
46
	}
47
}
48