Passed
Pull Request — master (#214)
by Jeroen De
02:38
created

InMemoryEntityIdPager::getPosition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
	public function __construct( EntityId ...$ids ) {
30
		$this->entityIds = $ids;
31
	}
32
33
	public function addEntityId( EntityId $entityId ) {
34
		$this->entityIds[] = $entityId;
35
	}
36
37
	/**
38
	 * @see EntityIdPager::fetchIds
39
	 *
40
	 * @param int $limit
41
	 *
42
	 * @return EntityId[]
43
	 */
44
	public function fetchIds( $limit ) {
45
		$entityIds = array_slice( $this->entityIds, $this->offset, $limit );
46
		$this->offset += count( $entityIds );
47
		return $entityIds;
48
	}
49
50
	public function getPosition() {
51
		return $this->offset;
52
	}
53
54
	public function setPosition( $position ) {
55
		$this->offset = $position;
56
	}
57
58
}
59