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

Sync_State   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 55
loc 55
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A increment_index() 6 6 1
A set_state() 6 6 1
A get_array() 9 9 1
A unknown() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}