@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace HnrAzevedo\Router; |
| 6 | 6 | |
@@ -12,28 +12,28 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | protected function hasRouteName(string $name): void |
| 14 | 14 | { |
| 15 | - if(!isset($this->routesName[$name])) { |
|
| 15 | + if (!isset($this->routesName[$name])) { |
|
| 16 | 16 | throw new \RuntimeException("There is no route named with {$name}"); |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | protected function isInNameGroup(): void |
| 21 | 21 | { |
| 22 | - if(!is_null($this->getGroup())) { |
|
| 22 | + if (!is_null($this->getGroup())) { |
|
| 23 | 23 | throw new \RuntimeException("It is not allowed to assign names to groups"); |
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | protected function isInPseudGroup(): void |
| 28 | 28 | { |
| 29 | - if(!is_null($this->getGroup())) { |
|
| 29 | + if (!is_null($this->getGroup())) { |
|
| 30 | 30 | throw new \RuntimeException("To assign actions before or after the execution of the route, use beforeGroup or afterGroup"); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | protected function existRouteName(string $name): void |
| 35 | 35 | { |
| 36 | - if(isset($this->routesName[$name])) { |
|
| 36 | + if (isset($this->routesName[$name])) { |
|
| 37 | 37 | throw new \RuntimeException("There is already a route named with {$name}"); |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -41,35 +41,35 @@ discard block |
||
| 41 | 41 | protected function checkMethod(array $route, $method): void |
| 42 | 42 | { |
| 43 | 43 | $hasMethod = false; |
| 44 | - foreach(explode('|', $route['method']) as $routeMethod){ |
|
| 45 | - if(@preg_match("/{$routeMethod}/", $method) !== 0 || $method === '*') { |
|
| 44 | + foreach (explode('|', $route['method']) as $routeMethod) { |
|
| 45 | + if (@preg_match("/{$routeMethod}/", $method) !== 0 || $method === '*') { |
|
| 46 | 46 | $hasMethod = true; |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | - if(!$hasMethod) { |
|
| 49 | + if (!$hasMethod) { |
|
| 50 | 50 | throw new \Exception('This route is not released for the accessed method'); |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | protected function throwCallable($value): void |
| 55 | 55 | { |
| 56 | - if(is_callable($value)) { |
|
| 56 | + if (is_callable($value)) { |
|
| 57 | 57 | throw new \Exception('Passing functions as attributes is not allowed'); |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | protected function checkControllerMeth(string $controllerMeth): void |
| 62 | 62 | { |
| 63 | - $routeURI = str_replace(['{?','{','}'], '', urldecode(unserialize($this->current()['uri'])->getPath())); |
|
| 63 | + $routeURI = str_replace(['{?', '{', '}'], '', urldecode(unserialize($this->current()['uri'])->getPath())); |
|
| 64 | 64 | |
| 65 | 65 | $controller = (string) explode('@', $controllerMeth)[0]; |
| 66 | 66 | $method = (string) explode('@', $controllerMeth)[1]; |
| 67 | 67 | |
| 68 | - if(!class_exists($controller)) { |
|
| 68 | + if (!class_exists($controller)) { |
|
| 69 | 69 | throw new \RuntimeException("Controller not found in route URI {$routeURI}"); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if(!method_exists($controller, $method)) { |
|
| 72 | + if (!method_exists($controller, $method)) { |
|
| 73 | 73 | throw new \RuntimeException("Method {$method} not found in controller {$controller} in route URI {$routeURI}"); |
| 74 | 74 | } |
| 75 | 75 | |