| Conditions | 10 |
| Paths | 64 |
| Total Lines | 47 |
| Code Lines | 29 |
| 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 |
||
| 66 | public function generateDetailHtml($detail,$values){ |
||
| 67 | $type = $detail->type; |
||
| 68 | |||
| 69 | if($type === 'select'){ |
||
| 70 | $html = ''; |
||
| 71 | $html .= '<select class="form-control">'; |
||
| 72 | $html .= '<option value="">Seleziona</option>'; |
||
| 73 | foreach($values as $value){ |
||
| 74 | $html .= '<option value="'.$value->id.'">'.$value->value.'</option>'; |
||
| 75 | } |
||
| 76 | $html .= '</select>'; |
||
| 77 | } |
||
| 78 | |||
| 79 | if($type === 'checkbox'){ |
||
| 80 | $html = ''; |
||
| 81 | |||
| 82 | foreach($values as $value){ |
||
| 83 | $html .= '<div class="custom-control custom-checkbox">'; |
||
| 84 | $html .= '<input type="checkbox" class="custom-control-input" id="defaultUnchecked_'.$value->id.'">'; |
||
| 85 | $html .= '<label class="custom-control-label" for="defaultUnchecked_'.$value->id.'">'.$value->value.'</label>'; |
||
| 86 | $html .= '</div>'; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if($type === 'radio'){ |
||
| 91 | $html = ''; |
||
| 92 | foreach($values as $value){ |
||
| 93 | $html .= '<div class="custom-control custom-radio">'; |
||
| 94 | $html .= '<input name="radio_'.$value->detail_id.'" type="radio" class="custom-control-input" id="defaultradio_'.$value->id.'">'; |
||
| 95 | $html .= '<label class="custom-control-label" for="defaultradio_'.$value->id.'">'.$value->value.'</label>'; |
||
| 96 | $html .= '</div>'; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | if($type === 'text'){ |
||
| 101 | $html = '<input type="text" class="form-control" id="text_' . $detail->id . '">'; |
||
| 102 | } |
||
| 103 | |||
| 104 | if($type === 'number'){ |
||
| 105 | $html = '<input type="number" class="form-control" id="number_' . $detail->id . '">'; |
||
| 106 | } |
||
| 107 | |||
| 108 | if($type === 'textarea'){ |
||
| 109 | $html = '<textarea class="form-control" id="textarea_'.$detail->id.'"></textarea>'; |
||
| 110 | } |
||
| 111 | |||
| 112 | return $html; |
||
|
|
|||
| 113 | } |
||
| 115 |