GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Process::terminate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Sid\Phalcon\Cron;
4
5
/**
6
 * As this class uses PNCTL/POSIX functions and applies a shutdown handler that
7
 * waits for the process to finish, you should not use this class to interact
8
 * with regular processes.
9
 */
10
class Process
11
{
12
    /**
13
     * @var int
14
     */
15
    protected $processID;
16
17
18
19
    public function __construct(int $processID)
20
    {
21
        $this->processID = $processID;
22
23
24
25
        register_shutdown_function(
26
            [
27
                $this,
28
                "wait",
29
            ]
30
        );
31
    }
32
33
34
35
    public function getProcessID() : int
36
    {
37
        return $this->processID;
38
    }
39
40
41
42
    /**
43
     * Determine if this process is currently running. Defunct/zombie processes
44
     * are ignored.
45
     */
46
    public function isRunning() : bool
47
    {
48
        $result = shell_exec(
49
            sprintf(
50
                "ps -p %d --no-headers | grep -v '<defunct>'",
51
                $this->getProcessID()
52
            )
53
        );
54
55
        $result = trim($result, "\n");
56
57
        return ($result !== "");
58
    }
59
60
61
62
    /**
63
     * Wait for the process to finish.
64
     */
65
    public function wait()
66
    {
67
        pcntl_waitpid(
68
            $this->getProcessID(),
69
            $status
70
        );
71
    }
72
73
74
75
    /**
76
     * Terminate the process.
77
     */
78
    public function terminate() : bool
79
    {
80
        return posix_kill(
81
            $this->getProcessID(),
82
            SIGTERM
83
        );
84
    }
85
86
    /**
87
     * Kill the process.
88
     */
89
    public function kill() : bool
90
    {
91
        return posix_kill(
92
            $this->getProcessID(),
93
            SIGKILL
94
        );
95
    }
96
}
97