Completed
Pull Request — develop (#1350)
by Naveen
03:05
created

Data_Source::count()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
1
<?php
2
namespace Wordlift\Common\Background_Process;
3
4
abstract class Data_Source {
5
6
	/**
7
	 * @var string The key which is provided to the background process
8
	 * in order to retrieve its state, it should be the same as the one provided to
9
	 * background process.
10
	 */
11
	private $state_storage_key;
12
13
	public function __construct( $state_storage_key ) {
14
		$this->state_storage_key = $state_storage_key;
15
	}
16
17
	/**
18
	 * A list of item ids.
19
	 * @return int[]
20
	 */
21
	abstract public function next();
22
23
	/**
24
	 * The count of total items which needs to be processed.
25
	 * @return int[]
26
	 */
27
	abstract public function count();
28
29
	/**
30
	 * A numerical value indicating how many items should be processed per
31
	 * background call.
32
	 * @return int
33
	 */
34
	abstract public function get_batch_size();
35
36
37
	public function get_state() {
38
		try {
39
			return get_option( $this->state_storage_key, Sync_State::unknown() );
40
		} catch ( \Exception $e ) {
41
			return Sync_State::unknown();
42
		}
43
44
	}
45
46
}
47