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

CliRunner::start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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