Passed
Pull Request — main (#13)
by Chema
02:33
created

Handlers   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 17
ccs 5
cts 5
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getByException() 0 3 1
A handle() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Router;
6
7
use Exception;
8
9
use function get_class;
10
11
final class Handlers
12
{
13
    /** @var array<class-string, callable> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string, callable> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string, callable>.
Loading history...
14
    private array $handlers = [];
15
16
    /**
17
     * @param class-string $exception
18
     */
19 1
    public function handle(string $exception, callable $handler): self
20
    {
21 1
        $this->handlers[$exception] = $handler;
22 1
        return $this;
23
    }
24
25 2
    public function getByException(Exception $exception): ?callable
26
    {
27 2
        return $this->handlers[get_class($exception)] ?? null;
28
    }
29
}
30