Conditions | 7 |
Paths | 32 |
Total Lines | 81 |
Code Lines | 63 |
Lines | 6 |
Ratio | 7.41 % |
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 |
||
23 | public function __construct(AlumniCategory $obj) |
||
24 | { |
||
25 | $xoops = Xoops::getInstance(); |
||
26 | $moduleDirName = basename(dirname(__DIR__)); |
||
27 | $admin_lang = '_AM_' . strtoupper($moduleDirName); |
||
28 | |||
29 | $title = sprintf($obj->isNew() ? AlumniLocale::ADD_CAT : AlumniLocale::EDIT_CAT); |
||
30 | parent::__construct($title, 'form', false, 'post', true); |
||
31 | |||
32 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
33 | |||
34 | $this->setExtra('enctype="multipart/form-data"'); |
||
35 | |||
36 | include_once XOOPS_ROOT_PATH . '/class/tree.php'; |
||
37 | $categoryHandler = $xoops->getModuleHandler('category', 'alumni'); |
||
38 | $arr = $categoryHandler->getAll(); |
||
39 | $mytree = new XoopsObjectTree($arr, 'cid', 'pid'); |
||
40 | |||
41 | $this->addElement(new Xoops\Form\Label(AlumniLocale::CATEGORY_PID, $mytree->makeSelBox('pid', 'title', '-', $obj->getVar('pid'), true))); |
||
42 | $this->addElement(new Xoops\Form\Text(AlumniLocale::CATEGORY_TITLE, 'title', 50, 255, $obj->getVar('title')), true); |
||
43 | |||
44 | if ($obj->isNew()) { |
||
45 | $default_img = 'default.gif'; |
||
46 | } else { |
||
47 | $default_img = str_replace('alumni/', '', $obj->getVar('img', 'e')); |
||
48 | } |
||
49 | |||
50 | $img = $obj->getVar('img') ?: 'default.gif'; |
||
51 | $imgtray_img = new Xoops\Form\ElementTray(AlumniLocale::IMGCAT, '<br>'); |
||
52 | $img_path = \XoopsBaseConfig::get('root-path') . '/modules/alumni/images/cat'; |
||
53 | |||
54 | $imgpath_img = sprintf(AlumniLocale::FORMIMAGE_PATH, $img_path); |
||
55 | $imageselect_img = new Xoops\Form\Select(sprintf(XoopsLocale::F_FILE_EXISTS_IN, $img_path . '/'), 'img', $img); |
||
56 | $image_array_img = XoopsLists::getImgListAsArray($img_path); |
||
57 | $imageselect_img->addOption("$default_img", $default_img); |
||
58 | foreach ($image_array_img as $image_img) { |
||
59 | $imageselect_img->addOption("$image_img", $image_img); |
||
60 | } |
||
61 | |||
62 | $alumni_upload_url = \XoopsBaseConfig::get('url') . '/modules/alumni/images/cat'; |
||
63 | |||
64 | $imageselect_img->setExtra("onchange='showImgSelected(\"image_img\", \"img\", \"\", \"\", \"" . $alumni_upload_url . "\")'"); |
||
65 | $imgtray_img->addElement($imageselect_img, false); |
||
66 | $imgtray_img->addElement(new Xoops\Form\Label('', "<br><img src='" . $alumni_upload_url . '/' . $img . "' name='image_img' id='image_img' alt=''>")); |
||
67 | |||
68 | $fileseltray_category_img = new Xoops\Form\ElementTray('<br>', '<br>'); |
||
69 | $fileseltray_category_img->addElement(new Xoops\Form\File(AlumniLocale::FORMUPLOAD, 'img'), false); |
||
70 | $fileseltray_category_img->addElement(new Xoops\Form\Label(''), false); |
||
71 | $imgtray_img->addElement($fileseltray_category_img); |
||
72 | $this->addElement($imgtray_img); |
||
73 | |||
74 | $this->addElement(new Xoops\Form\Text(AlumniLocale::ORDER, 'ordre', 4, 4, $obj->getVar('ordre')), false); |
||
75 | $this->addElement(new Xoops\Form\Label(AlumniLocale::IFSCHOOL, '')); |
||
76 | |||
77 | $photo_old = $obj->getVar('scphoto') ?: ''; |
||
78 | $uploadirectory_photo = XOOPS_ROOT_PATH . "/uploads/{$moduleDirName}/photos/school_photos"; |
||
79 | $imgtray_photo = new Xoops\Form\ElementTray(AlumniLocale::SCPHOTO, '<br>'); |
||
80 | $imgpath_photo = sprintf(AlumniLocale::FORMIMAGE_PATH, $uploadirectory_photo); |
||
81 | $fileseltray_photo = new Xoops\Form\ElementTray('', '<br>'); |
||
82 | $fileseltray_photo->addElement(new XoopsFormFile(AlumniLocale::FORMUPLOAD, 'scphoto', $xoops->getModuleConfig('alumni_photomax')), false); |
||
83 | View Code Duplication | if ($photo_old) { |
|
84 | $fileseltray_photo->addElement(new Xoops\Form\Label(AlumniLocale::SELECTED_PHOTO, '<a href="../photos/school_photos/' . $photo_old . '">' . $photo_old . '</a>', false)); |
||
85 | $imgtray_checkbox = new Xoops\Form\Checkbox('', 'del_photo', 0); |
||
86 | $imgtray_checkbox->addOption(1, AlumniLocale::DELPICT); |
||
87 | $fileseltray_photo->addElement($imgtray_checkbox); |
||
88 | } |
||
89 | $imgtray_photo->addElement($fileseltray_photo); |
||
90 | $this->addElement($imgtray_photo); |
||
91 | $this->addElement(new Xoops\Form\Hidden('photo_old', $photo_old)); |
||
92 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCADDRESS, 'scaddress', 50, 255, $obj->getVar('scaddress')), false); |
||
93 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCADDRESS2, 'scaddress2', 50, 255, $obj->getVar('scaddress2')), false); |
||
94 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCCITY, 'sccity', 50, 255, $obj->getVar('sccity')), false); |
||
95 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCSTATE, 'scstate', 50, 255, $obj->getVar('scstate')), false); |
||
96 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCZIP, 'sczip', 50, 255, $obj->getVar('sczip')), false); |
||
97 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCPHONE, 'scphone', 50, 255, $obj->getVar('scphone')), false); |
||
98 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCFAX, 'scfax', 50, 255, $obj->getVar('scfax')), false); |
||
99 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCMOTTO, 'scmotto', 50, 255, $obj->getVar('scmotto')), false); |
||
100 | $this->addElement(new Xoops\Form\Text(AlumniLocale::SCURL, 'scurl', 50, 255, $obj->getVar('scurl')), false); |
||
101 | $this->addElement(new Xoops\Form\Hidden('op', 'save_category')); |
||
102 | $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit')); |
||
103 | } |
||
104 | } |
||
105 |
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.