| Conditions | 4 |
| Paths | 8 |
| Total Lines | 68 |
| Code Lines | 48 |
| 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 |
||
| 70 | public function getForm() |
||
| 71 | { |
||
| 72 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 73 | $uid = !empty($GLOBALS['xoopsUser']) ? (int)$GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
| 74 | |||
| 75 | $form = new \XoopsThemeForm(\_AM_WFDOWNLOADS_MIRROR_SNEWMNAMEDESC, 'mirrorform', $_SERVER['REQUEST_URI']); |
||
| 76 | // title |
||
| 77 | $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_MIRROR_FHOMEURLTITLE, 'title', 50, 255, $this->getVar('title', 'e')), true); |
||
| 78 | // homeurl |
||
| 79 | $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_MIRROR_FHOMEURL, 'homeurl', 50, 255, $this->getVar('homeurl', 'e')), true); |
||
| 80 | // location |
||
| 81 | $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_MIRROR_LOCATION, 'location', 50, 255, $this->getVar('location', 'e')), true); |
||
| 82 | // continent |
||
| 83 | $continent_select = new \XoopsFormSelect(\_AM_WFDOWNLOADS_MIRROR_CONTINENT, 'continent', $this->getVar('continent')); |
||
| 84 | $continent_select->addOptionArray( |
||
| 85 | [ |
||
| 86 | \_AM_WFDOWNLOADS_CONT1 => \_AM_WFDOWNLOADS_CONT1, |
||
| 87 | \_AM_WFDOWNLOADS_CONT2 => \_AM_WFDOWNLOADS_CONT2, |
||
| 88 | \_AM_WFDOWNLOADS_CONT3 => \_AM_WFDOWNLOADS_CONT3, |
||
| 89 | \_AM_WFDOWNLOADS_CONT4 => \_AM_WFDOWNLOADS_CONT4, |
||
| 90 | \_AM_WFDOWNLOADS_CONT5 => \_AM_WFDOWNLOADS_CONT5, |
||
| 91 | \_AM_WFDOWNLOADS_CONT6 => \_AM_WFDOWNLOADS_CONT6, |
||
| 92 | \_AM_WFDOWNLOADS_CONT7 => \_AM_WFDOWNLOADS_CONT7, |
||
| 93 | ] |
||
| 94 | ); |
||
| 95 | $form->addElement($continent_select); |
||
| 96 | // downurl |
||
| 97 | $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_MIRROR_DOWNURL, 'downurl', 50, 255, $this->getVar('downurl', 'e')), true); |
||
| 98 | // approve |
||
| 99 | $approved = (0 == $this->getVar('submit')) ? 0 : 1; |
||
| 100 | $approve_checkbox = new \XoopsFormCheckBox(\_AM_WFDOWNLOADS_MIRROR_FAPPROVE, 'approve', $approved); |
||
| 101 | $approve_checkbox->addOption(1, ' '); |
||
| 102 | $form->addElement($approve_checkbox); |
||
| 103 | // lid |
||
| 104 | $form->addElement(new \XoopsFormHidden('lid', (int)$this->getVar('lid'))); |
||
| 105 | // mirror_id |
||
| 106 | $form->addElement(new \XoopsFormHidden('mirror_id', (int)$this->getVar('mirror_id'))); |
||
| 107 | // uid |
||
| 108 | $form->addElement(new \XoopsFormHidden('uid', $uid)); |
||
| 109 | // confirm |
||
| 110 | $form->addElement(new \XoopsFormHidden('confirm', 1)); |
||
| 111 | // op |
||
| 112 | $form->addElement(new \XoopsFormHidden('op', '')); |
||
| 113 | // buttons |
||
| 114 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 115 | if ($this->isNew()) { |
||
| 116 | $createButton = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BSAVE, 'submit'); |
||
| 117 | $createButton->setExtra('onclick="this.form.elements.op.value=\'mirror.save\'"'); |
||
| 118 | $buttonTray->addElement($createButton); |
||
| 119 | $clearButton = new \XoopsFormButton('', '', _RESET, 'reset'); |
||
| 120 | $buttonTray->addElement($clearButton); |
||
| 121 | $cancelButton = new \XoopsFormButton('', '', _CANCEL, 'button'); |
||
| 122 | $cancelButton->setExtra('onclick="history.go(-1)"'); |
||
| 123 | $buttonTray->addElement($cancelButton); |
||
| 124 | } else { |
||
| 125 | $createButton = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BSAVE, 'submit'); |
||
| 126 | $createButton->setExtra('onclick="this.form.elements.op.value=\'mirror.save\'"'); |
||
| 127 | $buttonTray->addElement($createButton); |
||
| 128 | $deleteButton = new \XoopsFormButton('', '', _DELETE, 'submit'); |
||
| 129 | $deleteButton->setExtra('onclick="this.form.elements.op.value=\'mirror.delete\'"'); |
||
| 130 | $buttonTray->addElement($deleteButton); |
||
| 131 | $cancelButton = new \XoopsFormButton('', '', _CANCEL, 'button'); |
||
| 132 | $cancelButton->setExtra('onclick="history.go(-1)"'); |
||
| 133 | $buttonTray->addElement($cancelButton); |
||
| 134 | } |
||
| 135 | $form->addElement($buttonTray); |
||
| 136 | |||
| 137 | return $form; |
||
| 138 | } |
||
| 140 |