| Conditions | 7 |
| Paths | 13 |
| Total Lines | 114 |
| Code Lines | 80 |
| 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 declare(strict_types=1); |
||
| 97 | public function renderForm() |
||
| 98 | {
|
||
| 99 | /** @var Helper $helper */ |
||
| 100 | $helper = Helper::getHelper($this->dirname); |
||
| 101 | /** @var CategoryHandler $categoryHandler */ |
||
| 102 | $categoryHandler = $helper->getHandler('Category');
|
||
| 103 | $catCount = $categoryHandler->getCount(); |
||
| 104 | if (empty($catCount)) {
|
||
| 105 | \xoops_error(\_AM_XOOPSFAQ_ERROR_NO_CATS_EXIST, ''); |
||
| 106 | \xoops_cp_footer(); |
||
| 107 | exit(); |
||
| 108 | } |
||
| 109 | |||
| 110 | require_once \dirname(__DIR__, 3) . '/class/xoopsformloader.php'; |
||
| 111 | |||
| 112 | if ($this->isNew()) {
|
||
| 113 | $caption = \_AM_XOOPSFAQ_CREATE_NEW; |
||
| 114 | } else {
|
||
| 115 | $contentsTitle = $this->getVar('contents_title');
|
||
| 116 | if (\is_scalar($contentsTitle)) {
|
||
| 117 | $caption = \sprintf(\_AM_XOOPSFAQ_MODIFY_ITEM, $contentsTitle); |
||
| 118 | } else {
|
||
| 119 | $caption = ''; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | $form = new \XoopsThemeForm($caption, 'content', $_SERVER['REQUEST_URI'], 'post', true); |
||
| 124 | // $form->addElement(new \XoopsFormHiddenToken()); |
||
| 125 | $form->addElement(new \XoopsFormHidden('op', 'save'));
|
||
| 126 | $form->addElement(new \XoopsFormHidden('contents_id', $this->getVar('contents_id', 'e')));
|
||
| 127 | |||
| 128 | // Active |
||
| 129 | $contents_active = new \XoopsFormRadioYN(\_AM_XOOPSFAQ_E_CONTENTS_ACTIVE, 'contents_active', $this->getVar('contents_active', 'e'), ' ' . \_YES, ' ' . \_NO);
|
||
| 130 | $contents_active->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_ACTIVE_DESC); |
||
| 131 | $form->addElement($contents_active, false); |
||
| 132 | |||
| 133 | // Title |
||
| 134 | $contents_title = new \XoopsFormText(\_AM_XOOPSFAQ_E_CONTENTS_TITLE, 'contents_title', 50, 150, $this->getVar('contents_title', 'e'));
|
||
| 135 | $contents_title->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_TITLE_DESC); |
||
| 136 | $form->addElement($contents_title, true); |
||
| 137 | |||
| 138 | // Category |
||
| 139 | $catCriteria = new \CriteriaCompo(); |
||
| 140 | $catCriteria->order = 'ASC'; |
||
| 141 | $catCriteria->setSort('category_order');
|
||
| 142 | $objects = $categoryHandler->getList($catCriteria); |
||
| 143 | $contents_cid = new \XoopsFormSelect(\_AM_XOOPSFAQ_E_CONTENTS_CATEGORY, 'contents_cid', $this->getVar('contents_cid', 'e'), 1, false);
|
||
| 144 | $contents_cid->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_CATEGORY_DESC); |
||
| 145 | $contents_cid->addOptionArray($objects); |
||
| 146 | $form->addElement($contents_cid); |
||
| 147 | |||
| 148 | // Weight |
||
| 149 | $contents_weight = new \XoopsFormText(\_AM_XOOPSFAQ_E_CONTENTS_WEIGHT, 'contents_weight', 5, 5, $this->getVar('contents_weight', 'e'));
|
||
| 150 | $contents_weight->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_WEIGHT_DESC); |
||
| 151 | $form->addElement($contents_weight, false); |
||
| 152 | |||
| 153 | // Editor |
||
| 154 | $editorConfigs = []; |
||
| 155 | $options_tray = new \XoopsFormElementTray(\_AM_XOOPSFAQ_E_CONTENTS_CONTENT, '<br>'); |
||
| 156 | if (\class_exists('XoopsFormEditor')) {
|
||
| 157 | // $editorConfigs = array('editor' => $GLOBALS['xoopsConfig']['general_editor'],
|
||
| 158 | $editorConfigs = [ |
||
| 159 | 'editor' => $helper->getConfig('use_wysiwyg', 'dhtmltextarea'),
|
||
| 160 | 'rows' => 25, |
||
| 161 | 'cols' => '100%', |
||
| 162 | 'width' => '100%', |
||
| 163 | 'height' => '600px', |
||
| 164 | 'name' => 'contents_contents', |
||
| 165 | 'value' => $this->getVar('contents_contents', 'e'),
|
||
| 166 | ]; |
||
| 167 | $contents_contents = new \XoopsFormEditor('', 'contents_contents', $editorConfigs);
|
||
| 168 | } else {
|
||
| 169 | $contents_contents = new \XoopsFormDhtmlTextArea('', 'contents_contents', $this->getVar('contents_contents', 'e'), '100%', '100%');
|
||
| 170 | } |
||
| 171 | $options_tray->addElement($contents_contents); |
||
| 172 | $options_tray->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_CONTENT_DESC); |
||
| 173 | |||
| 174 | \xoops_load('XoopsEditorHandler');
|
||
| 175 | $editorHandler = \XoopsEditorHandler::getInstance(); |
||
| 176 | $editorList = $editorHandler->getList(true); |
||
| 177 | if (isset($editorConfigs['editor']) && \in_array($editorConfigs['editor'], \array_flip($editorList), true)) {
|
||
| 178 | $form->addElement(new \XoopsFormHidden('dohtml', (string)Constants::NOTSET));
|
||
| 179 | $form->addElement(new \XoopsFormHidden('dobr', (string)Constants::SET));
|
||
| 180 | } else {
|
||
| 181 | $html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml', 'e'));
|
||
| 182 | $html_checkbox->addOption('1', \_AM_XOOPSFAQ_E_DOHTML);
|
||
| 183 | $options_tray->addElement($html_checkbox); |
||
| 184 | |||
| 185 | $breaks_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr', 'e'));
|
||
| 186 | $breaks_checkbox->addOption('1', \_AM_XOOPSFAQ_E_BREAKS);
|
||
| 187 | $options_tray->addElement($breaks_checkbox); |
||
| 188 | } |
||
| 189 | |||
| 190 | $doimage_checkbox = new \XoopsFormCheckBox('', 'doimage', $this->getVar('doimage', 'e'));
|
||
| 191 | $doimage_checkbox->addOption('1', \_AM_XOOPSFAQ_E_DOIMAGE);
|
||
| 192 | $options_tray->addElement($doimage_checkbox); |
||
| 193 | |||
| 194 | $xcodes_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode', 'e'));
|
||
| 195 | $xcodes_checkbox->addOption('1', \_AM_XOOPSFAQ_E_DOXCODE);
|
||
| 196 | $options_tray->addElement($xcodes_checkbox); |
||
| 197 | |||
| 198 | $smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley', 'e'));
|
||
| 199 | $smiley_checkbox->addOption('1', \_AM_XOOPSFAQ_E_DOSMILEY);
|
||
| 200 | $options_tray->addElement($smiley_checkbox); |
||
| 201 | |||
| 202 | $form->addElement($options_tray); |
||
| 203 | |||
| 204 | $contents_publish = new \XoopsFormTextDateSelect(\_AM_XOOPSFAQ_E_CONTENTS_PUBLISH, 'contents_publish', 20, (int)$this->getVar('contents_publish'), $this->isNew());
|
||
| 205 | $contents_publish->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_PUBLISH_DESC); |
||
| 206 | $form->addElement($contents_publish); |
||
| 207 | |||
| 208 | $form->addElement(new \XoopsFormButtonTray('contents_form', \_SUBMIT, 'submit'));
|
||
| 209 | |||
| 210 | return $form->render(); |
||
| 211 | } |
||
| 245 |