Completed
Push — master ( 388143...889690 )
by Thomas
05:32 queued 02:57
created

DispatchingEntityLookup::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Wikibase\EntityStore\Internal;
4
5
use Wikibase\DataModel\Entity\EntityId;
6
use Wikibase\DataModel\Entity\ItemId;
7
use Wikibase\DataModel\Entity\PropertyId;
8
use Wikibase\DataModel\Services\Lookup\EntityLookup;
9
use Wikibase\DataModel\Services\Lookup\EntityLookupException;
10
use Wikibase\DataModel\Services\Lookup\ItemLookup;
11
use Wikibase\DataModel\Services\Lookup\ItemLookupException;
12
use Wikibase\DataModel\Services\Lookup\PropertyLookup;
13
use Wikibase\DataModel\Services\Lookup\PropertyLookupException;
14
use Wikibase\EntityStore\EntityDocumentLookup;
15
16
/**
17
 * Internal class
18
 *
19
 * @licence GPLv2+
20
 * @author Thomas Pellissier Tanon
21
 */
22
class DispatchingEntityLookup implements ItemLookup, PropertyLookup, EntityLookup, EntityDocumentLookup {
23
24
	/**
25
	 * @var EntityDocumentLookup
26
	 */
27
	private $entityDocumentLookup;
28
29
	/**
30
	 * @param EntityDocumentLookup $entityDocumentLookup
31
	 */
32 11
	public function __construct( EntityDocumentLookup $entityDocumentLookup ) {
33 11
		$this->entityDocumentLookup = $entityDocumentLookup;
34 11
	}
35
36
	/**
37
	 * @see EntityLookup:getEntity
38
	 */
39
	public function getEntity( EntityId $entityId ) {
40
		return $this->entityDocumentLookup->getEntityDocumentForId( $entityId );
41
	}
42
43
	/**
44
	 * @see EntityLookup:hasEntity
45
	 */
46
	public function hasEntity( EntityId $entityId ) {
47
		return $this->entityDocumentLookup->getEntityDocumentForId( $entityId ) !== null;
48
	}
49
50
	/**
51
	 * @see EntityDocumentLookup:getEntityDocumentForId
52
	 */
53 4
	public function getEntityDocumentForId( EntityId $entityId ) {
54 4
		return $this->entityDocumentLookup->getEntityDocumentForId( $entityId );
55
	}
56
57
	/**
58
	 * @see EntityDocumentLookup:getEntityDocumentsForIds
59
	 */
60 3
	public function getEntityDocumentsForIds( array $entityIds ) {
61 3
		return $this->entityDocumentLookup->getEntityDocumentsForIds( $entityIds );
62
	}
63
64
	/**
65
	 * @see ItemLookup::getItemForId
66
	 */
67 4
	public function getItemForId( ItemId $itemId ) {
68
		try {
69 4
			return $this->entityDocumentLookup->getEntityDocumentForId( $itemId );
70 1
		} catch(EntityLookupException $e) {
71 1
			throw new ItemLookupException( $e->getEntityId(), $e->getMessage(), $e );
0 ignored issues
show
Compatibility introduced by
$e->getEntityId() of type object<Wikibase\DataModel\Entity\EntityId> is not a sub-type of object<Wikibase\DataModel\Entity\ItemId>. It seems like you assume a child class of the class Wikibase\DataModel\Entity\EntityId to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
72
		}
73
	}
74
75
	/**
76
	 * @see PropertyLookup::getPropertyForId
77
	 */
78 3
	public function getPropertyForId( PropertyId $propertyId ) {
79
		try {
80 3
			return $this->entityDocumentLookup->getEntityDocumentForId( $propertyId );
81 1
		} catch(EntityLookupException $e) {
82 1
			throw new PropertyLookupException( $e->getEntityId(), $e->getMessage(), $e );
0 ignored issues
show
Compatibility introduced by
$e->getEntityId() of type object<Wikibase\DataModel\Entity\EntityId> is not a sub-type of object<Wikibase\DataModel\Entity\PropertyId>. It seems like you assume a child class of the class Wikibase\DataModel\Entity\EntityId to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
83
		}
84
	}
85
}
86