| Conditions | 5 |
| Paths | 16 |
| Total Lines | 101 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 getForm($action = false) |
||
| 67 | { |
||
| 68 | global $xoopsDB, $xoopsModule, $xoopsModuleConfig; |
||
| 69 | |||
| 70 | if (false === $action) { |
||
| 71 | $action = $_SERVER['REQUEST_URI']; |
||
| 72 | } |
||
| 73 | $title = $this->isNew() ? \sprintf(\_AM_XHTTPERR_ERROR_ADD) : \sprintf(\_AM_XHTTPERR_ERROR_EDIT); |
||
| 74 | |||
| 75 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 76 | |||
| 77 | $formObj = new \XoopsThemeForm($title, 'form_error', $action, 'post', true); |
||
| 78 | $formObj->setExtra('enctype="multipart/form-data"'); |
||
| 79 | |||
| 80 | // Title |
||
| 81 | $errorTitle = new \XoopsFormText(\_AM_XHTTPERR_ERROR_TITLE, 'error_title', 40, 255, $this->getVar('error_title')); |
||
| 82 | $errorTitle->setDescription(\_AM_XHTTPERR_ERROR_TITLE_DESC); |
||
| 83 | $formObj->addElement($errorTitle, true); |
||
| 84 | unset($errorTitle); |
||
| 85 | // Error number |
||
| 86 | if ($this->isNew()) { |
||
| 87 | $errorStatuscode = new \XoopsFormText(\_AM_XHTTPERR_ERROR_STATUSCODE, 'error_statuscode', 3, 3, $this->getVar('error_statuscode')); |
||
| 88 | } else { |
||
| 89 | $errorStatuscode = new \XoopsFormLabel(\_AM_XHTTPERR_ERROR_STATUSCODE, $this->getVar('error_statuscode')); |
||
| 90 | } |
||
| 91 | $formObj->addElement($errorStatuscode, true); |
||
| 92 | unset($errorStatuscode); |
||
| 93 | // Text |
||
| 94 | $editor_configs = []; |
||
| 95 | $editor_configs['name'] = 'error_text'; |
||
| 96 | $editor_configs['value'] = $this->getVar('error_text', 'e'); |
||
| 97 | $editor_configs['rows'] = 10; |
||
| 98 | $editor_configs['cols'] = 50; |
||
| 99 | $editor_configs['width'] = '100%'; |
||
| 100 | $editor_configs['height'] = '100px'; |
||
| 101 | $editor_configs['editor'] = $GLOBALS['xoopsModuleConfig']['text_editor']; |
||
| 102 | $errorText = new \XoopsFormEditor(\_AM_XHTTPERR_ERROR_TEXT, 'error_text', $editor_configs); |
||
| 103 | $errorText->setDescription(\_AM_XHTTPERR_ERROR_TEXT_DESC); |
||
| 104 | $formObj->addElement($errorText); |
||
| 105 | // Text options |
||
| 106 | $errorTextOptions = new \XoopsFormElementTray(\_AM_XHTTPERR_ERROR_TEXT_OPTIONS, '|', ''); |
||
| 107 | $errorTextOptions->addElement(new \XoopsFormRadioYN(\_AM_XHTTPERR_ERROR_TEXT_HTML, 'error_text_html', $this->getVar('error_text_html'), _YES, _NO)); |
||
| 108 | $errorTextOptions->addElement(new \XoopsFormRadioYN(\_AM_XHTTPERR_ERROR_TEXT_SMILEY, 'error_text_smiley', $this->getVar('error_text_smiley'), _YES, _NO)); |
||
| 109 | $errorTextOptions->addElement(new \XoopsFormRadioYN(\_AM_XHTTPERR_ERROR_TEXT_BREAKS, 'error_text_breaks', $this->getVar('error_text_breaks'), _YES, _NO)); |
||
| 110 | $errorTextOptions->setDescription(\_AM_XHTTPERR_ERROR_TEXT_OPTIONS_DESC); |
||
| 111 | $formObj->addElement($errorTextOptions); |
||
| 112 | unset($errorTextOptions); |
||
| 113 | // Showme |
||
| 114 | $errorShowme = new \XoopsFormRadioYN(\_AM_XHTTPERR_ERROR_STATUS, 'error_showme', $this->getVar('error_showme'), _YES, _NO); |
||
| 115 | $errorShowme->setDescription(\_AM_XHTTPERR_ERROR_STATUS_DESC); |
||
| 116 | $formObj->addElement($errorShowme); |
||
| 117 | unset($errorShowme); |
||
| 118 | |||
| 119 | $formObj->addElement(new \XoopsFormLabel(_AM_XHTTPERR_ERROR_REDIRECT_OPTIONS, '', '')); |
||
| 120 | // Redirect |
||
| 121 | $errorRedirect = new \XoopsFormSelect(\_AM_XHTTPERR_ERROR_REDIRECT, 'error_redirect', $this->getVar('error_redirect'), 1, false); |
||
| 122 | $errorRedirect->addOption(\XHTTPERR_REDIRECT_NO, \_AM_XHTTPERR_ERROR_REDIRECT_OPTION_NO); |
||
| 123 | $errorRedirect->addOption(\XHTTPERR_REDIRECT_URI, \_AM_XHTTPERR_ERROR_REDIRECT_OPTION_URI); |
||
| 124 | $errorRedirect->addOption(\XHTTPERR_REDIRECT_PREVIOUS, \_AM_XHTTPERR_ERROR_REDIRECT_OPTION_PREVIOUS); |
||
| 125 | //$errorRedirect = new \XoopsFormRadioYN(, _YES, _NO); |
||
| 126 | $errorRedirect->setDescription(\_AM_XHTTPERR_ERROR_REDIRECT_DESC); |
||
| 127 | $formObj->addElement($errorRedirect); |
||
| 128 | unset($errorRedirect); |
||
| 129 | // Redirect time |
||
| 130 | $errorRedirectTime = new \XoopsFormText(\_AM_XHTTPERR_ERROR_REDIRECT_TIME, 'error_redirect_time', 2, 2, $this->getVar('error_redirect_time')); |
||
| 131 | $errorRedirectTime->setDescription(\_AM_XHTTPERR_ERROR_REDIRECT_TIME_DESC); |
||
| 132 | $formObj->addElement($errorRedirectTime); |
||
| 133 | unset($errorRedirectTime); |
||
| 134 | /* IN PROGRESS |
||
| 135 | // Redirect message |
||
| 136 | $errorRedirectMessage = new \XoopsFormText(_AM_XHTTPERR_ERROR_REDIRECT_MESSAGE, 'error_redirect_message', 40, 255, $this->getVar('error_redirect_message')); |
||
| 137 | $errorRedirectMessage->setDescription(_AM_XHTTPERR_ERROR_REDIRECT_MESSAGE_DESC); |
||
| 138 | $formObj->addElement($errorRedirectMessage, true); |
||
| 139 | unset($errorRedirectMessage); |
||
| 140 | */ |
||
| 141 | // Redirect uri |
||
| 142 | $errorRedirectUri = new \XoopsFormText(\_AM_XHTTPERR_ERROR_REDIRECT_URI, 'error_redirect_uri', 40, 255, $this->getVar('error_redirect_uri')); |
||
| 143 | $errorRedirectUri->setDescription(\_AM_XHTTPERR_ERROR_REDIRECT_URI_DESC); |
||
| 144 | $formObj->addElement($errorRedirectUri); |
||
| 145 | unset($errorRedirectUri); |
||
| 146 | |||
| 147 | // Captcha |
||
| 148 | \xoops_load('xoopscaptcha'); |
||
| 149 | $formObj->addElement(new \XoopsFormCaptcha(), true); |
||
| 150 | // Hidden Fields |
||
| 151 | $formObj->addElement(new \XoopsFormHidden('op', 'save_error')); |
||
| 152 | if ($this->isNew()) { |
||
| 153 | // NOP |
||
| 154 | } else { |
||
| 155 | $formObj->addElement(new \XoopsFormHidden('error_id', $this->getVar('error_id'))); |
||
| 156 | } |
||
| 157 | // Submit button |
||
| 158 | $buttonTray = new \XoopsFormElementTray(\_AM_XHTTPERR_ACTION, '', ''); |
||
| 159 | $buttonTray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 160 | $buttonTray->addElement(new \XoopsFormButton('', 'reset', _RESET, 'reset')); |
||
| 161 | $cancel_button = new \XoopsFormButton('', 'cancel', _CANCEL, 'button'); |
||
| 162 | $cancel_button->setExtra("onclick='javascript:history.back();'"); |
||
| 163 | $buttonTray->addElement($cancel_button); |
||
| 164 | $formObj->addElement($buttonTray); |
||
| 165 | |||
| 166 | return $formObj; |
||
| 167 | } |
||
| 169 |