Passed
Push — master ( 3f1d3b...2842d6 )
by Alaa
48s queued 11s
created

InMemoryEntityIdPager::addEntityId()   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 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
	public function getPosition() {
54
		return $this->offset;
55
	}
56
57
	public function setPosition( $position ) {
58
		$this->offset = $position;
59
	}
60
61
}
62