BatchingEntityIdFetcherBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 36
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A addFetcherForEntityType() 0 7 1
A getPreviousIdForEntityType() 0 7 3
A getFetcher() 0 3 1
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