| Conditions | 21 |
| Paths | > 20000 |
| Total Lines | 129 |
| Code Lines | 99 |
| 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 |
||
| 81 | public function getFormArticles($action = false) |
||
| 82 | { |
||
| 83 | $helper = \XoopsModules\Mymodule3\Helper::getInstance(); |
||
| 84 | if (false === $action) { |
||
| 85 | $action = $_SERVER['REQUEST_URI']; |
||
| 86 | } |
||
| 87 | // Permissions for uploader |
||
| 88 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 89 | $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 90 | if ($GLOBALS['xoopsUser']) { |
||
| 91 | if (!$GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) { |
||
| 92 | $permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false; |
||
| 93 | } else { |
||
| 94 | $permissionUpload = true; |
||
| 95 | } |
||
| 96 | } else { |
||
| 97 | $permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false; |
||
| 98 | } |
||
| 99 | // Title |
||
| 100 | $title = $this->isNew() ? sprintf(_AM_MYMODULE3_ARTICLE_ADD) : sprintf(_AM_MYMODULE3_ARTICLE_EDIT); |
||
| 101 | // Get Theme Form |
||
| 102 | xoops_load('XoopsFormLoader'); |
||
| 103 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
| 104 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 105 | // Use tag module |
||
| 106 | $dirTag = is_dir(XOOPS_ROOT_PATH . '/modules/tag') ? true : false; |
||
| 107 | if (($helper->getConfig('usetag') == 1) && $dirTag) { |
||
| 108 | $tagId = $this->isNew() ? 0 : $this->getVar('art_id'); |
||
| 109 | include_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php'; |
||
| 110 | $form->addElement(new \XoopsFormTag( 'tag', 60, 255, $tagId, 0 ), true); |
||
| 111 | } |
||
| 112 | // Form Table categories |
||
| 113 | $categoriesHandler = $helper->getHandler('categories'); |
||
| 114 | $artCatSelect = new \XoopsFormSelect( _AM_MYMODULE3_ARTICLE_CAT, 'art_cat', $this->getVar('art_cat')); |
||
| 115 | $artCatSelect->addOptionArray($categoriesHandler->getList()); |
||
| 116 | $form->addElement($artCatSelect, true); |
||
| 117 | // Form Text artTitle |
||
| 118 | $form->addElement(new \XoopsFormText( _AM_MYMODULE3_ARTICLE_TITLE, 'art_title', 50, 255, $this->getVar('art_title') ), true); |
||
| 119 | // Form Editor DhtmlTextArea artDescr |
||
| 120 | $editorConfigs = []; |
||
| 121 | $editorConfigs['name'] = 'art_descr'; |
||
| 122 | $editorConfigs['value'] = $this->getVar('art_descr', 'e'); |
||
| 123 | $editorConfigs['rows'] = 5; |
||
| 124 | $editorConfigs['cols'] = 40; |
||
| 125 | $editorConfigs['width'] = '100%'; |
||
| 126 | $editorConfigs['height'] = '400px'; |
||
| 127 | $editorConfigs['editor'] = $helper->getConfig('editor_descr'); |
||
| 128 | $form->addElement(new \XoopsFormEditor( _AM_MYMODULE3_ARTICLE_DESCR, 'art_descr', $editorConfigs), true); |
||
| 129 | // Form Image artImg |
||
| 130 | // Form Image artImg: Select Uploaded Image |
||
| 131 | $getArtImg = $this->getVar('art_img'); |
||
| 132 | $artImg = $getArtImg ? $getArtImg : 'blank.gif'; |
||
| 133 | $imageDirectory = '/uploads/mymodule3/images/articles'; |
||
| 134 | $imageTray = new \XoopsFormElementTray(_AM_MYMODULE3_ARTICLE_IMG, '<br>' ); |
||
| 135 | $imageSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE3_ARTICLE_IMG_UPLOADS, ".{$imageDirectory}/"), 'art_img', $artImg, 5); |
||
| 136 | $imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $imageDirectory ); |
||
| 137 | foreach($imageArray as $image1) { |
||
| 138 | $imageSelect->addOption("{$image1}", $image1); |
||
| 139 | } |
||
| 140 | $imageSelect->setExtra("onchange='showImgSelected(\"imglabel_art_img\", \"art_img\", \"" . $imageDirectory . "\", \"\", \"" . XOOPS_URL . "\")'"); |
||
| 141 | $imageTray->addElement($imageSelect, false); |
||
| 142 | $imageTray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . "/" . $imageDirectory . "/" . $artImg . "' id='imglabel_art_img' alt='' style='max-width:100px' />")); |
||
| 143 | // Form Image artImg: Upload new image |
||
| 144 | if ($permissionUpload) { |
||
| 145 | $maxsize = $helper->getConfig('maxsize_image'); |
||
| 146 | $imageTray->addElement(new \XoopsFormFile( '<br>' . _AM_MYMODULE3_FORM_UPLOAD_NEW, 'art_img', $maxsize )); |
||
| 147 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE3_FORM_UPLOAD_SIZE_MB)); |
||
| 148 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_IMG_WIDTH, $helper->getConfig('maxwidth_image') . ' px')); |
||
| 149 | $imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_IMG_HEIGHT, $helper->getConfig('maxheight_image') . ' px')); |
||
| 150 | } else { |
||
| 151 | $imageTray->addElement(new \XoopsFormHidden( 'art_img', $artImg )); |
||
| 152 | } |
||
| 153 | $form->addElement($imageTray, ); |
||
| 154 | // Form Radio Yes/No artOnline |
||
| 155 | $artOnline = $this->isNew() ? 0 : $this->getVar('art_online'); |
||
| 156 | $form->addElement(new \XoopsFormRadioYN( _AM_MYMODULE3_ARTICLE_ONLINE, 'art_online', $artOnline), true); |
||
| 157 | // Form File Upload artFile |
||
| 158 | $artFile = $this->isNew() ? '' : $this->getVar('art_file'); |
||
| 159 | if ($permissionUpload) { |
||
| 160 | $fileUploadTray = new \XoopsFormElementTray(_AM_MYMODULE3_ARTICLE_FILE, '<br>' ); |
||
| 161 | $fileDirectory = '/uploads/mymodule3/files/articles'; |
||
| 162 | if (!$this->isNew()) { |
||
| 163 | $fileUploadTray->addElement(new \XoopsFormLabel(sprintf(_AM_MYMODULE3_ARTICLE_FILE_UPLOADS, ".{$fileDirectory}/"), $artFile)); |
||
| 164 | } |
||
| 165 | $maxsize = $helper->getConfig('maxsize_file'); |
||
| 166 | $fileUploadTray->addElement(new \XoopsFormFile( '', 'art_file', $maxsize )); |
||
| 167 | $fileUploadTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE3_FORM_UPLOAD_SIZE_MB)); |
||
| 168 | $form->addElement($fileUploadTray, ); |
||
| 169 | } else { |
||
| 170 | $form->addElement(new \XoopsFormHidden( 'art_file', $artFile )); |
||
| 171 | } |
||
| 172 | // Form Text Date Select artCreated |
||
| 173 | $artCreated = $this->isNew() ? 0 : $this->getVar('art_created'); |
||
| 174 | $form->addElement(new \XoopsFormTextDateSelect( _AM_MYMODULE3_ARTICLE_CREATED, 'art_created', '', $artCreated )); |
||
| 175 | // Form Select User artSubmitter |
||
| 176 | $form->addElement(new \XoopsFormSelectUser( _AM_MYMODULE3_ARTICLE_SUBMITTER, 'art_submitter', false, $this->getVar('art_submitter') )); |
||
| 177 | // Permissions |
||
| 178 | $memberHandler = xoops_getHandler('member'); |
||
| 179 | $groupList = $memberHandler->getGroupList(); |
||
| 180 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 181 | $fullList[] = array_keys($groupList); |
||
| 182 | if (!$this->isNew()) { |
||
| 183 | $groupsIdsApprove = $grouppermHandler->getGroupIds('mymodule3_approve_articles', $this->getVar('art_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 184 | $groupsIdsApprove[] = array_values($groupsIdsApprove); |
||
| 185 | $groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_APPROVE, 'groups_approve_articles[]', $groupsIdsApprove); |
||
| 186 | $groupsIdsSubmit = $grouppermHandler->getGroupIds('mymodule3_submit_articles', $this->getVar('art_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 187 | $groupsIdsSubmit[] = array_values($groupsIdsSubmit); |
||
| 188 | $groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_SUBMIT, 'groups_submit_articles[]', $groupsIdsSubmit); |
||
| 189 | $groupsIdsView = $grouppermHandler->getGroupIds('mymodule3_view_articles', $this->getVar('art_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
||
| 190 | $groupsIdsView[] = array_values($groupsIdsView); |
||
| 191 | $groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_VIEW, 'groups_view_articles[]', $groupsIdsView); |
||
| 192 | } else { |
||
| 193 | $groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_APPROVE, 'groups_approve_articles[]', $fullList); |
||
| 194 | $groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_SUBMIT, 'groups_submit_articles[]', $fullList); |
||
| 195 | $groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_VIEW, 'groups_view_articles[]', $fullList); |
||
| 196 | } |
||
| 197 | // To Approve |
||
| 198 | $groupsCanApproveCheckbox->addOptionArray($groupList); |
||
| 199 | $form->addElement($groupsCanApproveCheckbox); |
||
| 200 | // To Submit |
||
| 201 | $groupsCanSubmitCheckbox->addOptionArray($groupList); |
||
| 202 | $form->addElement($groupsCanSubmitCheckbox); |
||
| 203 | // To View |
||
| 204 | $groupsCanViewCheckbox->addOptionArray($groupList); |
||
| 205 | $form->addElement($groupsCanViewCheckbox); |
||
| 206 | // To Save |
||
| 207 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 208 | $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
||
| 209 | return $form; |
||
| 210 | } |
||
| 252 |
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