Passed
Push — master ( 35afea...a9381d )
by Dirk
02:07
created

SignalHandler::setWorker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Resque;
6
7
use Resque\Dispatchers\Noop;
8
use Resque\Dispatchers\PayloadDispatcher;
0 ignored issues
show
Bug introduced by
The type Resque\Dispatchers\PayloadDispatcher was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class SignalHandler
11
{
12
    private $worker = null;
13
    private $dispatcher;
14
15
    private $signals = [
16
        SIGTERM => 'shutdown',
17
        SIGINT => 'shutdown',
18
        SIGQUIT => 'shutdown',
19
        SIGUSR1 => 'pause',
20
        SIGCONT => 'continue',
21
        SIGUSR2 => 'forceShutdown',
22
    ];
23
24
    public function __construct(array $signals = [])
25
    {
26
        foreach ($signals as $type => $signalCallback) {
27
            if (in_array($type, array_keys($this->signals)) && is_callable($signalCallback)) {
28
                $this->signals[$type] = $signalCallback;
29
            }
30
        }
31
        $this->dispatcher = new Noop();
32
    }
33
34
    public function setDispatcher(PayloadDispatcher $dispatcher): void
35
    {
36
        $this->dispatcher = $dispatcher;
37
    }
38
39
    public function setWorker(Worker $worker): void
40
    {
41
        $this->worker = $worker;
42
    }
43
44
    public function register(): void
45
    {
46
        $payload = $this->dispatcher->dispatch(BeforeSignalsRegister::class, ['signals' => $this->signals]);
0 ignored issues
show
Bug introduced by
The type Resque\BeforeSignalsRegister was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
        pcntl_async_signals(true);
48
        foreach ($payload['signals'] as $signalType => $signalHandler) {
49
            pcntl_signal($signalType, [$this->worker, $this->$signalHandler]);
50
        }
51
52
        register_shutdown_function([$this, 'unregisterSignalHandlers']);
53
    }
54
}
55