Writing_On_GitHub_Semaphore::lock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Locks and unlock the import/export process.
4
 * @package Writing_On_GitHub
5
 */
6
7
/**
8
 * Class Writing_On_GitHub_Semaphore
9
 */
10
class Writing_On_GitHub_Semaphore {
11
12
    /**
13
     * Sempahore's option key.
14
     */
15
    const KEY = 'wogh_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