| Conditions | 5 |
| Paths | 8 |
| Total Lines | 25 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | public function addController(array $input): void |
||
| 27 | { |
||
| 28 | $controllers = []; |
||
| 29 | foreach ($input as $controller) { |
||
| 30 | $key = array_key_first($controller); |
||
| 31 | $controllers[$key] = $controller[$key]; |
||
| 32 | } |
||
| 33 | |||
| 34 | foreach ($controllers as $slug => $value) { |
||
| 35 | if (!is_subclass_of($value['controller'], Controller::class)) { |
||
| 36 | throw new \RuntimeException(sprintf( |
||
| 37 | 'Class `%s` must be a instance of `%s`', |
||
| 38 | $value['controller'], |
||
| 39 | Controller::class |
||
| 40 | )); |
||
| 41 | } |
||
| 42 | |||
| 43 | if (in_array($slug, Application::$reservedWords)) { |
||
| 44 | throw new \RuntimeException(sprintf( |
||
| 45 | 'The slug `%s` is reserved word', |
||
| 46 | $slug |
||
| 47 | )); |
||
| 48 | } |
||
| 49 | |||
| 50 | Router::controller($slug, $value['uri'], $value['controller']); |
||
| 51 | } |
||
| 54 | } |