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