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

RouteParamsRegistry   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
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
    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