Passed
Push — master ( ff2631...b5fad1 )
by Radu
01:29
created

CliRunner   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPid() 0 3 1
A start() 0 10 1
A finish() 0 9 3
A __construct() 0 3 1
1
<?php
2
namespace WebServCo\Framework;
3
4
final class CliRunner
5
{
6
    protected $workDir;
7
    protected $script;
8
    protected $pid = [];
9
10
    public function __construct($workDir)
11
    {
12
        $this->workDir = $workDir;
13
    }
14
15
    public function start($script)
16
    {
17
        $this->pid[$script] = sprintf(
18
            '%s%s%s.pid',
19
            realpath($this->workDir),
20
            DIRECTORY_SEPARATOR,
21
            md5($script)
22
        );
23
        touch($this->pid[$script]);
24
        return true;
25
    }
26
27
    public function hasPid($script)
28
    {
29
        return is_readable($this->pid[$script]);
30
    }
31
32
    public function finish($script)
33
    {
34
        if (is_file($this->pid[$script]) &&
35
            is_readable($this->pid[$script])
36
        ) {
37
            unlink($this->pid[$script]);
38
            return true;
39
        }
40
        return false;
41
    }
42
}
43