| Conditions | 13 | 
| Paths | 521 | 
| Total Lines | 57 | 
| Code Lines | 25 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 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 | ||
| 173 | public function match() | ||
| 174 |     { | ||
| 175 | if (!is_callable($this->classNameBuilder)) | ||
| 176 |             throw \LogicException("No class name builder found"); | ||
|  | |||
| 177 | |||
| 178 | /* | ||
| 179 | * Key value pairs builder: | ||
| 180 | * Searches for the pattern /var1/value1/var2/value2 and converts it to var1 => value1, var2 => value2 | ||
| 181 | */ | ||
| 182 |         if (array_key_exists('params', $_GET)) | ||
| 183 |         { | ||
| 184 | $keypairs = $this->parseRequestParameters($_GET["params"]); | ||
| 185 | unset($_GET["params"]); | ||
| 186 | $_GET = array_merge($_GET, $keypairs); | ||
| 187 | } | ||
| 188 | |||
| 189 | /* | ||
| 190 | * Route builder: | ||
| 191 | * The route is built by default from the URL as follow | ||
| 192 | * www.example.com/module/controller/view | ||
| 193 | */ | ||
| 194 | |||
| 195 | $module = (is_null($this->identifiers["module"]) || empty($this->identifiers["module"])) | ||
| 196 | ? $this->routes["defaults"]["module"] : $this->identifiers["module"]; | ||
| 197 | |||
| 198 | if (!array_key_exists($module, $this->routes)) | ||
| 199 |             throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); | ||
| 200 | |||
| 201 | $controller = (is_null($this->identifiers["controller"]) || empty($this->identifiers["controller"])) | ||
| 202 | ? $this->routes[$module]["controller"] : $this->identifiers["controller"]; | ||
| 203 | |||
| 204 | $view = (is_null($this->identifiers["view"]) || empty($this->identifiers["view"])) | ||
| 205 | ? $this->routes[$module]["view"] : $this->identifiers["view"]; | ||
| 206 | |||
| 207 | $fqn_controller = call_user_func($this->classNameBuilder, $module, $controller); | ||
| 208 | |||
| 209 | if (class_exists($fqn_controller)) | ||
| 210 |         { | ||
| 211 |             try { | ||
| 212 | $this->controller = new $fqn_controller; | ||
| 213 | } | ||
| 214 | # change context, in terms of Router MethodNotFoundException or | ||
| 215 | # PrivateMethodExecutionException is a PageNotfoundException | ||
| 216 | catch (Exception\MethodNotFoundException $e) | ||
| 217 |             { | ||
| 218 | throw new Exception\PageNotFoundException($e->getMessage(), $e->getCode(), $e); | ||
| 219 | } | ||
| 220 | catch (Exception\PrivateMethodExecutionException $e) | ||
| 221 |             { | ||
| 222 | throw new Exception\PageNotFoundException($e->getMessage(), $e->getCode(), $e); | ||
| 223 | } | ||
| 224 | |||
| 225 | # in controller terms, a view is a method | ||
| 226 | $this->controller->setMethod($view); | ||
| 227 | } | ||
| 228 | else | ||
| 229 |             throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); | ||
| 230 | } | ||
| 319 | } |