PcntlSignals::unblock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Eclipxe\SoftDaemon\Internal;
6
7
/**
8
 * Wrapper class to pcntl used by SoftDaemon
9
 * Do not put any logic on this class, it is only used to make system calls
10
 * @internal
11
 * @codeCoverageIgnore
12
 */
13
class PcntlSignals
14
{
15
    /** @var int[] */
16
    protected $signals;
17
18
    /**
19
     * PcntlSignals constructor.
20
     *
21
     * @param int[] $signals
22
     */
23
    public function __construct(array $signals)
24
    {
25
        $this->signals = $signals;
26
    }
27
28
    /**
29
     * block signals using pcntl_sigprocmask
30
     * This is not covered on test because it creates a php system call
31
     *
32
     * @return bool
33
     */
34
    public function block(): bool
35
    {
36
        return pcntl_sigprocmask(SIG_BLOCK, $this->signals);
37
    }
38
39
    /**
40
     * unblock signals using pcntl_sigprocmask
41
     * This is not covered on test because it creates a php system call
42
     *
43
     * @return bool
44
     */
45
    public function unblock(): bool
46
    {
47
        return pcntl_sigprocmask(SIG_UNBLOCK, $this->signals);
48
    }
49
50
    /**
51
     * wait for blocked signals using pcntl_sigtimedwait
52
     * This is not covered on test because it creates a php system call
53
     *
54
     * @param int $seconds Numbers of seconds to wait
55
     * @return int
56
     */
57
    public function wait(int $seconds): int
58
    {
59
        $siginfo = [];
60
        return pcntl_sigtimedwait($this->signals, $siginfo, $seconds) ?: 0;
61
    }
62
}
63