InMemoryEntityIdPager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPosition() 0 2 1
A __construct() 0 2 1
A fetchIds() 0 4 1
A setPosition() 0 2 1
A addEntityId() 0 2 1
1
<?php
2
3
namespace Wikibase\DataModel\Services\EntityId;
4
5
use Wikibase\DataModel\Entity\EntityId;
6
7
/**
8
 * The position markers are implementation dependent and are not
9
 * interchangeable between different implementations.
10
 *
11
 * @since 3.14
12
 *
13
 * @author Addshore
14
 * @author Jeroen De Dauw
15
 * @license GPL-2.0-or-later
16
 */
17
class InMemoryEntityIdPager implements SeekableEntityIdPager {
18
19
	/**
20
	 * @var EntityId[]
21
	 */
22
	private $entityIds = [];
23
24
	/**
25
	 * @var int
26
	 */
27
	private $offset = 0;
28
29
	/**
30
	 * @param EntityId ...$ids
31
	 */
32
	public function __construct( ...$ids ) {
33
		$this->entityIds = $ids;
34
	}
35
36
	public function addEntityId( EntityId $entityId ) {
37
		$this->entityIds[] = $entityId;
38
	}
39
40
	/**
41
	 * @see EntityIdPager::fetchIds
42
	 *
43
	 * @param int $limit
44
	 *
45
	 * @return EntityId[]
46
	 */
47
	public function fetchIds( $limit ) {
48
		$entityIds = array_slice( $this->entityIds, $this->offset, $limit );
49
		$this->offset += count( $entityIds );
50
		return $entityIds;
51
	}
52
53
	/** @inheritDoc */
54
	public function getPosition() {
55
		return $this->offset;
56
	}
57
58
	/** @inheritDoc */
59
	public function setPosition( $position ) {
60
		$this->offset = $position;
61
	}
62
63
}
64