Conditions | 9 |
Paths | 132 |
Total Lines | 61 |
Code Lines | 38 |
Lines | 16 |
Ratio | 26.23 % |
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 |
||
29 | public function resource($descriptionGroup, $prefix, $controller, array $except = [], Closure $routes = null) |
||
30 | { |
||
31 | $exceptAll = false; |
||
32 | |||
33 | if (isset($except[0])) { |
||
34 | $exceptAll = $except[0] == '*'; |
||
35 | } |
||
36 | |||
37 | if (!$exceptAll) { |
||
38 | View Code Duplication | if (!in_array('index', $except)) { |
|
39 | $this->get($prefix, [ |
||
40 | 'as' => $prefix.'.index', |
||
41 | 'uses' => $controller.'@index', |
||
42 | 'description' => 'Buscar todos', |
||
43 | 'descriptionGroup' => $descriptionGroup, |
||
44 | ]); |
||
45 | } |
||
46 | |||
47 | if (!in_array('show', $except)) { |
||
48 | $this->get($prefix.'/{id:[0-9]+}', [ |
||
49 | 'as' => $prefix.'.show', |
||
50 | 'uses' => $controller.'@show', |
||
51 | 'description' => 'Buscar um', |
||
52 | 'descriptionGroup' => $descriptionGroup, |
||
53 | ]); |
||
54 | } |
||
55 | |||
56 | if (!in_array('store', $except)) { |
||
57 | $this->post($prefix, [ |
||
58 | 'as' => $prefix.'.store', |
||
59 | 'uses' => $controller.'@store', |
||
60 | 'description' => 'Cadastrar', |
||
61 | 'descriptionGroup' => $descriptionGroup, |
||
62 | ]); |
||
63 | } |
||
64 | |||
65 | View Code Duplication | if (!in_array('update', $except)) { |
|
66 | $this->put($prefix.'/{id:[0-9]+}', [ |
||
67 | 'as' => $prefix.'.update', |
||
68 | 'uses' => $controller.'@update', |
||
69 | 'description' => 'Editar', |
||
70 | 'descriptionGroup' => $descriptionGroup, |
||
71 | ]); |
||
72 | } |
||
73 | |||
74 | if (!in_array('destroy', $except)) { |
||
75 | $this->delete($prefix.'/{id:[0-9]+}', [ |
||
76 | 'as' => $prefix.'.destroy', |
||
77 | 'uses' => $controller.'@destroy', |
||
78 | 'description' => 'Excluir', |
||
79 | 'descriptionGroup' => $descriptionGroup, |
||
80 | ]); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | if ($routes instanceof Closure) { |
||
85 | $routes($descriptionGroup, $prefix, $controller); |
||
86 | } |
||
87 | |||
88 | return $this; |
||
89 | } |
||
90 | } |
||
91 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.