Conditions | 8 |
Paths | 9 |
Total Lines | 61 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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(is_null(Route::get404())) |
||
96 | // show_404(); |
||
97 | |||
98 | if (Route::get404()->controller != get_class($this->CI)) |
||
99 | { |
||
100 | if (ENVIRONMENT != 'production') |
||
101 | { |
||
102 | show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
||
103 | } else |
||
104 | { |
||
105 | //redirect(Route::get404()->path); |
||
106 | Route::trigger404(); |
||
107 | } |
||
108 | } |
||
109 | } else |
||
110 | { |
||
111 | if (method_exists($this->CI, $this->route->method)) |
||
112 | { |
||
113 | $path_args = Route::getRouteArgs($this->route, self::$uri_string); |
||
114 | $route_args = Route::compileRoute($this->route)->args; |
||
115 | |||
116 | |||
117 | |||
118 | // Redirect to 404 if not enough parameters provided |
||
119 | |||
120 | if(count($path_args) < count($route_args['required'])) |
||
121 | redirect(Route::get404()->path); |
||
122 | |||
123 | if(count($path_args) == 0) |
||
124 | { |
||
125 | $this->CI->{$this->route->method}(); |
||
126 | } |
||
127 | else |
||
128 | { |
||
129 | call_user_func_array( [$this->CI, $this->route->method], array_values($path_args) ); |
||
130 | } |
||
131 | |||
132 | |||
133 | // TODO: Add support to hooks in this execution thread |
||
134 | |||
135 | $this->CI->output->_display(); |
||
136 | exit(0); |
||
137 | } |
||
138 | else |
||
139 | { |
||
140 | if (ENVIRONMENT != 'production') |
||
141 | { |
||
142 | show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
||
143 | } |
||
144 | else |
||
145 | { |
||
146 | //redirect(Route::get404()->path); |
||
147 | Route::trigger404(); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | } |
Adding a
@return
annotation 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.