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