SystemUnix   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 63
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __destruct() 0 4 1
A run() 0 13 2
A kill() 0 6 1
A existsPid() 0 6 1
1
<?php
2
3
namespace Dazzle\Util\System;
4
5
use Dazzle\Util\Isolate\IsolateInterface;
6
7
class SystemUnix implements SystemInterface
8
{
9
    /**
10
     * @var IsolateInterface|null
11
     */
12
    protected $isolator;
13
14
    /**
15
     * @param IsolateInterface|null $isolator
16
     */
17
    public function __construct(IsolateInterface $isolator = null)
18
    {
19
        $this->isolator = $isolator;
20
    }
21
22
    /**
23
     *
24
     */
25
    public function __destruct()
26
    {
27
        unset($this->isolator);
28
    }
29
30
    /**
31
     * @override
32
     * @inheritDoc
33
     */
34
    public function run($command)
35
    {
36
        $command = $command . '>/dev/null 2>&1 & echo $!';
37
38
        if ($this->isolator !== null)
39
        {
40
            return $this->isolator->call('exec', [ $command ]);
41
        }
42
        else
43
        {
44
            return exec($command);
45
        }
46
    }
47
48
    /**
49
     * @override
50
     * @inheritDoc
51
     */
52
    public function kill($pid)
53
    {
54
        exec('kill -9 ' . $pid . ' >/dev/null 2>&1', $output, $result);
55
56
        return $result == 0;
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $result of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
57
    }
58
59
    /**
60
     * @override
61
     * @inheritDoc
62
     */
63
    public function existsPid($pid)
64
    {
65
        exec('kill -0 ' . $pid . ' >/dev/null 2>&1', $output, $result);
66
67
        return $result == 0;
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $result of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
68
    }
69
}
70