InMemoryEntityIdPager::getPosition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
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