Completed
Pull Request — develop (#1350)
by Naveen
02:56
created

Sync_State::set_state()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 6
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wordlift\Common\Background_Process;
4
5 View Code Duplication
class Sync_State {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
7
	public $started;
8
	public $index;
9
	public $count;
10
	public $last_update;
11
	public $state;
12
13
	/**
14
	 * Sync_Model constructor.
15
	 *
16
	 * @param $started
17
	 * @param $index
18
	 * @param $count
19
	 * @param $last_update
20
	 * @param $state
21
	 */
22
	public function __construct( $started, $index, $count, $last_update, $state ) {
23
		$this->started     = $started;
24
		$this->index       = $index;
25
		$this->count       = (int) $count;
26
		$this->last_update = $last_update;
27
		$this->state       = $state;
28
	}
29
30
	public function increment_index( $count ) {
31
		$this->index       += $count;
32
		$this->last_update = time();
33
34
		return $this;
35
	}
36
37
	public function set_state( $value ) {
38
		$this->state       = $value;
39
		$this->last_update = time();
40
41
		return $this;
42
	}
43
44
	public function get_array() {
45
		return array(
46
			'started'     => $this->started,
47
			'index'       => $this->index,
48
			'count'       => $this->count,
49
			'last_update' => $this->last_update,
50
			'state'       => $this->state
51
		);
52
	}
53
54
	public static function unknown() {
55
56
		return new self( time(), 0, 0, time(), 'unknown' );
57
	}
58
59
}