Conditions | 5 |
Paths | 10 |
Total Lines | 18 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 5 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
32 | 5 | public function handle(ParsedRoute $route) |
|
33 | { |
||
34 | 5 | $segments = explode("::", $route->controller()); |
|
35 | 5 | $controller = $segments[0]; |
|
36 | 5 | $action = count($segments) > 1 ? $segments[1] : "index"; |
|
37 | 5 | if (method_exists($controller, $action)) { |
|
38 | 4 | if (!isset($this->request)) { |
|
39 | 3 | $this->request = Request::createFromGlobals(); |
|
40 | 3 | } |
|
41 | 4 | $params = [$this->request, new Response()]; |
|
42 | 4 | if (count($route->params())) { |
|
43 | 1 | $params[] = $route->params(); |
|
44 | 1 | } |
|
45 | 4 | return call_user_func_array([new $controller(), $action], $params); |
|
46 | } else { |
||
47 | 1 | throw new RuntimeException("No method {$action} in controller {$segments[0]}"); |
|
48 | } |
||
49 | } |
||
50 | } |
||
51 |