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