Conditions | 10 |
Paths | 96 |
Total Lines | 74 |
Code Lines | 39 |
Lines | 6 |
Ratio | 8.11 % |
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 namespace Xoopsmodules\instruction; |
||
56 | public function getForm($action = false) |
||
57 | { |
||
58 | global $xoopsDB, $xoopsModule, $xoopsModuleConfig; |
||
59 | // Если нет $action |
||
60 | if (false === $action) { |
||
61 | $action = xoops_getenv('REQUEST_URI'); |
||
62 | } |
||
63 | // Подключаем формы |
||
64 | include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
||
65 | |||
66 | // Название формы |
||
67 | $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDINSTR) : sprintf(_AM_INSTRUCTION_FORMEDITINSTR); |
||
68 | |||
69 | // Форма |
||
70 | $form = new \XoopsThemeForm($title, 'forminstr', $action, 'post', true); |
||
71 | //$form->setExtra('enctype="multipart/form-data"'); |
||
72 | // Название инструкции |
||
73 | $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true); |
||
74 | // Категория |
||
75 | $categoryHandler = new CategoryHandler; |
||
76 | $criteria = new \CriteriaCompo(); |
||
77 | $criteria->setSort('weight ASC, title'); |
||
78 | $criteria->setOrder('ASC'); |
||
79 | $instructioncat_arr = $categoryHandler->getall($criteria); |
||
80 | unset($criteria); |
||
81 | // Подключаем трей |
||
82 | include_once $GLOBALS['xoops']->path('class/tree.php'); |
||
83 | $mytree = new \XoopsObjectTree($instructioncat_arr, 'cid', 'pid'); |
||
84 | |||
85 | // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true))); |
||
86 | $helper = Helper::getInstance(); |
||
87 | $module = $helper->getModule(); |
||
88 | |||
89 | View Code Duplication | if (Utility::checkVerXoops($module, '2.5.9')) { |
|
90 | $mytree_select = $mytree->makeSelectElement('cid', 'title', '--', $this->getVar('cid'), true, 0, '', _AM_INSTRUCTION_CATC); |
||
91 | $form->addElement($mytree_select); |
||
92 | } else { |
||
93 | $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true))); |
||
94 | } |
||
95 | |||
96 | // Описание |
||
97 | $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_DESCRIPTIONC, 'description', $this->getVar('description', 'e')), true); |
||
98 | // Статус |
||
99 | $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false); |
||
100 | |||
101 | // Теги |
||
102 | $dir_tag_ok = false; |
||
103 | if (is_dir('../../tag') || is_dir('../tag')) { |
||
104 | $dir_tag_ok = true; |
||
105 | } |
||
106 | // Если влючена поддержка тегов и есть модуль tag |
||
107 | if (xoops_getModuleOption('usetag', 'instruction') && $dir_tag_ok) { |
||
108 | $itemIdForTag = $this->isNew() ? 0 : $this->getVar('instrid'); |
||
109 | // Подключаем форму тегов |
||
110 | include_once $GLOBALS['xoops']->path('modules/tag/include/formtag.php'); |
||
111 | // Добавляем элемент в форму |
||
112 | $form->addElement(new \XoopsFormTag('tag', 60, 255, $itemIdForTag, 0)); |
||
113 | } |
||
114 | |||
115 | // Мета-теги ключевых слов |
||
116 | $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false); |
||
117 | // Мета-теги описания |
||
118 | $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false); |
||
119 | |||
120 | // Если мы редактируем категорию |
||
121 | if (!$this->isNew()) { |
||
122 | $form->addElement(new \XoopsFormHidden('instrid', $this->getVar('instrid'))); |
||
123 | } |
||
124 | // |
||
125 | $form->addElement(new \XoopsFormHidden('op', 'saveinstr')); |
||
126 | // Кнопка |
||
127 | $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
128 | return $form; |
||
129 | } |
||
130 | } |
||
132 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.