| Conditions | 4 |
| Paths | 8 |
| Total Lines | 67 |
| Code Lines | 49 |
| 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 |
||
| 68 | public function getForm() |
||
| 69 | { |
||
| 70 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 71 | $uid = !empty($GLOBALS['xoopsUser']) ? (int)$GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
| 72 | |||
| 73 | $form = new \XoopsThemeForm(\_AM_WFDOWNLOADS_REV_SNEWMNAMEDESC, 'reviewform', $_SERVER['REQUEST_URI']); |
||
| 74 | // review: title |
||
| 75 | $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_REV_FTITLE, 'title', 30, 40, $this->getVar('title', 'e')), true); |
||
| 76 | // review: rated |
||
| 77 | $rating_select = new \XoopsFormSelect(\_AM_WFDOWNLOADS_REV_FRATING, 'rated', $this->getVar('rated')); |
||
| 78 | $rating_select->addOptionArray( |
||
| 79 | [ |
||
| 80 | '1' => 1, |
||
| 81 | '2' => 2, |
||
| 82 | '3' => 3, |
||
| 83 | '4' => 4, |
||
| 84 | '5' => 5, |
||
| 85 | '6' => 6, |
||
| 86 | '7' => 7, |
||
| 87 | '8' => 8, |
||
| 88 | '9' => 9, |
||
| 89 | '10' => 10, |
||
| 90 | ] |
||
| 91 | ); |
||
| 92 | $form->addElement($rating_select); |
||
| 93 | // review: review |
||
| 94 | $form->addElement(new \XoopsFormDhtmlTextArea(\_AM_WFDOWNLOADS_REV_FDESCRIPTION, 'review', $this->getVar('review', 'e'), 15, 60), true); |
||
| 95 | // form: approve |
||
| 96 | $approved = (0 == $this->getVar('submit')) ? 0 : 1; |
||
| 97 | $approve_checkbox = new \XoopsFormCheckBox(\_AM_WFDOWNLOADS_REV_FAPPROVE, 'approve', $approved); |
||
| 98 | $approve_checkbox->addOption(1, ' '); |
||
| 99 | $form->addElement($approve_checkbox); |
||
| 100 | // review: lid |
||
| 101 | $form->addElement(new \XoopsFormHidden('lid', (int)$this->getVar('lid'))); |
||
| 102 | // review: uid |
||
| 103 | $form->addElement(new \XoopsFormHidden('uid', $uid)); |
||
| 104 | // review: review_id |
||
| 105 | $form->addElement(new \XoopsFormHidden('review_id', (int)$this->getVar('review_id'))); |
||
| 106 | // form: confirm |
||
| 107 | $form->addElement(new \XoopsFormHidden('confirm', 1)); |
||
| 108 | // form: op |
||
| 109 | $form->addElement(new \XoopsFormHidden('op', '')); |
||
| 110 | // form: buttons |
||
| 111 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 112 | if ($this->isNew()) { |
||
| 113 | $butt_create = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BSAVE, 'submit'); |
||
| 114 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'review.save\'"'); |
||
| 115 | $buttonTray->addElement($butt_create); |
||
| 116 | $butt_clear = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BRESET, 'reset'); |
||
| 117 | $buttonTray->addElement($butt_clear); |
||
| 118 | $butt_cancel = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BCANCEL, 'button'); |
||
| 119 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 120 | $buttonTray->addElement($butt_cancel); |
||
| 121 | } else { |
||
| 122 | $butt_create = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BSAVE, 'submit'); |
||
| 123 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'review.save\'"'); |
||
| 124 | $buttonTray->addElement($butt_create); |
||
| 125 | $butt_delete = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BDELETE, 'submit'); |
||
| 126 | $butt_delete->setExtra('onclick="this.form.elements.op.value=\'review.delete\'"'); |
||
| 127 | $buttonTray->addElement($butt_delete); |
||
| 128 | $butt_cancel = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BCANCEL, 'button'); |
||
| 129 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 130 | $buttonTray->addElement($butt_cancel); |
||
| 131 | } |
||
| 132 | $form->addElement($buttonTray); |
||
| 133 | |||
| 134 | return $form; |
||
| 135 | } |
||
| 137 |