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