| Conditions | 11 |
| Paths | 2 |
| Total Lines | 16 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 81 | public function resource(string $route, $handler, string $name = null, string $model_id_name = null): void |
||
| 82 | { |
||
| 83 | $sanitRoute = substr($route, 0, 1) == '/' ? substr_replace($route, '', 0, 1) : $route; |
||
| 84 | $sanitRoute = (explode('/', $sanitRoute))[0]; |
||
|
|
|||
| 85 | $singularized_route = singularize($sanitRoute); |
||
| 86 | $model_id_name = $model_id_name ?? $singularized_route; |
||
| 87 | |||
| 88 | $this->addRoute("GET", $route, $handler.":list", ($name ? "{$name}.list" : null)); |
||
| 89 | $this->addRoute("GET", "{$route}/home", $handler.":list", ($name ? "{$name}.home" : null)); |
||
| 90 | $this->addRoute("GET", "{$route}/home/{search}/{page}", $handler.":list", ($name ? "{$name}.searchGet" : null)); |
||
| 91 | $this->addRoute("GET", $singularized_route, $handler.":create", ($name ? "{$name}.create" : null)); |
||
| 92 | $this->addRoute("GET", singularize($route)."/{".$model_id_name."}", $handler.":edit", ($name ? "{$name}.edit" : null)); |
||
| 93 | $this->addRoute("POST", "{$route}/search", $handler.":search", ($name ? "{$name}.searchPost" : null)); |
||
| 94 | $this->addRoute("POST", $singularized_route, $handler.":store", ($name ? "{$name}.store" : null)); |
||
| 95 | $this->addRoute("POST", singularize($route)."/{".$model_id_name."}", $handler.":update", ($name ? "{$name}.update" : null)); |
||
| 96 | $this->addRoute("DELETE", singularize($route)."/{".$model_id_name."}", $handler.":delete", ($name ? "{$name}.delete" : null)); |
||
| 97 | } |
||
| 98 | } |