Passed
Pull Request — master (#3)
by PHPinnacle
03:21
created

HandlerRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 28
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A acquire() 0 3 1
A register() 0 5 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 HandlerRegistry
16
{
17
    /**
18
     * @var Handler[]
19
     */
20
    private $handlers = [];
21
22
    /**
23
     * @param string   $name
24
     * @param callable $handler
25
     *
26
     * @return self
27
     */
28 7
    public function register(string $name, callable $handler): self
29
    {
30 7
        $this->handlers[$name] = $handler instanceof Handler ? $handler : new Handler($handler);
31
32 7
        return $this;
33
    }
34
35
    /**
36
     * @param string $name
37
     *
38
     * @return Handler|null
39
     */
40 8
    public function acquire(string $name): ?Handler
41
    {
42 8
        return $this->handlers[$name] ?? Handler::unknown($name);
43
    }
44
}
45