| Conditions | 24 |
| Paths | > 20000 |
| Total Lines | 187 |
| Code Lines | 145 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 88 | public function getFormTestfields($action = false) |
||
| 89 | { |
||
| 90 | $helper = \XoopsModules\Mymodule2\Helper::getInstance(); |
||
| 91 | if (false === $action) { |
||
| 92 | $action = $_SERVER['REQUEST_URI']; |
||
| 93 | } |
||
| 94 | // Permissions for uploader |
||
| 95 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 96 | $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 97 | if ($GLOBALS['xoopsUser']) { |
||
| 98 | if (!$GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) { |
||
| 99 | $permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false; |
||
| 100 | } else { |
||
| 101 | $permissionUpload = true; |
||
| 102 | } |
||
| 103 | } else { |
||
| 104 | $permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false; |
||
| 105 | } |
||
| 106 | // Title |
||
| 107 | $title = $this->isNew() ? sprintf(_AM_MYMODULE2_TESTFIELD_ADD) : sprintf(_AM_MYMODULE2_TESTFIELD_EDIT); |
||
| 108 | // Get Theme Form |
||
| 109 | xoops_load('XoopsFormLoader'); |
||
| 110 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
| 111 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 112 | // Form Text TfText |
||
| 113 | $form->addElement(new \XoopsFormText( _AM_MYMODULE2_TESTFIELD_TEXT, 'tf_text', 50, 255, $this->getVar('tf_text') )); |
||
| 114 | // Form Text Area TfTextarea |
||
| 115 | $form->addElement(new \XoopsFormTextArea( _AM_MYMODULE2_TESTFIELD_TEXTAREA, 'tf_textarea', $this->getVar('tf_textarea'), 4, 47 )); |
||
| 116 | // Form editor TfDhtml |
||
| 117 | $editorConfigs = []; |
||
| 118 | $editorConfigs['name'] = 'tf_dhtml'; |
||
| 119 | $editorConfigs['value'] = $this->getVar('tf_dhtml', 'e'); |
||
| 120 | $editorConfigs['rows'] = 5; |
||
| 121 | $editorConfigs['cols'] = 40; |
||
| 122 | $editorConfigs['width'] = '100%'; |
||
| 123 | $editorConfigs['height'] = '400px'; |
||
| 124 | $editorConfigs['editor'] = $helper->getConfig('editor_dhtml'); |
||
| 125 | $form->addElement(new \XoopsFormEditor( _AM_MYMODULE2_TESTFIELD_DHTML, 'tf_dhtml', $editorConfigs)); |
||
| 126 | // Form Check Box TfCheckbox |
||
| 127 | $tfCheckbox = $this->isNew() ? 0 : $this->getVar('tf_checkbox'); |
||
| 128 | $checkTfCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_TESTFIELD_CHECKBOX, 'tf_checkbox', $tfCheckbox); |
||
| 129 | $checkTfCheckbox->addOption(1, _AM_MYMODULE2_TESTFIELD_CHECKBOX); |
||
| 130 | $form->addElement($checkTfCheckbox); |
||
| 131 | // Form Radio Yes/No TfYesno |
||
| 132 | $tfYesno = $this->isNew() ? 0 : $this->getVar('tf_yesno'); |
||
| 133 | $form->addElement(new \XoopsFormRadioYN( _AM_MYMODULE2_TESTFIELD_YESNO, 'tf_yesno', $tfYesno)); |
||
| 134 | // Testfields handler |
||
| 135 | $testfieldsHandler = $helper->getHandler('testfields'); |
||
| 136 | // Form Select Testfields |
||
| 137 | $tfSelectboxSelect = new \XoopsFormSelect( _AM_MYMODULE2_TESTFIELD_SELECTBOX, 'tf_selectbox', $this->getVar('tf_selectbox')); |
||
| 138 | $tfSelectboxSelect->addOption('Empty'); |
||
| 139 | $tfSelectboxSelect->addOptionArray($testfieldsHandler->getList()); |
||
| 140 | $form->addElement($tfSelectboxSelect); |
||
| 141 | // Form Select User TfUser |
||
| 142 | $form->addElement(new \XoopsFormSelectUser( _AM_MYMODULE2_TESTFIELD_USER, 'tf_user', false, $this->getVar('tf_user') )); |
||
| 143 | // Form Color Picker TfColor |
||
| 144 | $form->addElement(new \XoopsFormColorPicker( _AM_MYMODULE2_TESTFIELD_COLOR, 'tf_color', $this->getVar('tf_color') ), true); |
||
| 145 | // Form Frameworks Image Files TfImagelist |
||
| 146 | $getTfImagelist = $this->getVar('tf_imagelist'); |
||
| 147 | $tfImagelist = $getTfImagelist ? $getTfImagelist : 'blank.gif'; |
||
| 148 | $imageDirectory = '/Frameworks/moduleclasses/icons/32'; |
||
| 149 | $imageTray = new \XoopsFormElementTray(_AM_MYMODULE2_TESTFIELD_IMAGELIST, '<br>' ); |
||
| 150 | $imageSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE2_TESTFIELD_IMAGELIST_UPLOADS, ".{$imageDirectory}/"), 'tf_imagelist', $tfImagelist, 5); |
||
| 151 | $imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $imageDirectory ); |
||
| 152 | foreach($imageArray as $image1) { |
||
| 153 | $imageSelect->addOption("{$image1}", $image1); |
||
| 154 | } |
||
| 155 | $imageSelect->setExtra("onchange='showImgSelected(\"imglabel_tf_imagelist\", \"tf_imagelist\", \"".$imageDirectory."\", \"\", \"".XOOPS_URL."\")'"); |
||
| 156 | $imageTray->addElement($imageSelect, false); |
||
| 157 | $imageTray->addElement(new \XoopsFormLabel('', "<br><img src='".XOOPS_URL."/".$imageDirectory."/".$tfImagelist."' name='imglabel_tf_imagelist' id='imglabel_tf_imagelist' alt='' style='max-width:100px' />")); |
||
| 158 | // Form File |
||
| 159 | $fileSelectTray = new \XoopsFormElementTray('', '<br>' ); |
||
| 160 | $fileSelectTray->addElement(new \XoopsFormFile( _AM_MYMODULE2_FORM_UPLOAD_NEW, 'tf_imagelist', $helper->getConfig('maxsize_image') )); |
||
| 161 | $fileSelectTray->addElement(new \XoopsFormLabel('')); |
||
| 162 | $imageTray->addElement($fileSelectTray); |
||
| 163 | $form->addElement($imageTray); |
||
| 164 | // Form Url Text File TfUrlfile |
||
| 165 | $formUrlFile = new \XoopsFormElementTray(_AM_MYMODULE2_TESTFIELD_URLFILE, '<br><br>' ); |
||
| 166 | $formUrl = $this->isNew() ? '' : $this->getVar('tf_urlfile'); |
||
| 167 | $formText = new \XoopsFormText( _AM_MYMODULE2_TESTFIELD_URLFILE_UPLOADS, 'tf_urlfile', 75, 255, $formUrl ); |
||
| 168 | $formUrlFile->addElement($formText); |
||
| 169 | $formUrlFile->addElement(new \XoopsFormFile( _AM_MYMODULE2_FORM_UPLOAD, 'tf_urlfile', $helper->getConfig('maxsize_file') )); |
||
| 170 | $form->addElement($formUrlFile); |
||
| 171 | // Form Image TfUplimage |
||
| 172 | // Form Image TfUplimage: Select Uploaded Image |
||
| 173 | $getTfUplimage = $this->getVar('tf_uplimage'); |
||
| 174 | $tfUplimage = $getTfUplimage ? $getTfUplimage : 'blank.gif'; |
||
| 175 | $imageDirectory = '/uploads/mymodule2/images/testfields'; |
||
| 176 | $imageTray = new \XoopsFormElementTray(_AM_MYMODULE2_TESTFIELD_UPLIMAGE, '<br>' ); |
||
| 177 | $imageSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE2_TESTFIELD_UPLIMAGE_UPLOADS, ".{$imageDirectory}/"), 'tf_uplimage', $tfUplimage, 5); |
||
| 178 | $imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $imageDirectory ); |
||
| 179 | foreach($imageArray as $image1) { |
||
| 180 | $imageSelect->addOption("{$image1}", $image1); |
||
| 181 | } |
||
| 182 | $imageSelect->setExtra("onchange='showImgSelected(\"imglabel_tf_uplimage\", \"tf_uplimage\", \"".$imageDirectory."\", \"\", \"".XOOPS_URL."\")'"); |
||
| 183 | $imageTray->addElement($imageSelect, false); |
||
| 184 | $imageTray->addElement(new \XoopsFormLabel('', "<br><img src='".XOOPS_URL."/".$imageDirectory."/".$tfUplimage."' name='imglabel_tf_uplimage' id='imglabel_tf_uplimage' alt='' style='max-width:100px' />")); |
||
| 185 | // Form Image TfUplimage: Upload new image |
||
| 186 | if ($permissionUpload) { |
||
| 187 | $maxsize = $helper->getConfig('maxsize_image'); |
||
| 188 | $imageTray->addElement(new \XoopsFormFile( '<br>' . _AM_MYMODULE2_FORM_UPLOAD_NEW, 'tf_uplimage', $maxsize )); |
||
| 189 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE2_FORM_UPLOAD_SIZE_MB)); |
||
| 190 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_IMG_WIDTH, $helper->getConfig('maxwidth_image') . ' px')); |
||
| 191 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_IMG_HEIGHT, $helper->getConfig('maxheight_image') . ' px')); |
||
| 192 | } else { |
||
| 193 | $imageTray->addElement(new \XoopsFormHidden( 'tf_uplimage', $tfUplimage )); |
||
| 194 | } |
||
| 195 | $form->addElement($imageTray, ); |
||
| 196 | // Form File TfUplfile |
||
| 197 | $tfUplfile = $this->isNew() ? '' : $this->getVar('tf_uplfile'); |
||
| 198 | if ($permissionUpload) { |
||
| 199 | $fileUploadTray = new \XoopsFormElementTray(_AM_MYMODULE2_TESTFIELD_UPLFILE, '<br>' ); |
||
| 200 | $fileDirectory = '/uploads/mymodule2/files/testfields'; |
||
| 201 | if (!$this->isNew()) { |
||
| 202 | $fileUploadTray->addElement(new \XoopsFormLabel(sprintf(_AM_MYMODULE2_TESTFIELD_UPLFILE_UPLOADS, ".{$fileDirectory}/"), $tfUplfile)); |
||
| 203 | } |
||
| 204 | $maxsize = $helper->getConfig('maxsize_file'); |
||
| 205 | $fileUploadTray->addElement(new \XoopsFormFile( '', 'tf_uplfile', $maxsize )); |
||
| 206 | $fileUploadTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE2_FORM_UPLOAD_SIZE_MB)); |
||
| 207 | $form->addElement($fileUploadTray, ); |
||
| 208 | } else { |
||
| 209 | $form->addElement(new \XoopsFormHidden( 'tf_uplfile', $tfUplfile )); |
||
| 210 | } |
||
| 211 | // Form Text Date Select TfTextdateselect |
||
| 212 | $tfTextdateselect = $this->isNew() ? 0 : $this->getVar('tf_textdateselect'); |
||
| 213 | $form->addElement(new \XoopsFormTextDateSelect( _AM_MYMODULE2_TESTFIELD_TEXTDATESELECT, 'tf_textdateselect', '', $tfTextdateselect )); |
||
| 214 | // Form File TfSelectfile |
||
| 215 | // Form File TfSelectfile: Select Uploaded File |
||
| 216 | $getTfSelectfile = $this->getVar('tf_selectfile'); |
||
| 217 | $tfSelectfile = $getTfSelectfile ? $getTfSelectfile : 'blank.gif'; |
||
| 218 | $fileDirectory = '/uploads/mymodule2/files/testfields'; |
||
| 219 | $fileTray = new \XoopsFormElementTray(_AM_MYMODULE2_TESTFIELD_SELECTFILE, '<br>' ); |
||
| 220 | $fileSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE2_TESTFIELD_SELECTFILE_UPLOADS, ".{$fileDirectory}/"), 'tf_selectfile', $tfSelectfile, 5); |
||
| 221 | $fileArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $fileDirectory ); |
||
| 222 | foreach($fileArray as $file1) { |
||
| 223 | $fileSelect->addOption("{$file1}", $file1); |
||
| 224 | } |
||
| 225 | $fileTray->addElement($fileSelect, false); |
||
| 226 | // Form File TfSelectfile: Upload new file |
||
| 227 | if ($permissionUpload) { |
||
| 228 | $maxsize = $helper->getConfig('maxsize_file'); |
||
| 229 | $fileTray->addElement(new \XoopsFormFile( '<br>' . _AM_MYMODULE2_FORM_UPLOAD_NEW, 'tf_selectfile', $maxsize )); |
||
| 230 | $fileTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE2_FORM_UPLOAD_SIZE_MB)); |
||
| 231 | } else { |
||
| 232 | $fileTray->addElement(new \XoopsFormHidden( 'tf_selectfile', $tfSelectfile )); |
||
| 233 | } |
||
| 234 | $form->addElement($fileTray, ); |
||
| 235 | // Form Select Testfields |
||
| 236 | $tfStatusSelect = new \XoopsFormSelect( _AM_MYMODULE2_TESTFIELD_STATUS, 'tf_status', $this->getVar('tf_status')); |
||
| 237 | $tfStatusSelect->addOption(Constants::STATUS_NONE, _AM_MYMODULE2_STATUS_NONE); |
||
| 238 | $tfStatusSelect->addOption(Constants::STATUS_OFFLINE, _AM_MYMODULE2_STATUS_OFFLINE); |
||
| 239 | $tfStatusSelect->addOption(Constants::STATUS_SUBMITTED, _AM_MYMODULE2_STATUS_SUBMITTED); |
||
| 240 | $tfStatusSelect->addOption(Constants::STATUS_APPROVED, _AM_MYMODULE2_STATUS_APPROVED); |
||
| 241 | $form->addElement($tfStatusSelect); |
||
| 242 | // Permissions |
||
| 243 | $memberHandler = xoops_getHandler('member'); |
||
| 244 | $groupList = $memberHandler->getGroupList(); |
||
| 245 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 246 | $fullList[] = array_keys($groupList); |
||
| 247 | if (!$this->isNew()) { |
||
| 248 | $groupsIdsApprove = $grouppermHandler->getGroupIds('mymodule2_approve_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 249 | $groupsIdsApprove[] = array_values($groupsIdsApprove); |
||
| 250 | $groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_APPROVE, 'groups_approve_testfields[]', $groupsIdsApprove); |
||
| 251 | $groupsIdsSubmit = $grouppermHandler->getGroupIds('mymodule2_submit_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 252 | $groupsIdsSubmit[] = array_values($groupsIdsSubmit); |
||
| 253 | $groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_SUBMIT, 'groups_submit_testfields[]', $groupsIdsSubmit); |
||
| 254 | $groupsIdsView = $grouppermHandler->getGroupIds('mymodule2_view_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 255 | $groupsIdsView[] = array_values($groupsIdsView); |
||
| 256 | $groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_VIEW, 'groups_view_testfields[]', $groupsIdsView); |
||
| 257 | } else { |
||
| 258 | $groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_APPROVE, 'groups_approve_testfields[]', $fullList); |
||
| 259 | $groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_SUBMIT, 'groups_submit_testfields[]', $fullList); |
||
| 260 | $groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_VIEW, 'groups_view_testfields[]', $fullList); |
||
| 261 | } |
||
| 262 | // To Approve |
||
| 263 | $groupsCanApproveCheckbox->addOptionArray($groupList); |
||
| 264 | $form->addElement($groupsCanApproveCheckbox); |
||
| 265 | // To Submit |
||
| 266 | $groupsCanSubmitCheckbox->addOptionArray($groupList); |
||
| 267 | $form->addElement($groupsCanSubmitCheckbox); |
||
| 268 | // To View |
||
| 269 | $groupsCanViewCheckbox->addOptionArray($groupList); |
||
| 270 | $form->addElement($groupsCanViewCheckbox); |
||
| 271 | // To Save |
||
| 272 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 273 | $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
||
| 274 | return $form; |
||
| 275 | } |
||
| 323 |
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