PidManager::readPid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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