WordPress_GitHub_Sync_Semaphore::unlock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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