BatchingEntityIdFetcherBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Wikibase\EntityStore;
4
5
use BatchingIterator\Fetchers\MultipleBatchingFetcher;
6
use Wikibase\DataModel\Entity\EntityId;
7
use Wikibase\Repo\Store\EntityPerPage;
8
9
/**
10
 * @since 0.2
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class BatchingEntityIdFetcherBuilder {
15
16
	private $entityPerPageTable;
17
	private $previousId;
18
19
	private $fetchers = array();
20
21
	public function __construct( EntityPerPage $entityPerPageTable, EntityId $previousId = null ) {
22
		$this->entityPerPageTable = $entityPerPageTable;
23
		$this->previousId = $previousId;
24
25
		$this->addFetcherForEntityType( 'item' );
26
		$this->addFetcherForEntityType( 'property' );
27
	}
28
29
	private function addFetcherForEntityType( $entityType ) {
30
		$this->fetchers[] = new TypedEntityIdFetcher(
31
			$this->entityPerPageTable,
32
			$entityType,
33
			$this->getPreviousIdForEntityType( $entityType )
34
		);
35
	}
36
37
	private function getPreviousIdForEntityType( $entityType ) {
38
		if ( $this->previousId !== null && $this->previousId->getEntityType() === $entityType ) {
39
			return $this->previousId;
40
		}
41
42
		return null;
43
	}
44
45
	public function getFetcher() {
46
		return new MultipleBatchingFetcher( $this->fetchers );
47
	}
48
49
}
50