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

StaticDispatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 61.53%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 41
ccs 8
cts 13
cp 0.6153
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 3 1
A __construct() 0 4 1
A register() 0 3 1
A instance() 0 7 2
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