ExampleExecutable::signalHandler()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Eclipxe\SoftDaemon\Examples;
6
7
use Eclipxe\SoftDaemon\Executable;
8
9
class ExampleExecutable implements Executable
10
{
11
    /** @var int */
12
    protected $counter = 0;
13
14
    /** @var array<int, bool> */
15
    protected $returns;
16
17
    /** @param array<int, bool> $returns */
18
    public function __construct(array $returns)
19
    {
20
        $this->returns = $returns;
21
    }
22
23
    public function signalHandler(int $signo): void
24
    {
25
        echo 'ExampleExecutable process ', $signo, "\n";
26
        if (SIGHUP === $signo) {
27
            $this->counter = 0;
28
        }
29
    }
30
31
    public function runOnce(): bool
32
    {
33
        $return = array_key_exists($this->counter, $this->returns) ? $this->returns[$this->counter] : false;
34
        echo "Try to run $this->counter time: ", ($return) ? 'TRUE' : 'FALSE', "\n";
35
        $this->counter = $this->counter + 1;
36
        return $return;
37
    }
38
}
39