Passed
Branch v0.2 (3b8de8)
by Freddie
05:06
created

RouteParamsRegistry::getParameter()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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
    const CONTROLLER_KEY = '_controller';
16
17
    const ROUTE_KEY = '_route';
18
19
    private $routeParams;
20
21
    public function getRouteParams(): array
22
    {
23
        if (!isset($this->routeParams)) {
24
            throw new \LogicException('Route params have not been set');
25
        }
26
27
        return $this->routeParams;
28
    }
29
30
    public function setRouteParams(array $routeParams)
31
    {
32
        $this->routeParams = $routeParams;
33
    }
34
35
    public function getParameter(string $key): string
36
    {
37
        if (!isset($this->routeParams[$key])) {
38
            throw new \RuntimeException("Route parameter '$key' does not exist'");
39
        }
40
41
        return $this->routeParams[$key];
42
    }
43
}
44