| Conditions | 4 |
| Paths | 8 |
| Total Lines | 54 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 80 | public function getForm($action = false) |
||
| 81 | { |
||
| 82 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 83 | |||
| 84 | if (!$action) { |
||
| 85 | $action = $_SERVER['REQUEST_URI']; |
||
| 86 | } |
||
| 87 | $title = $this->isNew() ? \_AM_WFDOWNLOADS_MIME_CREATEF : \_AM_WFDOWNLOADS_MIME_MODIFYF; |
||
| 88 | |||
| 89 | $form = new \XoopsThemeForm($title, 'form_error', $action, 'post', true); |
||
| 90 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 91 | // mime_ext |
||
| 92 | $mime_ext_text = new \XoopsFormText(\_AM_WFDOWNLOADS_MIME_EXTF, 'mime_ext', 5, 60, $this->getVar('mime_ext', 'e')); |
||
| 93 | $mime_ext_text->setDescription(\_AM_WFDOWNLOADS_MIME_EXTF_DESC); |
||
| 94 | $form->addElement($mime_ext_text, true); |
||
| 95 | // mime_name |
||
| 96 | $mime_name_text = new \XoopsFormText(\_AM_WFDOWNLOADS_MIME_NAMEF, 'mime_name', 50, 255, $this->getVar('mime_name', 'e')); |
||
| 97 | $mime_name_text->setDescription(\_AM_WFDOWNLOADS_MIME_NAMEF_DESC); |
||
| 98 | $form->addElement($mime_name_text, true); |
||
| 99 | // mime_type |
||
| 100 | $mime_type_textarea = new \XoopsFormTextArea(\_AM_WFDOWNLOADS_MIME_TYPEF, 'mime_type', $this->getVar('mime_types', 'e')); |
||
| 101 | $mime_type_textarea->setDescription(\_AM_WFDOWNLOADS_MIME_TYPEF_DESC); |
||
| 102 | $form->addElement($mime_type_textarea, 7, 60); |
||
| 103 | // mime_admin |
||
| 104 | $madmin_radio = new \XoopsFormRadioYN(\_AM_WFDOWNLOADS_MIME_ADMINF, 'mime_admin', $this->getVar('mime_admin', 'e')); |
||
| 105 | $form->addElement($madmin_radio); |
||
| 106 | // mime_user |
||
| 107 | $muser_radio = new \XoopsFormRadioYN(\_AM_WFDOWNLOADS_MIME_USERF, 'mime_user', $this->getVar('mime_user', 'e')); |
||
| 108 | $form->addElement($muser_radio); |
||
| 109 | // op |
||
| 110 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 111 | // buttons |
||
| 112 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 113 | if ($this->isNew()) { |
||
| 114 | $butt_create = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_MIME_CREATE, 'submit'); |
||
| 115 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'mimetype.save\'"'); |
||
| 116 | $buttonTray->addElement($butt_create); |
||
| 117 | $butt_clear = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_MIME_CLEAR, 'reset'); |
||
| 118 | $buttonTray->addElement($butt_clear); |
||
| 119 | $butt_cancel = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_MIME_CANCEL, 'button'); |
||
| 120 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 121 | $buttonTray->addElement($butt_cancel); |
||
| 122 | } else { |
||
| 123 | $form->addElement(new \XoopsFormHidden('mime_id', $this->getVar('mime_id'))); |
||
| 124 | $butt_create = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_MIME_MODIFY, 'submit'); |
||
| 125 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'mimetype.save\'"'); |
||
| 126 | $buttonTray->addElement($butt_create); |
||
| 127 | $butt_cancel = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_MIME_CANCEL, 'button'); |
||
| 128 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 129 | $buttonTray->addElement($butt_cancel); |
||
| 130 | } |
||
| 131 | $form->addElement($buttonTray); |
||
| 132 | |||
| 133 | return $form; |
||
| 134 | } |
||
| 136 |