Conditions | 10 |
Paths | 1 |
Total Lines | 14 |
Code Lines | 11 |
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 |
||
81 | public function resource(string $route, $handler, string $name = null): void |
||
82 | { |
||
83 | $singularized_route = singularize($route); |
||
84 | $key_id = "{" . str_replace("/", "", $singularized_route) ."_id}"; |
||
85 | |||
86 | $this->addRoute("GET", $route, $handler.":list", ($name ? "{$name}-list" : null)); |
||
87 | $this->addRoute("GET", "{$route}/home", $handler.":list", ($name ? "{$name}-home" : null)); |
||
88 | $this->addRoute("GET", "{$route}/home/{search}/{page}", $handler.":list", ($name ? "{$name}-is-search" : null)); |
||
89 | $this->addRoute("GET", $singularized_route, $handler.":create", ($name ? "{$name}-create" : null)); |
||
90 | $this->addRoute("GET", singularize($route)."/{$key_id}", $handler.":edit", ($name ? "{$name}-edit" : null)); |
||
91 | $this->addRoute("POST", "{$route}/search", $handler.":search", ($name ? "{$name}-search" : null)); |
||
92 | $this->addRoute("POST", $singularized_route, $handler.":store", ($name ? "{$name}-store" : null)); |
||
93 | $this->addRoute("POST", singularize($route)."/{$key_id}", $handler.":update", ($name ? "{$name}-update" : null)); |
||
94 | $this->addRoute("DELETE", singularize($route)."/{$key_id}", $handler.":delete", ($name ? "{$name}-delete" : null)); |
||
95 | |||
97 | } |