| Conditions | 10 |
| Paths | 10 |
| Total Lines | 37 |
| Code Lines | 32 |
| 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 |
||
| 22 | function form($user, $json_fname) { |
||
| 23 | $form_desc = json_decode(file_get_contents($json_fname)); |
||
| 24 | page_head_select2($form_desc->title); |
||
| 25 | form_start($form_desc->handler); |
||
| 26 | foreach ($form_desc->fields as $field) { |
||
| 27 | switch ($field->type) { |
||
| 28 | case 'text': |
||
| 29 | case 'integer': |
||
| 30 | case 'float': |
||
| 31 | form_input_text($field->title, $field->name); |
||
| 32 | break; |
||
| 33 | case 'file_select': |
||
| 34 | $items = sb_file_select($user, $field->suffix); |
||
| 35 | form_select($field->title, $field->name, $items); |
||
| 36 | break; |
||
| 37 | case 'file_select_multi': |
||
| 38 | $items = sb_file_select($user, $field->suffix); |
||
| 39 | form_select2_multi( |
||
| 40 | $field->title, $field->name, $items, null, "id=$field->name" |
||
| 41 | ); |
||
| 42 | break; |
||
| 43 | case 'select': |
||
| 44 | form_select($field->title, $field->name, $field->items); |
||
| 45 | break; |
||
| 46 | case 'select_multi': |
||
| 47 | form_select2_multi( |
||
| 48 | $field->title, $field->name, $field->items, |
||
| 49 | null, "id=$field->name" |
||
| 50 | ); |
||
| 51 | break; |
||
| 52 | case 'radio': |
||
|
|
|||
| 53 | break; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | form_submit('OK'); |
||
| 57 | form_end(); |
||
| 58 | page_tail(); |
||
| 59 | } |
||
| 65 |