RouteParamsRegistry::getParameter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
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