Passed
Push — dev ( 915030...7801e0 )
by Janko
23:47 queued 09:25
created

FallbackRouter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A showFallbackSite() 0 12 2
1
<?php
2
3
namespace Stu\Module\Control\Router;
4
5
use Stu\Module\Control\GameControllerInterface;
6
use Stu\Module\Control\Router\Handler\FallbackHandlerInterface;
7
8
class FallbackRouter implements FallbackRouterInterface
9
{
10
    /** @param array<FallbackHandlerInterface> $handlers */
11 4
    public function __construct(
12
        private array $handlers
13 4
    ) {}
14
15 2
    public function showFallbackSite(FallbackRouteException $e, GameControllerInterface $game): void
16
    {
17 2
        $className = get_class($e);
18 2
        if (!array_key_exists($className, $this->handlers)) {
19 1
            throw new FallbackRouteException(
20 1
                sprintf('no fallback handler for exception class %s', $className),
21 1
                1,
22 1
                $e
23 1
            );
24
        }
25
26 1
        $this->handlers[$className]->handle($e, $game);
27
    }
28
}
29