Conditions | 10 |
Paths | 128 |
Total Lines | 59 |
Lines | 0 |
Ratio | 0 % |
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 |
||
164 | public function render($currentoption = 1, $display = true) |
||
165 | { |
||
166 | global $modversion; |
||
167 | $_dirname = $this->_obj->getVar('dirname'); |
||
168 | $i = 0; |
||
169 | |||
170 | /** |
||
171 | * Selects current menu tab |
||
172 | */ |
||
173 | foreach ($this->_menutabs as $k => $menus) { |
||
174 | $menuItems[] = $menus; |
||
175 | } |
||
176 | $breadcrumb = $menuItems[$currentoption]; |
||
177 | $menuItems[$currentoption] = 'current'; |
||
178 | //Not the best method of adding CSS but the only method available at the moment since xoops is shitty with the backend |
||
179 | $menu = '<style type="text/css" media="screen">@import "' . XOOPS_URL . '/modules/' . $this->_obj->getVar('dirname') . '/css/menu.css";</style>'; |
||
180 | $menu .= "<div id='buttontop_mod'>"; |
||
181 | $menu .= "<table style='width: 100%; padding: 0;' cellspacing='0'>\n<tr>"; |
||
182 | $menu .= "<td style='font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;'>"; |
||
183 | foreach ($this->_menutop as $k => $v) { |
||
184 | $menu .= " <a href=\"$k\">$v</a> |"; |
||
185 | } |
||
186 | $menu = substr($menu, 0, -1); |
||
187 | |||
188 | $menu .= '</td>'; |
||
189 | $menu .= "<td style='text-align: right;'><strong>" . $this->_obj->getVar('name') . '</strong> : ' . $breadcrumb . '</td>'; |
||
190 | $menu .= "</tr>\n</table>\n"; |
||
191 | $menu .= "</div>\n"; |
||
192 | $menu .= "<div id='buttonbar_mod'><ul>"; |
||
193 | foreach ($this->_menutabs as $k => $v) { |
||
194 | $menu .= "<li id='" . $menuItems[$i] . "'><a href='" . XOOPS_URL . '/modules/' . $this->_obj->getVar('dirname') . '/' . $k . "'><span>$v</span></a></li>\n"; |
||
195 | ++$i; |
||
196 | } |
||
197 | $menu .= "</ul>\n</div>\n"; |
||
198 | if ($this->_header) { |
||
199 | $menu .= "<h4 class='admin_header'>"; |
||
200 | if (isset($modversion['name'])) { |
||
201 | if ($modversion['image'] && $this->_obj->getVar('mid') == 1) { |
||
202 | $system_image = XOOPS_URL . '/modules/system/images/system/' . $modversion['image']; |
||
203 | } else { |
||
204 | $system_image = XOOPS_URL . '/modules/' . $_dirname . '/assets/images/' . $modversion['image']; |
||
205 | } |
||
206 | $menu .= "<img src='$system_image' align='middle' height='32' width='32' alt='' />"; |
||
207 | $menu .= ' ' . $modversion['name'] . "</h4>\n"; |
||
208 | } else { |
||
209 | $menu .= ' ' . $this->_header . "</h4>\n"; |
||
210 | } |
||
211 | } |
||
212 | if ($this->_subheader) { |
||
213 | $menu .= "<div class='admin_subheader'>" . $this->_subheader . "</div>\n"; |
||
214 | } |
||
215 | $menu .= '<div class="clear"> </div>'; |
||
216 | unset($this->_obj); |
||
217 | if ($display === true) { |
||
218 | echo $menu; |
||
219 | } else { |
||
220 | return $menu; |
||
221 | } |
||
222 | } |
||
223 | } |
||
224 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.