| Conditions | 14 |
| Paths | 2048 |
| Total Lines | 123 |
| Code Lines | 94 |
| Lines | 12 |
| Ratio | 9.76 % |
| 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 |
||
| 32 | public function __construct(AlumniListing $obj) |
||
| 33 | { |
||
| 34 | $xoops = Xoops::getInstance(); |
||
| 35 | |||
| 36 | if ('1' == $xoops->getModuleConfig('alumni_moderated')) { |
||
| 37 | $title = sprintf($obj->isNew() ? AlumniLocale::ADD_MOD : AlumniLocale::EDIT_MOD); |
||
| 38 | } else { |
||
| 39 | $title = sprintf($obj->isNew() ? AlumniLocale::ADD_LISTING : AlumniLocale::EDIT_LISTING); |
||
| 40 | } |
||
| 41 | |||
| 42 | parent::__construct($title, 'form', false, 'post', true); |
||
| 43 | |||
| 44 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 45 | |||
| 46 | $member_handler = $xoops->getHandlerMember(); |
||
| 47 | $userGroups = $member_handler->getGroupList(); |
||
| 48 | |||
| 49 | $lid = Request::getInt('lid', 0); |
||
| 50 | // if (isset($lid)) { |
||
| 51 | // $lid = $lid; |
||
| 52 | // } |
||
| 53 | |||
| 54 | $this->addElement(new Xoops\Form\Label(AlumniLocale::SUBMITTER, $xoops->user->uname())); |
||
| 55 | |||
| 56 | $categoryHandler = $xoops->getModuleHandler('category', 'alumni'); |
||
| 57 | $categories = $categoryHandler->getObjects(); |
||
| 58 | $mytree = new XoopsObjectTree($categories, 'cid', 'pid'); |
||
| 59 | if ($obj->isNew()) { |
||
| 60 | $this_cid = Request::getInt('cid', 0); |
||
| 61 | } else { |
||
| 62 | $this_cid = $obj->getVar('cid'); |
||
| 63 | } |
||
| 64 | $categories_Handler = $xoops->getModuleHandler('category', 'alumni'); |
||
| 65 | $categories = $categories_Handler->getObjects(); |
||
| 66 | $mytree = new XoopsObjectTree($categories, 'cid', 'pid'); |
||
| 67 | $category_select = $mytree->makeSelBox('cid', 'title', '--', $this_cid, true); |
||
| 68 | $this->addElement(new Xoops\Form\Label(AlumniLocale::SCHOOL, $category_select), true); |
||
| 69 | |||
| 70 | $cat_name = ''; |
||
| 71 | $categories_Handler = $xoops->getModuleHandler('category', 'alumni'); |
||
| 72 | $catObj = $categories_Handler->get($obj->getVar('cid')); |
||
| 73 | $cat_name = $catObj->getVar('title'); |
||
| 74 | $this->addElement(new Xoops\Form\Hidden('school', $cat_name)); |
||
| 75 | |||
| 76 | $this->addElement(new Xoops\Form\Text(AlumniLocale::NAME_2, 'name', 50, 255, $obj->getVar('name')), true); |
||
| 77 | $this->addElement(new Xoops\Form\Text(AlumniLocale::MNAME_2, 'mname', 50, 255, $obj->getVar('mname')), false); |
||
| 78 | $this->addElement(new Xoops\Form\Text(AlumniLocale::LNAME_2, 'lname', 50, 255, $obj->getVar('lname')), true); |
||
| 79 | $this->addElement(new Xoops\Form\Text(AlumniLocale::CLASS_OF_2, 'year', 50, 255, $obj->getVar('year')), true); |
||
| 80 | $this->addElement(new Xoops\Form\Text(AlumniLocale::STUDIES_2, 'studies', 50, 255, $obj->getVar('studies')), false); |
||
| 81 | $activities = $obj->getVar('activities', 'e') ?: ''; |
||
| 82 | $editor_configs = []; |
||
| 83 | $editor_configs['name'] = 'activities'; |
||
| 84 | $editor_configs['value'] = $activities; |
||
| 85 | $editor_configs['editor'] = $xoops->getModuleConfig('alumni_form_options'); |
||
| 86 | $editor_configs['rows'] = 6; |
||
| 87 | $editor_configs['cols'] = 8; |
||
| 88 | |||
| 89 | $this->addElement(new Xoops\Form\Editor(AlumniLocale::ACTIVITIES, 'activities', $editor_configs), false); |
||
| 90 | $extrainfo = $obj->getVar('extrainfo', 'e') ?: ''; |
||
| 91 | $editor_configs = []; |
||
| 92 | $editor_configs['name'] = 'extrainfo'; |
||
| 93 | $editor_configs['value'] = $extrainfo; |
||
| 94 | $editor_configs['editor'] = $xoops->getModuleConfig('alumni_form_options'); |
||
| 95 | $editor_configs['rows'] = 6; |
||
| 96 | $editor_configs['cols'] = 8; |
||
| 97 | |||
| 98 | $this->addElement(new Xoops\Form\Editor(AlumniLocale::EXTRAINFO, 'extrainfo', $editor_configs), false); |
||
| 99 | $photo_old = $obj->getVar('photo') ?: ''; |
||
| 100 | $uploadirectory_photo = XOOPS_ROOT_PATH . '/modules/alumni/photos/grad_photo'; |
||
| 101 | $imgtray_photo = new Xoops\Form\ElementTray(AlumniLocale::GRAD_PHOTO, '<br>'); |
||
| 102 | $imgpath_photo = sprintf(AlumniLocale::FORMIMAGE_PATH, $uploadirectory_photo); |
||
| 103 | $fileseltray_photo = new Xoops\Form\ElementTray('', '<br>'); |
||
| 104 | $fileseltray_photo->addElement(new Xoops\Form\File(AlumniLocale::FORMUPLOAD, 'photo', $xoops->getModuleConfig('alumni_photomax')), false); |
||
| 105 | |||
| 106 | View Code Duplication | if ($photo_old) { |
|
| 107 | $fileseltray_photo->addElement(new Xoops\Form\Label(AlumniLocale::PHOTO2, '<a href="photos/grad_photo/' . $photo_old . '">' . $photo_old . '</a>', false)); |
||
| 108 | $imgtray_checkbox = new Xoops\Form\Checkbox('', 'del_photo', 0); |
||
| 109 | $imgtray_checkbox->addOption(1, AlumniLocale::DELPICT); |
||
| 110 | $fileseltray_photo->addElement($imgtray_checkbox); |
||
| 111 | } |
||
| 112 | $imgtray_photo->addElement($fileseltray_photo); |
||
| 113 | $this->addElement($imgtray_photo); |
||
| 114 | $this->addElement(new Xoops\Form\Hidden('photo_old', $photo_old)); |
||
| 115 | |||
| 116 | $photo2_old = $obj->getVar('photo2') ?: ''; |
||
| 117 | $uploadirectory_photo2 = XOOPS_ROOT_PATH . '/modules/alumni/photos/now_photo'; |
||
| 118 | $imgtray_photo2 = new Xoops\Form\ElementTray(AlumniLocale::NOW_PHOTO, '<br>'); |
||
| 119 | $imgpath_photo2 = sprintf(AlumniLocale::FORMIMAGE_PATH, $uploadirectory_photo2); |
||
| 120 | $fileseltray_photo2 = new Xoops\Form\ElementTray('', '<br>'); |
||
| 121 | $fileseltray_photo2->addElement(new Xoops\Form\File(AlumniLocale::FORMUPLOAD, 'photo2', $xoops->getModuleConfig('alumni_photomax')), false); |
||
| 122 | |||
| 123 | View Code Duplication | if ($photo2_old) { |
|
| 124 | $fileseltray_photo2->addElement(new Xoops\Form\Label(AlumniLocale::PHOTO2, '<a href="photos/now_photo/' . $photo2_old . '">' . $photo2_old . '</a>', false)); |
||
| 125 | $imgtray_checkbox2 = new Xoops\Form\Checkbox('', 'del_photo2', 0); |
||
| 126 | $imgtray_checkbox2->addOption(1, AlumniLocale::DELPICT); |
||
| 127 | $fileseltray_photo2->addElement($imgtray_checkbox2); |
||
| 128 | } |
||
| 129 | $imgtray_photo2->addElement($fileseltray_photo2); |
||
| 130 | $this->addElement($imgtray_photo2); |
||
| 131 | $this->addElement(new Xoops\Form\Hidden('photo2_old', $photo2_old)); |
||
| 132 | $this->addElement(new Xoops\Form\Text(AlumniLocale::EMAIL_2, 'email', 50, 255, $obj->getVar('email')), true); |
||
| 133 | $this->addElement(new Xoops\Form\Text(AlumniLocale::OCC_2, 'occ', 50, 255, $obj->getVar('occ')), false); |
||
| 134 | $this->addElement(new Xoops\Form\Text(AlumniLocale::TOWN_2, 'town', 50, 255, $obj->getVar('town')), false); |
||
| 135 | |||
| 136 | if ($xoops->user->isAdmin()) { |
||
| 137 | $this->addElement(new Xoops\Form\RadioYesNo(AlumniLocale::APPROVE_2, 'valid', $obj->getVar('valid'), XoopsLocale::YES, XoopsLocale::NO)); |
||
| 138 | } |
||
| 139 | if ('1' == $xoops->getModuleConfig('alumni_use_captcha')) { |
||
| 140 | $this->addElement(new Xoops\Form\Captcha()); |
||
| 141 | } |
||
| 142 | |||
| 143 | $this->addElement(new Xoops\Form\Hidden('security', $xoops->security()->createToken())); |
||
| 144 | |||
| 145 | if (isset($_REQUEST['date'])) { |
||
| 146 | $this->addElement(new Xoops\Form\Hidden('date', $_REQUEST['date'])); |
||
| 147 | } else { |
||
| 148 | $this->addElement(new XoopsFormHidden('date', time())); |
||
| 149 | } |
||
| 150 | $this->addElement(new Xoops\Form\Hidden('submitter', $xoops->user->uname())); |
||
| 151 | $this->addElement(new Xoops\Form\Hidden('usid', $xoops->user->uid())); |
||
| 152 | $this->addElement(new Xoops\Form\Hidden('op', 'save_listing')); |
||
| 153 | $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit')); |
||
| 154 | } |
||
| 155 | } |
||
| 156 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.