Passed
Push — master ( 2f01ca...ac7767 )
by PHPinnacle
06:39
created

StaticDispatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of PHPinnacle/Ensign.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types = 1);
12
13
namespace PHPinnacle\Ensign;
14
15
final class StaticDispatcher implements Dispatcher
16
{
17
    private static $instance;
18
    private $handlers;
19
    private $dispatcher;
20
21 1
    private function __construct()
22
    {
23 1
        $this->handlers   = new HandlerMap();
24 1
        $this->dispatcher = new SignalDispatcher($this->handlers);
25 1
    }
26
27
    /**
28
     * @return self
29
     */
30 1
    public static function instance(): self
31
    {
32 1
        if (null === self::$instance) {
33 1
            self::$instance = new self();
34
        }
35
36 1
        return self::$instance;
37
    }
38
39
    /**
40
     * @param string   $signal
41
     * @param callable $action
42
     *
43
     * @return void
44
     */
45
    public function register(string $signal, callable $action): void
46
    {
47
        $this->handlers->register($signal, $action);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function dispatch(string $signal, ...$arguments): Task
54
    {
55
        return $this->dispatcher->dispatch($signal, ...$arguments);
56
    }
57
}
58