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

ExampleExecutable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A signalHandler() 0 5 2
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