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

Handlers::handle()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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