Conditions | 8 |
Paths | 128 |
Total Lines | 116 |
Code Lines | 69 |
Lines | 6 |
Ratio | 5.17 % |
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; |
||
61 | public function getForm($action = false, $instrid = 0) |
||
62 | { |
||
63 | // Если нет $action |
||
64 | if (false === $action) { |
||
65 | $action = xoops_getenv('REQUEST_URI'); |
||
66 | } |
||
67 | |||
68 | // Подключаем формы |
||
69 | include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
||
70 | // Подключаем типы страниц |
||
71 | $pagetypes = include $GLOBALS['xoops']->path('modules/instruction/include/pagetypes.inc.php'); |
||
72 | |||
73 | // Название формы |
||
74 | $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDPAGE) : sprintf(_AM_INSTRUCTION_FORMEDITPAGE); |
||
75 | |||
76 | // Форма |
||
77 | $form = new \XoopsThemeForm($title, 'instr_form_page', $action, 'post', true); |
||
78 | // Название |
||
79 | $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true); |
||
80 | |||
81 | // Родительская страница |
||
82 | // $pageHandler = xoops_getModuleHandler('page', 'instruction'); |
||
83 | $criteria = new \CriteriaCompo(); |
||
84 | // ID инструкции в которой данная страница |
||
85 | $instrid_page = $this->isNew() ? $instrid : $this->getVar('instrid'); |
||
86 | // Находим все страницы данной инструкции |
||
87 | $criteria->add(new \Criteria('instrid', $instrid_page, '=')); |
||
88 | // Если мы редактируем, то убрать текущую страницу из списка выбора родительской |
||
89 | if (!$this->isNew()) { |
||
90 | $criteria->add(new \Criteria('pageid', $this->getVar('pageid'), '<>')); |
||
91 | } |
||
92 | $criteria->setSort('weight'); |
||
93 | $criteria->setOrder('ASC'); |
||
94 | $inspage_arr = $pageHandler->getall($criteria); |
||
95 | unset($criteria); |
||
96 | // Подключаем трей |
||
97 | include_once $GLOBALS['xoops']->path('class/tree.php'); |
||
98 | $mytree = new \XoopsObjectTree($inspage_arr, 'pageid', 'pid'); |
||
99 | |||
100 | // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
||
101 | $helper = Helper::getInstance(); |
||
102 | $module = $helper->getModule(); |
||
103 | |||
104 | View Code Duplication | if (Utility::checkVerXoops($module, '2.5.9')) { |
|
105 | $mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PPAGEC); |
||
106 | $form->addElement($mytree_select); |
||
107 | } else { |
||
108 | $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
||
109 | } |
||
110 | |||
111 | // Вес |
||
112 | $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true); |
||
113 | // Основной текст |
||
114 | $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_HOMETEXTC, 'hometext', $this->getVar('hometext', 'e')), true); |
||
115 | // Сноска |
||
116 | $form_footnote = new \XoopsFormTextArea(_AM_INSTRUCTION_FOOTNOTEC, 'footnote', $this->getVar('footnote', 'e')); |
||
117 | $form_footnote->setDescription(_AM_INSTRUCTION_FOOTNOTE_DSC); |
||
118 | $form->addElement($form_footnote, false); |
||
119 | unset($form_footnote); |
||
120 | // Статус |
||
121 | $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false); |
||
122 | // Тип страницы |
||
123 | $form_type = new \XoopsFormSelect(_AM_INSTR_PAGETYPEC, 'type', $this->getVar('type')); |
||
124 | $form_type->setDescription(_AM_INSTR_PAGETYPEC_DESC); |
||
125 | $form_type->addOptionArray($pagetypes); |
||
126 | $form->addElement($form_type, false); |
||
127 | // Мета-теги ключевых слов |
||
128 | $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'keywords', 50, 255, $this->getVar('keywords')), false); |
||
129 | // Мета-теги описания |
||
130 | $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'description', 50, 255, $this->getVar('description')), false); |
||
131 | |||
132 | // Настройки |
||
133 | $option_tray = new \XoopsFormElementTray(_OPTIONS, '<br>'); |
||
134 | // HTML |
||
135 | $html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml')); |
||
136 | $html_checkbox->addOption(1, _AM_INSTR_DOHTML); |
||
137 | $option_tray->addElement($html_checkbox); |
||
138 | // Смайлы |
||
139 | $smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley')); |
||
140 | $smiley_checkbox->addOption(1, _AM_INSTR_DOSMILEY); |
||
141 | $option_tray->addElement($smiley_checkbox); |
||
142 | // ББ коды |
||
143 | $xcode_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode')); |
||
144 | $xcode_checkbox->addOption(1, _AM_INSTR_DOXCODE); |
||
145 | $option_tray->addElement($xcode_checkbox); |
||
146 | // |
||
147 | $br_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr')); |
||
148 | $br_checkbox->addOption(1, _AM_INSTR_DOAUTOWRAP); |
||
149 | $option_tray->addElement($br_checkbox); |
||
150 | // |
||
151 | $form->addElement($option_tray); |
||
152 | |||
153 | // Если мы редактируем страницу |
||
154 | if (!$this->isNew()) { |
||
155 | $form->addElement(new \XoopsFormHidden('pageid', $this->getVar('pageid'))); |
||
156 | } else { |
||
157 | $form->addElement(new \XoopsFormHidden('pageid', 0)); |
||
158 | } |
||
159 | // ID инструкции |
||
160 | if ($instrid) { |
||
161 | $form->addElement(new \XoopsFormHidden('instrid', $instrid)); |
||
162 | } else { |
||
163 | $form->addElement(new \XoopsFormHidden('instrid', 0)); |
||
164 | } |
||
165 | // |
||
166 | $form->addElement(new \XoopsFormHidden('op', 'savepage')); |
||
167 | // Кнопка |
||
168 | $button_tray = new \XoopsFormElementTray('', ''); |
||
169 | $button_tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
170 | $save_btn = new \XoopsFormButton('', 'cancel', _AM_INSTR_SAVEFORM); |
||
171 | $save_btn->setExtra('onclick="instrSavePage();"'); |
||
172 | $button_tray->addElement($save_btn); |
||
173 | $form->addElement($button_tray); |
||
174 | |||
175 | return $form; |
||
176 | } |
||
177 | |||
189 |
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.