PcntlSignals   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A wait() 0 4 2
A unblock() 0 3 1
A __construct() 0 3 1
A block() 0 3 1
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