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

FallbackRouter::showFallbackSite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 2
rs 10
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