WordPress_GitHub_Sync_Semaphore   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A is_open() 0 7 2
A lock() 0 3 1
A unlock() 0 3 1
1
<?php
2
/**
3
 * Locks and unlock the import/export process.
4
 * @package WordPress_GitHub_Sync
5
 */
6
7
/**
8
 * Class WordPress_GitHub_Sync_Semaphore
9
 */
10
class WordPress_GitHub_Sync_Semaphore {
11
12
	/**
13
	 * Sempahore's option key.
14
	 */
15
	const KEY = 'wpghs_semaphore_lock';
16
17
	/**
18
	 * Option key when semaphore is locked.
19
	 */
20
	const VALUE_LOCKED = 'yes';
21
22
	/**
23
	 * Option key when semaphore is unlocked.
24
	 */
25
	const VALUE_UNLOCKED = 'no';
26
27
	/**
28
	 * Clean up the old values on instantiation.
29
	 */
30
	public function __construct() {
31
		delete_option( self::KEY );
32
	}
33
34
	/**
35
	 * Checks if the Semaphore is open.
36
	 *
37
	 * Fails to report it's open if the the Api class can't make a call
38
	 * or the push lock has been enabled.
39
	 *
40
	 * @return bool
41
	 */
42
	public function is_open() {
43
		if ( self::VALUE_LOCKED === get_transient( self::KEY ) ) {
44
			return false;
45
		}
46
47
		return true;
48
	}
49
50
	/**
51
	 * Enables the push lock.
52
	 */
53
	public function lock() {
54
		set_transient( self::KEY, self::VALUE_LOCKED, MINUTE_IN_SECONDS );
55
	}
56
57
	/**
58
	 * Disables the push lock.
59
	 */
60
	public function unlock() {
61
		set_transient( self::KEY, self::VALUE_UNLOCKED, MINUTE_IN_SECONDS );
62
	}
63
}
64