Passed
Push — main ( a747ee...a6a62e )
by Carlos C
01:59 queued 23s
created

ExampleExecutable::__construct()   A

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 1
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\Examples;
6
7
use Eclipxe\SoftDaemon\Executable;
8
9
class ExampleExecutable implements Executable
10
{
11
    protected $counter = 0;
12
13
    protected $returns;
14
15
    public function __construct(array $returns)
16
    {
17
        $this->returns = $returns;
18
    }
19
20
    public function signalHandler(int $signo): void
21
    {
22
        echo 'ExampleExecutable process ', $signo, "\n";
23
        if (SIGHUP === $signo) {
24
            $this->counter = 0;
25
        }
26
    }
27
28
    public function runOnce(): bool
29
    {
30
        $return = array_key_exists($this->counter, $this->returns) ? $this->returns[$this->counter] : false;
31
        echo "Try to run $this->counter time: ", ($return) ? 'TRUE' : 'FALSE', "\n";
32
        $this->counter = $this->counter + 1;
33
        return $return;
34
    }
35
}
36