Conditions | 8 |
Paths | 18 |
Total Lines | 63 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
139 | public function router(SystemInterface &$core, &$result) |
||
140 | { |
||
141 | //elapsed('Start routing'); |
||
142 | // Flag for matching SamsonPHP asynchronous requests |
||
143 | $async = $this->isAsynchronousRequest(); |
||
144 | // Get HTTP request path |
||
145 | $path = $_SERVER['REQUEST_URI']; |
||
146 | // Get HTTP request method |
||
147 | $method = $_SERVER['REQUEST_METHOD']; |
||
148 | // Prepend HTTP request type, true - asynchronous |
||
149 | $method = ($async ? GenericRouteGenerator::ASYNC_PREFIX : '').$method; |
||
150 | |||
151 | $result = false; |
||
152 | |||
153 | //$path = strtok(rtrim($method.'/'.ltrim($path, '/'),'/'),'?'); |
||
154 | |||
155 | /** @var mixed $routeMetadata Dispatching result route metadata */ |
||
156 | if (is_array($routeMetadata = call_user_func(Core::ROUTING_LOGIC_FUNCTION, $path, $method))) { |
||
157 | // Get callback info |
||
158 | list($module, $method) = explode("#", $routeMetadata[2]); |
||
159 | // Get module |
||
160 | $module = $core->module($module); |
||
161 | // Create callback |
||
162 | $callback = array($module, $method); |
||
163 | |||
164 | // Check if we have vaild callback |
||
165 | if (is_callable($callback)) { |
||
166 | // Routing result |
||
167 | $result = call_user_func_array( |
||
168 | $callback, |
||
169 | $this->parseParameters($callback, $routeMetadata[1]) |
||
170 | ); |
||
171 | |||
172 | // Get object from callback and set it as current active core module |
||
173 | $core->active($module); |
||
174 | |||
175 | // If this route is asynchronous |
||
176 | if ($async) { |
||
177 | // Set async response |
||
178 | $core->async(true); |
||
179 | |||
180 | // If controller action has failed |
||
181 | if (!isset($result['status']) || !$result['status']) { |
||
182 | $result['message'] = "\n" . 'Event failed: ' . $routeMetadata[0]; |
||
183 | $result['status'] = 0; |
||
184 | } |
||
185 | |||
186 | // Encode event result as json object |
||
187 | echo json_encode($result, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); |
||
188 | |||
189 | // Mark as successful |
||
190 | $result = true; |
||
191 | } |
||
192 | } |
||
193 | |||
194 | // If no result is passed - consider success |
||
195 | $result = $result !== false ? true : $result; |
||
196 | } |
||
197 | |||
198 | //elapsed('Finished routing'); |
||
199 | // Return true or false depending on $result |
||
200 | return $result; |
||
201 | } |
||
202 | } |
||
203 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: