| Conditions | 26 |
| Paths | > 20000 |
| Total Lines | 222 |
| Code Lines | 172 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 94 | public function getFormTestfields($action = false) |
||
| 95 | { |
||
| 96 | $helper = \XoopsModules\Mymodule3\Helper::getInstance(); |
||
| 97 | if (false === $action) { |
||
| 98 | $action = $_SERVER['REQUEST_URI']; |
||
| 99 | } |
||
| 100 | // Permissions for uploader |
||
| 101 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 102 | $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 103 | if ($GLOBALS['xoopsUser']) { |
||
| 104 | if (!$GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) { |
||
| 105 | $permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false; |
||
| 106 | } else { |
||
| 107 | $permissionUpload = true; |
||
| 108 | } |
||
| 109 | } else { |
||
| 110 | $permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false; |
||
| 111 | } |
||
| 112 | // Title |
||
| 113 | $title = $this->isNew() ? sprintf(_AM_MYMODULE3_TESTFIELD_ADD) : sprintf(_AM_MYMODULE3_TESTFIELD_EDIT); |
||
| 114 | // Get Theme Form |
||
| 115 | xoops_load('XoopsFormLoader'); |
||
| 116 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
| 117 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 118 | // Form Text tfText |
||
| 119 | $form->addElement(new \XoopsFormText( _AM_MYMODULE3_TESTFIELD_TEXT, 'tf_text', 50, 255, $this->getVar('tf_text') )); |
||
| 120 | // Form Editor TextArea tfTextarea |
||
| 121 | $form->addElement(new \XoopsFormTextArea( _AM_MYMODULE3_TESTFIELD_TEXTAREA, 'tf_textarea', $this->getVar('tf_textarea'), 4, 47 )); |
||
| 122 | // Form Editor DhtmlTextArea tfDhtml |
||
| 123 | $editorConfigs = []; |
||
| 124 | $editorConfigs['name'] = 'tf_dhtml'; |
||
| 125 | $editorConfigs['value'] = $this->getVar('tf_dhtml', 'e'); |
||
| 126 | $editorConfigs['rows'] = 5; |
||
| 127 | $editorConfigs['cols'] = 40; |
||
| 128 | $editorConfigs['width'] = '100%'; |
||
| 129 | $editorConfigs['height'] = '400px'; |
||
| 130 | $editorConfigs['editor'] = $helper->getConfig('editor_dhtml'); |
||
| 131 | $form->addElement(new \XoopsFormEditor( _AM_MYMODULE3_TESTFIELD_DHTML, 'tf_dhtml', $editorConfigs)); |
||
| 132 | // Form Check Box tfCheckbox |
||
| 133 | $tfCheckbox = $this->isNew() ? 0 : $this->getVar('tf_checkbox'); |
||
| 134 | $checkTfCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_TESTFIELD_CHECKBOX, 'tf_checkbox', $tfCheckbox); |
||
| 135 | $checkTfCheckbox->addOption(1, _AM_MYMODULE3_TESTFIELD_CHECKBOX); |
||
| 136 | $form->addElement($checkTfCheckbox); |
||
| 137 | // Form Radio Yes/No tfYesno |
||
| 138 | $tfYesno = $this->isNew() ? 0 : $this->getVar('tf_yesno'); |
||
| 139 | $form->addElement(new \XoopsFormRadioYN( _AM_MYMODULE3_TESTFIELD_YESNO, 'tf_yesno', $tfYesno)); |
||
| 140 | // Testfields handler |
||
| 141 | $testfieldsHandler = $helper->getHandler('testfields'); |
||
| 142 | // Form Select tfSelectbox |
||
| 143 | $tfSelectboxSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_SELECTBOX, 'tf_selectbox', $this->getVar('tf_selectbox')); |
||
| 144 | $tfSelectboxSelect->addOption('Empty'); |
||
| 145 | $tfSelectboxSelect->addOptionArray($testfieldsHandler->getList()); |
||
| 146 | $form->addElement($tfSelectboxSelect); |
||
| 147 | // Form Select User tfUser |
||
| 148 | $form->addElement(new \XoopsFormSelectUser( _AM_MYMODULE3_TESTFIELD_USER, 'tf_user', false, $this->getVar('tf_user') )); |
||
| 149 | // Form Color Picker tfColor |
||
| 150 | $form->addElement(new \XoopsFormColorPicker( _AM_MYMODULE3_TESTFIELD_COLOR, 'tf_color', $this->getVar('tf_color') )); |
||
| 151 | // Form Frameworks Images Files tfImagelist |
||
| 152 | // Form Frameworks Images tfImagelist: Select Uploaded Image |
||
| 153 | $getTfImagelist = $this->getVar('tf_imagelist'); |
||
| 154 | $tfImagelist = $getTfImagelist ? $getTfImagelist : 'blank.gif'; |
||
| 155 | $imageDirectory = '/Frameworks/moduleclasses/icons/32'; |
||
| 156 | $imageTray = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_IMAGELIST, '<br>' ); |
||
| 157 | $imageSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE3_TESTFIELD_IMAGELIST_UPLOADS, ".{$imageDirectory}/"), 'tf_imagelist', $tfImagelist, 5); |
||
| 158 | $imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $imageDirectory ); |
||
| 159 | foreach($imageArray as $image1) { |
||
| 160 | $imageSelect->addOption("{$image1}", $image1); |
||
| 161 | } |
||
| 162 | $imageSelect->setExtra("onchange='showImgSelected(\"imglabel_tf_imagelist\", \"tf_imagelist\", \"" . $imageDirectory . "\", \"\", \"" . XOOPS_URL . "\")'"); |
||
| 163 | $imageTray->addElement($imageSelect, false); |
||
| 164 | $imageTray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . "/" . $imageDirectory . "/" . $tfImagelist . "' id='imglabel_tf_imagelist' alt='' style='max-width:100px' />")); |
||
| 165 | // Form Frameworks Images tfImagelist: Upload new image |
||
| 166 | $fileSelectTray = new \XoopsFormElementTray('', '<br>' ); |
||
| 167 | $fileSelectTray->addElement(new \XoopsFormFile( _AM_MYMODULE3_FORM_UPLOAD_NEW, 'tf_imagelist', $helper->getConfig('maxsize_image') )); |
||
| 168 | $fileSelectTray->addElement(new \XoopsFormLabel('')); |
||
| 169 | $imageTray->addElement($fileSelectTray); |
||
| 170 | $form->addElement($imageTray); |
||
| 171 | // Form Url Text File tfUrlfile |
||
| 172 | $formUrlFile = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_URLFILE, '<br><br>' ); |
||
| 173 | $formUrl = $this->isNew() ? '' : $this->getVar('tf_urlfile'); |
||
| 174 | $formText = new \XoopsFormText( _AM_MYMODULE3_TESTFIELD_URLFILE_UPLOADS, 'tf_urlfile', 75, 255, $formUrl ); |
||
| 175 | $formUrlFile->addElement($formText); |
||
| 176 | $formUrlFile->addElement(new \XoopsFormFile( _AM_MYMODULE3_FORM_UPLOAD, 'tf_urlfile', $helper->getConfig('maxsize_file') )); |
||
| 177 | $form->addElement($formUrlFile); |
||
| 178 | // Form Image tfUplimage |
||
| 179 | // Form Image tfUplimage: Select Uploaded Image |
||
| 180 | $getTfUplimage = $this->getVar('tf_uplimage'); |
||
| 181 | $tfUplimage = $getTfUplimage ? $getTfUplimage : 'blank.gif'; |
||
| 182 | $imageDirectory = '/uploads/mymodule3/images/testfields'; |
||
| 183 | $imageTray = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_UPLIMAGE, '<br>' ); |
||
| 184 | $imageSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE3_TESTFIELD_UPLIMAGE_UPLOADS, ".{$imageDirectory}/"), 'tf_uplimage', $tfUplimage, 5); |
||
| 185 | $imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $imageDirectory ); |
||
| 186 | foreach($imageArray as $image1) { |
||
| 187 | $imageSelect->addOption("{$image1}", $image1); |
||
| 188 | } |
||
| 189 | $imageSelect->setExtra("onchange='showImgSelected(\"imglabel_tf_uplimage\", \"tf_uplimage\", \"" . $imageDirectory . "\", \"\", \"" . XOOPS_URL . "\")'"); |
||
| 190 | $imageTray->addElement($imageSelect, false); |
||
| 191 | $imageTray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . "/" . $imageDirectory . "/" . $tfUplimage . "' id='imglabel_tf_uplimage' alt='' style='max-width:100px' />")); |
||
| 192 | // Form Image tfUplimage: Upload new image |
||
| 193 | if ($permissionUpload) { |
||
| 194 | $maxsize = $helper->getConfig('maxsize_image'); |
||
| 195 | $imageTray->addElement(new \XoopsFormFile( '<br>' . _AM_MYMODULE3_FORM_UPLOAD_NEW, 'tf_uplimage', $maxsize )); |
||
| 196 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE3_FORM_UPLOAD_SIZE_MB)); |
||
| 197 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_IMG_WIDTH, $helper->getConfig('maxwidth_image') . ' px')); |
||
| 198 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_IMG_HEIGHT, $helper->getConfig('maxheight_image') . ' px')); |
||
| 199 | } else { |
||
| 200 | $imageTray->addElement(new \XoopsFormHidden( 'tf_uplimage', $tfUplimage )); |
||
| 201 | } |
||
| 202 | $form->addElement($imageTray, ); |
||
| 203 | // Form File Upload tfUplfile |
||
| 204 | $tfUplfile = $this->isNew() ? '' : $this->getVar('tf_uplfile'); |
||
| 205 | if ($permissionUpload) { |
||
| 206 | $fileUploadTray = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_UPLFILE, '<br>' ); |
||
| 207 | $fileDirectory = '/uploads/mymodule3/files/testfields'; |
||
| 208 | if (!$this->isNew()) { |
||
| 209 | $fileUploadTray->addElement(new \XoopsFormLabel(sprintf(_AM_MYMODULE3_TESTFIELD_UPLFILE_UPLOADS, ".{$fileDirectory}/"), $tfUplfile)); |
||
| 210 | } |
||
| 211 | $maxsize = $helper->getConfig('maxsize_file'); |
||
| 212 | $fileUploadTray->addElement(new \XoopsFormFile( '', 'tf_uplfile', $maxsize )); |
||
| 213 | $fileUploadTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE3_FORM_UPLOAD_SIZE_MB)); |
||
| 214 | $form->addElement($fileUploadTray, ); |
||
| 215 | } else { |
||
| 216 | $form->addElement(new \XoopsFormHidden( 'tf_uplfile', $tfUplfile )); |
||
| 217 | } |
||
| 218 | // Form Text Date Select tfTextdateselect |
||
| 219 | $tfTextdateselect = $this->isNew() ? 0 : $this->getVar('tf_textdateselect'); |
||
| 220 | $form->addElement(new \XoopsFormTextDateSelect( _AM_MYMODULE3_TESTFIELD_TEXTDATESELECT, 'tf_textdateselect', '', $tfTextdateselect )); |
||
| 221 | // Form File tfSelectfile |
||
| 222 | // Form File tfSelectfile: Select Uploaded File |
||
| 223 | $getTfSelectfile = $this->getVar('tf_selectfile'); |
||
| 224 | $tfSelectfile = $getTfSelectfile ? $getTfSelectfile : 'blank.gif'; |
||
| 225 | $fileDirectory = '/uploads/mymodule3/files/testfields'; |
||
| 226 | $fileTray = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_SELECTFILE, '<br>' ); |
||
| 227 | $fileSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE3_TESTFIELD_SELECTFILE_UPLOADS, ".{$fileDirectory}/"), 'tf_selectfile', $tfSelectfile, 5); |
||
| 228 | $fileArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $fileDirectory ); |
||
| 229 | foreach($fileArray as $file1) { |
||
| 230 | $fileSelect->addOption("{$file1}", $file1); |
||
| 231 | } |
||
| 232 | $fileTray->addElement($fileSelect, false); |
||
| 233 | // Form File tfSelectfile: Upload new file |
||
| 234 | if ($permissionUpload) { |
||
| 235 | $maxsize = $helper->getConfig('maxsize_file'); |
||
| 236 | $fileTray->addElement(new \XoopsFormFile( '<br>' . _AM_MYMODULE3_FORM_UPLOAD_NEW, 'tf_selectfile', $maxsize )); |
||
| 237 | $fileTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE3_FORM_UPLOAD_SIZE_MB)); |
||
| 238 | } else { |
||
| 239 | $fileTray->addElement(new \XoopsFormHidden( 'tf_selectfile', $tfSelectfile )); |
||
| 240 | } |
||
| 241 | $form->addElement($fileTray, ); |
||
| 242 | // Form Text Enter Password tfPassword |
||
| 243 | $form->addElement(new \XoopsFormPassword( _AM_MYMODULE3_TESTFIELD_PASSWORD, 'tf_password', 10, 32 )); |
||
| 244 | // Form Select Country tfCountry_list |
||
| 245 | $tfCountry_listSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_COUNTRY_LIST, 'tf_country_list', $this->getVar('tf_country_list')); |
||
| 246 | $tfCountry_listSelect->addOption('', _NONE); |
||
| 247 | $countryArray = \XoopsLists::getCountryList(); |
||
| 248 | $tfCountry_listSelect->addOptionArray($countryArray); |
||
| 249 | $form->addElement($tfCountry_listSelect); |
||
| 250 | // Form Select Lang tfLanguage |
||
| 251 | $tfLanguageSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_LANGUAGE, 'tf_language', $this->getVar('tf_language')); |
||
| 252 | $tfLanguageSelect->addOption('', _NONE); |
||
| 253 | $langArray = \XoopsLists::getLangList(); |
||
| 254 | $tfLanguageSelect->addOptionArray($langArray); |
||
| 255 | $form->addElement($tfLanguageSelect); |
||
| 256 | // Form Radio tfRadio |
||
| 257 | $tfRadio = $this->isNew() ? 0 : $this->getVar('tf_radio'); |
||
| 258 | $tfRadioSelect = new \XoopsFormRadio( _AM_MYMODULE3_TESTFIELD_RADIO, 'tf_radio', $tfRadio); |
||
| 259 | $tfRadioSelect->addOption('0', _NONE); |
||
| 260 | $tfRadioSelect->addOption('1', _AM_MYMODULE3_LIST_1); |
||
| 261 | $tfRadioSelect->addOption('2', _AM_MYMODULE3_LIST_2); |
||
| 262 | $tfRadioSelect->addOption('3', _AM_MYMODULE3_LIST_3); |
||
| 263 | $form->addElement($tfRadioSelect); |
||
| 264 | // Form Select Status tfStatus |
||
| 265 | $tfStatusSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_STATUS, 'tf_status', $this->getVar('tf_status')); |
||
| 266 | $tfStatusSelect->addOption(Constants::STATUS_NONE, _AM_MYMODULE3_STATUS_NONE); |
||
| 267 | $tfStatusSelect->addOption(Constants::STATUS_OFFLINE, _AM_MYMODULE3_STATUS_OFFLINE); |
||
| 268 | $tfStatusSelect->addOption(Constants::STATUS_SUBMITTED, _AM_MYMODULE3_STATUS_SUBMITTED); |
||
| 269 | $tfStatusSelect->addOption(Constants::STATUS_APPROVED, _AM_MYMODULE3_STATUS_APPROVED); |
||
| 270 | $form->addElement($tfStatusSelect, true); |
||
| 271 | // Form Text Date Select tfDatetime |
||
| 272 | $tfDatetime = $this->isNew() ? 0 : $this->getVar('tf_datetime'); |
||
| 273 | $form->addElement(new \XoopsFormDateTime( _AM_MYMODULE3_TESTFIELD_DATETIME, 'tf_datetime', '', $tfDatetime )); |
||
| 274 | // Testfields handler |
||
| 275 | $testfieldsHandler = $helper->getHandler('testfields'); |
||
| 276 | // Form Select tfCombobox |
||
| 277 | $tfComboboxSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_COMBOBOX, 'tf_combobox', $this->getVar('tf_combobox'), 5); |
||
| 278 | $tfComboboxSelect->addOption('0', _NONE); |
||
| 279 | $tfComboboxSelect->addOption('1', _AM_MYMODULE3_LIST_1); |
||
| 280 | $tfComboboxSelect->addOption('2', _AM_MYMODULE3_LIST_2); |
||
| 281 | $tfComboboxSelect->addOption('3', _AM_MYMODULE3_LIST_3); |
||
| 282 | $form->addElement($tfComboboxSelect); |
||
| 283 | // Permissions |
||
| 284 | $memberHandler = xoops_getHandler('member'); |
||
| 285 | $groupList = $memberHandler->getGroupList(); |
||
| 286 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 287 | $fullList[] = array_keys($groupList); |
||
| 288 | if (!$this->isNew()) { |
||
| 289 | $groupsIdsApprove = $grouppermHandler->getGroupIds('mymodule3_approve_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 290 | $groupsIdsApprove[] = array_values($groupsIdsApprove); |
||
| 291 | $groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_APPROVE, 'groups_approve_testfields[]', $groupsIdsApprove); |
||
| 292 | $groupsIdsSubmit = $grouppermHandler->getGroupIds('mymodule3_submit_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 293 | $groupsIdsSubmit[] = array_values($groupsIdsSubmit); |
||
| 294 | $groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_SUBMIT, 'groups_submit_testfields[]', $groupsIdsSubmit); |
||
| 295 | $groupsIdsView = $grouppermHandler->getGroupIds('mymodule3_view_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 296 | $groupsIdsView[] = array_values($groupsIdsView); |
||
| 297 | $groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_VIEW, 'groups_view_testfields[]', $groupsIdsView); |
||
| 298 | } else { |
||
| 299 | $groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_APPROVE, 'groups_approve_testfields[]', $fullList); |
||
| 300 | $groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_SUBMIT, 'groups_submit_testfields[]', $fullList); |
||
| 301 | $groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_VIEW, 'groups_view_testfields[]', $fullList); |
||
| 302 | } |
||
| 303 | // To Approve |
||
| 304 | $groupsCanApproveCheckbox->addOptionArray($groupList); |
||
| 305 | $form->addElement($groupsCanApproveCheckbox); |
||
| 306 | // To Submit |
||
| 307 | $groupsCanSubmitCheckbox->addOptionArray($groupList); |
||
| 308 | $form->addElement($groupsCanSubmitCheckbox); |
||
| 309 | // To View |
||
| 310 | $groupsCanViewCheckbox->addOptionArray($groupList); |
||
| 311 | $form->addElement($groupsCanViewCheckbox); |
||
| 312 | // To Save |
||
| 313 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 314 | $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
||
| 315 | return $form; |
||
| 316 | } |
||
| 369 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths