Total Complexity | 7 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | final class RouteArgsResolver |
||
10 | { |
||
11 | /** |
||
12 | * @var callable[] |
||
13 | */ |
||
14 | private $resolvers = []; |
||
15 | |||
16 | /** |
||
17 | * @param RouteArgsResolverInterface $routeArgsResolver |
||
18 | * |
||
19 | * @return RouteArgsResolver |
||
20 | * |
||
21 | * @throws RouteArgsResolverException |
||
22 | */ |
||
23 | 8 | public function add(RouteArgsResolverInterface $routeArgsResolver): self |
|
24 | { |
||
25 | 8 | $keys = $routeArgsResolver->getArgsResolver(); |
|
26 | 8 | foreach ($keys as $key => $callable) { |
|
27 | 8 | $this->isValid($key, $callable); |
|
28 | 7 | $this->resolvers[$key] = $callable; |
|
29 | } |
||
30 | 7 | return $this; |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param string $key |
||
35 | * @param string $value |
||
36 | * |
||
37 | * @return mixed |
||
38 | */ |
||
39 | 4 | public function resolve(string $key, string $value) |
|
40 | { |
||
41 | 4 | return $this->resolvers[$key]($value); |
|
42 | } |
||
43 | |||
44 | 4 | public function has(string $key): bool |
|
45 | { |
||
46 | 4 | return isset($this->resolvers[$key]); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $key |
||
51 | * @param mixed $callable |
||
52 | * |
||
53 | * @throws RouteArgsResolverException |
||
54 | */ |
||
55 | 8 | private function isValid(string $key, $callable): void |
|
63 | } |
||
64 | 7 | } |
|
65 | } |
||
66 |