| Conditions | 10 |
| Paths | 17 |
| Total Lines | 28 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 52 | function get_inputs($form_desc) { |
||
| 53 | $vals = new StdClass; |
||
| 54 | $errs = []; |
||
| 55 | foreach ($form_desc->fields as $field) { |
||
| 56 | switch ($field->type) { |
||
| 57 | case 'text': |
||
| 58 | case 'select': |
||
| 59 | case 'file_select': |
||
| 60 | $err = null; |
||
| 61 | $val = get_str($field->name); |
||
| 62 | break; |
||
| 63 | case 'integer': |
||
| 64 | case 'float': |
||
| 65 | [$val, $err] = get_num($field); |
||
| 66 | break; |
||
| 67 | case 'select_multi': |
||
| 68 | case 'file_select_multi': |
||
| 69 | [$val, $err] = get_multi($field); |
||
| 70 | break; |
||
| 71 | } |
||
| 72 | if ($err) { |
||
|
|
|||
| 73 | $errs[] = [$field->title, $err]; |
||
| 74 | } else { |
||
| 75 | $x = $field->name; |
||
| 76 | $vals->$x = $val; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | return [$vals, $errs]; |
||
| 80 | } |
||
| 83 |