InMemoryEntityLookup   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 8
c 3
b 0
f 1
lcom 1
cbo 1
dl 0
loc 45
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getEntityDocumentForId() 0 4 2
A buildEntitiesArray() 0 6 2
A getEntityDocumentsForIds() 0 12 3
1
<?php
2
3
namespace Wikibase\EntityStore\InMemory;
4
5
use Wikibase\DataModel\Entity\EntityDocument;
6
use Wikibase\DataModel\Entity\EntityId;
7
use Wikibase\EntityStore\EntityDocumentLookup;
8
9
/**
10
 * Internal class
11
 *
12
 * @licence GPLv2+
13
 * @author Thomas Pellissier Tanon
14
 */
15
class InMemoryEntityLookup implements EntityDocumentLookup {
16
17
	/**
18
	 * @var EntityDocument[]
19
	 */
20
	private $entities = [];
21
22
	/**
23
	 * @param EntityDocument[] $entities
24
	 */
25 3
	public function __construct( array $entities ) {
26 3
		$this->buildEntitiesArray( $entities );
27 3
	}
28
29 3
	private function buildEntitiesArray( array $entities ) {
30
		/** @var EntityDocument $entity */
31 3
		foreach( $entities as $entity ) {
32 2
			$this->entities[$entity->getId()->getSerialization()] = $entity;
33 3
		}
34 3
	}
35
36
	/**
37
	 * @see EntityDocumentLookup::getEntityDocumentForId
38
	 */
39 3
	public function getEntityDocumentForId( EntityId $entityId ) {
40 3
		$key = $entityId->getSerialization();
41 3
		return array_key_exists( $key, $this->entities ) ? $this->entities[$key] : null;
42
	}
43
44
	/**
45
	 * @see EntityDocumentLookup::getEntityDocumentsForIds
46
	 */
47 1
	public function getEntityDocumentsForIds( array $entityIds ) {
48 1
		$entities = [];
49
50 1
		foreach( $entityIds as $entityId ) {
51 1
			$entity = $this->getEntityDocumentForId( $entityId );
52 1
			if( $entity !== null ) {
53 1
				$entities[] = $entity;
54 1
			}
55 1
		}
56
57 1
		return $entities;
58
	}
59
}
60