Completed
Pull Request — develop (#1282)
by David
07:16 queued 04:07
created

Abstract_Sync_Background_Process_State   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get_info() 0 18 2
1
<?php
2
3
namespace Wordlift\Dataset\Background;
4
5
abstract class Abstract_Sync_Background_Process_State implements Sync_Background_Process_State {
6
7
	private $state;
8
9
	function __construct( $state ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
10
		$this->state = $state;
11
	}
12
13
	function get_info() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
		$started     = get_option( '_wl_sync_background_process_started' );
15
		$offset      = get_option( '_wl_sync_background_process_offset' );
16
		$stage       = get_option( '_wl_sync_background_process_stage' );
17
		$counts      = get_option( '_wl_sync_background_process_count', array( 0 ) );
18
		$last_update = get_option( '_wl_sync_background_process_updated' );
19
20
		// Calculate the overall index by adding the count of completed stages.
21
		$index = $offset + 1;
22
		for ( $i = 0; $i < $stage; $i ++ ) {
23
			$index += $counts[ $i ];
24
		}
25
26
		// Get the total count.
27
		$total_count = array_sum( $counts );
28
29
		return new Sync_Background_Process_Info( $this->state, $started, $index, $total_count, $last_update );
30
	}
31
32
}
33