Conditions | 6 |
Paths | 18 |
Total Lines | 23 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 6 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | 5 | public function handle(ParsedRoute $route) |
|
16 | { |
||
17 | 5 | $controller = $route->controller(); |
|
18 | 5 | $rawParams = $route->params(); |
|
19 | 5 | foreach ($rawParams as $param => $value) { |
|
20 | 2 | if (strpos($controller, "{".$param."}") !== false) { |
|
21 | 1 | $controller = str_replace("{".$param."}", ucfirst($value), $controller); |
|
22 | 1 | unset($rawParams[$param]); |
|
23 | 1 | } |
|
24 | 5 | } |
|
25 | 5 | $segments = explode("::", $controller); |
|
26 | 5 | $controller = $segments[0]; |
|
27 | 5 | $action = count($segments) > 1 ? $segments[1] : "index"; |
|
28 | 5 | if (method_exists($controller, $action)) { |
|
29 | 4 | $params = []; |
|
30 | 4 | if (count($rawParams)) { |
|
31 | 2 | $params[] = $rawParams; |
|
32 | 2 | } |
|
33 | 4 | return call_user_func_array([new $controller, $action], $params); |
|
34 | } else { |
||
35 | 1 | throw new RuntimeException("No method {$action} in controller {$segments[0]}"); |
|
36 | } |
||
37 | } |
||
38 | } |
||
39 |