RouteParamsRegistry   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
ccs 9
cts 11
cp 0.8182
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setRouteParams() 0 3 1
A getParameter() 0 7 2
A getRouteParams() 0 7 2
1
<?php declare(strict_types = 1);
2
3
/**
4
 * This file is part of the Simplex package.
5
 *
6
 * (c) Freddie Frantzen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Simplex\Routing;
12
13
class RouteParamsRegistry
14
{
15
    public const CONTROLLER_KEY = '_controller';
16
17
    public const ROUTE_KEY = '_route';
18
19
    private $routeParams;
20
21 3
    public function getRouteParams(): array
22
    {
23 3
        if (!isset($this->routeParams)) {
24
            throw new \LogicException('Route params have not been set');
25
        }
26
27 3
        return $this->routeParams;
28
    }
29
30 3
    public function setRouteParams(array $routeParams): void
31
    {
32 3
        $this->routeParams = $routeParams;
33 3
    }
34
35 2
    public function getParameter(string $key): string
36
    {
37 2
        if (!isset($this->routeParams[$key])) {
38
            throw new \RuntimeException("Route parameter '$key' does not exist'");
39
        }
40
41 2
        return $this->routeParams[$key];
42
    }
43
}
44