PidManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 33
ccs 13
cts 14
cp 0.9286
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A pidExists() 0 3 1
A removePid() 0 7 2
A readPid() 0 4 1
A writePid() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\TableSync\Integration\Laravel\Console;
6
7
use Safe;
8
9
class PidManager
10
{
11
    private $pathToPidFile;
12
13 1
    public function __construct(string $pathToPidFile)
14
    {
15 1
        $this->pathToPidFile = $pathToPidFile;
16
    }
17
18 1
    public function pidExists(): bool
19
    {
20 1
        return file_exists($this->pathToPidFile);
21
    }
22
23 1
    public function readPid(): int
24
    {
25 1
        $pid = Safe\file_get_contents($this->pathToPidFile);
26 1
        return (int) $pid;
27
    }
28
29 1
    public function writePid(int $pid = null): void
30
    {
31 1
        $pid = $pid ?? posix_getpid();
32 1
        Safe\file_put_contents($this->pathToPidFile, $pid);
33
    }
34
35 1
    public function removePid(): void
36
    {
37 1
        if (!$this->pidExists()) {
38
            return;
39
        }
40
41 1
        unlink($this->pathToPidFile);
42
    }
43
}
44