| Conditions | 12 |
| Paths | 2048 |
| Total Lines | 153 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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); |
||
| 104 | public function getFormImages($action = false) |
||
| 105 | { |
||
| 106 | $moduleDirName = \basename(dirname(__DIR__, 2)); |
||
| 107 | |||
| 108 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
| 109 | |||
| 110 | $helper = Tdmdownloads\Helper::getInstance(); |
||
| 111 | |||
| 112 | if (!$action) { |
||
| 113 | $action = $_SERVER['REQUEST_URI']; |
||
| 114 | } |
||
| 115 | |||
| 116 | // Title |
||
| 117 | |||
| 118 | $title = $this->isNew() ? \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ADD')) : \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_EDIT')); |
||
| 119 | |||
| 120 | // Get Theme Form |
||
| 121 | |||
| 122 | \xoops_load('XoopsFormLoader'); |
||
| 123 | |||
| 124 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
| 125 | |||
| 126 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 127 | |||
| 128 | // Form Text ImgTitle |
||
| 129 | |||
| 130 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_TITLE'), 'img_title', 50, 255, $this->getVar('img_title'))); |
||
|
|
|||
| 131 | |||
| 132 | // Form editor ImgDesc |
||
| 133 | |||
| 134 | $editorConfigs = []; |
||
| 135 | |||
| 136 | $editorConfigs['name'] = 'img_desc'; |
||
| 137 | |||
| 138 | $editorConfigs['value'] = $this->getVar('img_desc', 'e'); |
||
| 139 | |||
| 140 | $editorConfigs['rows'] = 5; |
||
| 141 | |||
| 142 | $editorConfigs['cols'] = 40; |
||
| 143 | |||
| 144 | $editorConfigs['width'] = '100%'; |
||
| 145 | |||
| 146 | $editorConfigs['height'] = '400px'; |
||
| 147 | |||
| 148 | $editorConfigs['editor'] = $helper->getConfig('editor'); |
||
| 149 | |||
| 150 | $form->addElement(new \XoopsFormEditor(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DESC'), 'img_desc', $editorConfigs)); |
||
| 151 | |||
| 152 | // Form Text ImgName |
||
| 153 | |||
| 154 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAME'), 'img_name', 50, 255, $this->getVar('img_name')), true); |
||
| 155 | |||
| 156 | // Form Text ImgNameLarge |
||
| 157 | |||
| 158 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMELARGE'), 'img_namelarge', 50, 255, $this->getVar('img_namelarge')), true); |
||
| 159 | |||
| 160 | // Form Text ImgOrigname |
||
| 161 | |||
| 162 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMEORIG'), 'img_nameorig', 50, 255, $this->getVar('img_nameorig')), true); |
||
| 163 | |||
| 164 | // Form Text ImgMimetype |
||
| 165 | |||
| 166 | $imgMimetype = $this->isNew() ? '0' : $this->getVar('img_mimetype'); |
||
| 167 | |||
| 168 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_MIMETYPE'), 'img_mimetype', 20, 150, $imgMimetype)); |
||
| 169 | |||
| 170 | // Form Text ImgSize |
||
| 171 | |||
| 172 | $imgSize = $this->isNew() ? '0' : $this->getVar('img_size'); |
||
| 173 | |||
| 174 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_SIZE'), 'img_size', 20, 150, $imgSize)); |
||
| 175 | |||
| 176 | // Form Text ImgResx |
||
| 177 | |||
| 178 | $imgResx = $this->isNew() ? '0' : $this->getVar('img_resx'); |
||
| 179 | |||
| 180 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESX'), 'img_resx', 20, 150, $imgResx)); |
||
| 181 | |||
| 182 | // Form Text ImgResy |
||
| 183 | |||
| 184 | $imgResy = $this->isNew() ? '0' : $this->getVar('img_resy'); |
||
| 185 | |||
| 186 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESY'), 'img_resy', 20, 150, $imgResy)); |
||
| 187 | |||
| 188 | // Form Text ImgDownloads |
||
| 189 | |||
| 190 | $imgDownloads = $this->isNew() ? '0' : $this->getVar('img_downloads'); |
||
| 191 | |||
| 192 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DOWNLOADS'), 'img_downloads', 20, 150, $imgDownloads)); |
||
| 193 | |||
| 194 | // Form Text ImgRatinglikes |
||
| 195 | |||
| 196 | $imgRatinglikes = $this->isNew() ? '0' : $this->getVar('img_ratinglikes'); |
||
| 197 | |||
| 198 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RATINGLIKES'), 'img_ratinglikes', 20, 150, $imgRatinglikes)); |
||
| 199 | |||
| 200 | // Form Text ImgVotes |
||
| 201 | |||
| 202 | $imgVotes = $this->isNew() ? '0' : $this->getVar('img_votes'); |
||
| 203 | |||
| 204 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_VOTES'), 'img_votes', 20, 150, $imgVotes)); |
||
| 205 | |||
| 206 | // Form Text ImgWeight |
||
| 207 | |||
| 208 | $imgWeight = $this->isNew() ? '0' : $this->getVar('img_weight'); |
||
| 209 | |||
| 210 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WEIGHT'), 'img_weight', 20, 150, $imgWeight)); |
||
| 211 | |||
| 212 | // Form Table albums |
||
| 213 | |||
| 214 | $albumsHandler = $helper->getHandler('Albums'); |
||
| 215 | |||
| 216 | $imgAlbidSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ALBID'), 'img_albid', $this->getVar('img_albid')); |
||
| 217 | |||
| 218 | $imgAlbidSelect->addOptionArray($albumsHandler->getList()); |
||
| 219 | |||
| 220 | $form->addElement($imgAlbidSelect, true); |
||
| 221 | |||
| 222 | // Images handler |
||
| 223 | |||
| 224 | $imagesHandler = $helper->getHandler('Images'); |
||
| 225 | |||
| 226 | // Form Select Images |
||
| 227 | |||
| 228 | $imgStateSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_STATE'), 'img_state', $this->getVar('img_state')); |
||
| 229 | |||
| 230 | $imgStateSelect->addOption('Empty'); |
||
| 231 | |||
| 232 | $imgStateSelect->addOptionArray($imagesHandler->getList()); |
||
| 233 | |||
| 234 | $form->addElement($imgStateSelect, true); |
||
| 235 | |||
| 236 | // Form Text Date Select ImgDate |
||
| 237 | |||
| 238 | $imgDate = $this->isNew() ? 0 : $this->getVar('img_date'); |
||
| 239 | |||
| 240 | $form->addElement(new \XoopsFormTextDateSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'DATE'), 'img_date', '', $imgDate)); |
||
| 241 | |||
| 242 | // Form Select User ImgSubmitter |
||
| 243 | |||
| 244 | $form->addElement(new \XoopsFormSelectUser(\constant('CO_' . $moduleDirNameUpper . '_' . 'SUBMITTER'), 'img_submitter', false, $this->getVar('img_submitter'))); |
||
| 245 | |||
| 246 | // Form Text ImgIp |
||
| 247 | |||
| 248 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_IP'), 'img_ip', 50, 255, $this->getVar('img_ip'))); |
||
| 249 | |||
| 250 | // To Save |
||
| 251 | |||
| 252 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 253 | |||
| 254 | $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
||
| 255 | |||
| 256 | return $form; |
||
| 257 | } |
||
| 353 |