Completed
Push — 2.0 ( 0d93f2...14c778 )
by Marco
16:42
created

RunLock   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 46
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A pause() 0 5 1
A resume() 0 5 1
A lock() 0 5 1
A release() 0 5 1
A check() 0 5 1
1
<?php namespace Comodojo\Extender\Components;
2
3
use \Exception;
4
5
/**
6
 * Lock file manager (static methods)
7
 *
8
 * @package     Comodojo extender
9
 * @author      Marco Giovinazzi <[email protected]>
10
 * @license     GPL-3.0+
11
 *
12
 * LICENSE:
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26
 */
27
28
class RunLock extends AbstractLocker {
29
30
    /**
31
     * Run file name
32
     *
33
     * @var string
34
     */
35
    private $runfile = "extender.run";
36
37
    public function __construct($runfile = null) {
38
39
        if ( $runfile !== null ) $this->runfile = $runfile;
40
41
    }
42
43
    public function pause() {
44
45
        return self::writeLock($this->runfile, 'PAUSED');
46
47
    }
48
49
    public function resume() {
50
51
        return $this->lock();
52
53
    }
54
55
    public function lock() {
56
57
        return self::writeLock($this->runfile, 'RUNNING');
58
59
    }
60
61
    public function release() {
62
63
        return self::releaseLock($this->runfile);
64
65
    }
66
67
    public function check() {
68
69
        return self::readLock($this->runfile) == 'RUNNING';
70
71
    }
72
73
}
74