| Conditions | 11 |
| Paths | 20 |
| Total Lines | 52 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 91 | public function run() |
||
| 92 | { |
||
| 93 | if (!$this->route) |
||
| 94 | { |
||
| 95 | if (ENVIRONMENT != 'production') |
||
| 96 | show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
||
| 97 | |||
| 98 | if(is_null(Route::get404())) |
||
| 99 | show_404(); |
||
| 100 | |||
| 101 | if (Route::get404()->controller != get_class($this->CI)) |
||
| 102 | Route::trigger404(); |
||
| 103 | } |
||
| 104 | else |
||
| 105 | { |
||
| 106 | if (method_exists($this->CI, $this->route->method)) |
||
| 107 | { |
||
| 108 | $path_args = Route::getRouteArgs($this->route, self::$uri_string); |
||
| 109 | $route_args = Route::compileRoute($this->route)->args; |
||
| 110 | |||
| 111 | // Redirect to 404 if not enough parameters provided |
||
| 112 | |||
| 113 | if(count($path_args) < count($route_args['required'])) |
||
| 114 | redirect(Route::get404()->path); |
||
| 115 | |||
| 116 | if(count($path_args) == 0) |
||
| 117 | { |
||
| 118 | $this->CI->{$this->route->method}(); |
||
| 119 | } |
||
| 120 | else |
||
| 121 | { |
||
| 122 | call_user_func_array( [$this->CI, $this->route->method], array_values($path_args) ); |
||
| 123 | } |
||
| 124 | |||
| 125 | // TODO: Add support to hooks in this execution thread |
||
| 126 | |||
| 127 | $this->CI->output->_display(); |
||
| 128 | exit(0); |
||
| 129 | } |
||
| 130 | else |
||
| 131 | { |
||
| 132 | if (ENVIRONMENT != 'production') |
||
| 133 | show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
||
| 134 | |||
| 135 | if(is_null(Route::get404())) |
||
| 136 | show_404(); |
||
| 137 | |||
| 138 | if (Route::get404()->controller != get_class($this->CI)) |
||
| 139 | Route::trigger404(); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | } |
||
| 143 | } |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.