Conditions | 13 |
Paths | 648 |
Total Lines | 132 |
Code Lines | 88 |
Lines | 12 |
Ratio | 9.09 % |
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 |
||
119 | function manageFiles() |
||
120 | { |
||
121 | global $aSortBy, $aOrderBy, $aLimitBy, $order, $limit, $start, $sort; |
||
122 | $xhelpUploadDir = XHELP_UPLOAD_PATH; |
||
123 | $dir_status =& xhelp_admin_getPathStatus($xhelpUploadDir, true); |
||
124 | |||
125 | if($dir_status == -1){ |
||
126 | $can_upload = xhelp_admin_mkdir($xhelpUploadDir); |
||
127 | } |
||
128 | |||
129 | $hFile =& xhelpGetHandler('file'); |
||
130 | |||
131 | if(isset($_POST['deleteFiles'])){ // Delete all selected files |
||
132 | $aFiles = $_POST['files']; |
||
133 | $crit = new Criteria('id', "(". implode($aFiles, ',') .")", "IN"); |
||
134 | |||
135 | if($hFile->deleteAll($crit)){ |
||
136 | header("Location: ".XHELP_ADMIN_URL."/file.php?op=manageFiles"); |
||
137 | } |
||
138 | redirect_header(XHELP_ADMIN_URL."/file.php?op=manageFiles", 3, _XHELP_MESSAGE_DELETE_FILE_ERR); |
||
139 | } |
||
140 | xoops_cp_header(); |
||
141 | //echo $oAdminButton->renderButtons('manFiles'); |
||
142 | $indexAdmin = new ModuleAdmin(); |
||
143 | echo $indexAdmin->addNavigation('file.php?op=manageFiles'); |
||
144 | |||
145 | echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>'; |
||
146 | echo "<form method='post' action='".XHELP_ADMIN_URL."/file.php?op=manageFiles'>"; |
||
147 | |||
148 | echo "<table width='100%' cellspacing='1' class='outer'> |
||
149 | <tr><th colspan='2'><label>"._AM_XHELP_TEXT_TOTAL_USED_SPACE."</label></th></tr>"; |
||
150 | |||
151 | echo "<tr><td class='head' width='20%'>"._AM_XHELP_TEXT_ALL_ATTACH."</td> |
||
152 | <td class='even'>".xhelpDirsize($xhelpUploadDir)." |
||
153 | </td> |
||
154 | </tr>"; |
||
155 | |||
156 | $resolvedSize = xhelpDirsize($xhelpUploadDir, true); |
||
157 | echo "<tr><td class='head'>"._AM_XHELP_TEXT_RESOLVED_ATTACH."</td> |
||
158 | <td class='even'>"; |
||
159 | if($resolvedSize > 0){ |
||
160 | echo $resolvedSize." <b>("._AM_XHELP_TEXT_DELETE_RESOLVED." |
||
161 | <a href='".XHELP_ADMIN_URL."/file.php?op=deleteResolved'><img src='".XHELP_IMAGE_URL."/button_delete.png' title='"._AM_XHELP_TEXT_DELETE."' name='deleteFile' /></a>)</b>"; |
||
162 | } else { |
||
163 | echo $resolvedSize; |
||
164 | } |
||
165 | echo "</td> |
||
166 | </tr>"; |
||
167 | echo "</table></form>"; |
||
168 | |||
169 | $crit = new Criteria('', ''); |
||
170 | $crit->setOrder($order); |
||
171 | $crit->setSort($sort); |
||
172 | $crit->setLimit($limit); |
||
173 | $crit->setStart($start); |
||
174 | $files =& $hFile->getObjects($crit); |
||
175 | $total = $hFile->getCount($crit); |
||
176 | |||
177 | $nav = new XoopsPageNav($total, $limit, $start, 'start', "op=manageFiles&limit=$limit"); |
||
178 | |||
179 | echo "<form action='". XHELP_ADMIN_URL."/file.php?op=manageFiles' style='margin:0; padding:0;' method='post'>"; |
||
180 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
181 | echo "<tr><td align='right'>"._AM_XHELP_TEXT_SORT_BY." |
||
182 | <select name='sort'>"; |
||
183 | View Code Duplication | foreach($aSortBy as $value=>$text){ |
|
184 | ($sort == $value) ? $selected = "selected='selected'" : $selected = ''; |
||
185 | echo "<option value='$value' $selected>$text</option>"; |
||
186 | } |
||
187 | echo "</select> |
||
188 | |
||
189 | "._AM_XHELP_TEXT_ORDER_BY." |
||
190 | <select name='order'>"; |
||
191 | View Code Duplication | foreach($aOrderBy as $value=>$text){ |
|
192 | ($order == $value) ? $selected = "selected='selected'" : $selected = ''; |
||
193 | echo "<option value='$value' $selected>$text</option>"; |
||
194 | } |
||
195 | echo "</select> |
||
196 | |
||
197 | "._AM_XHELP_TEXT_NUMBER_PER_PAGE." |
||
198 | <select name='limit'>"; |
||
199 | View Code Duplication | foreach($aLimitBy as $value=>$text){ |
|
200 | ($limit == $value) ? $selected = "selected='selected'" : $selected = ''; |
||
201 | echo "<option value='$value' $selected>$text</option>"; |
||
202 | } |
||
203 | echo "</select> |
||
204 | <input type='submit' name='file_sort' id='file_sort' value='"._AM_XHELP_BUTTON_SUBMIT."' /> |
||
205 | </td> |
||
206 | </tr>"; |
||
207 | echo "</table></form>"; |
||
208 | |||
209 | echo "<form method='post' action='".XHELP_ADMIN_URL."/file.php?op=manageFiles'>"; |
||
210 | echo "<table width='100%' cellspacing='1' class='outer'> |
||
211 | <tr><th colspan='6'><label>"._AM_XHELP_TEXT_MANAGE_FILES."</label></th></tr>"; |
||
212 | if($total != 0){ |
||
213 | echo "<tr class='head'> |
||
214 | <td>"._AM_XHELP_TEXT_ID."</td> |
||
215 | <td>"._AM_XHELP_TEXT_TICKETID."</td> |
||
216 | <td>"._AM_XHELP_TEXT_FILENAME."</td> |
||
217 | <td>"._AM_XHELP_TEXT_SIZE."</td> |
||
218 | <td>"._AM_XHELP_TEXT_MIMETYPE."</td> |
||
219 | <td>"._AM_XHELP_TEXT_ACTIONS."</td> |
||
220 | </tr>"; |
||
221 | |||
222 | foreach($files as $file){ |
||
223 | $filepath = XHELP_BASE_URL.'/viewFile.php?id='. $file->getVar('id'); |
||
224 | $ticketpath = XHELP_BASE_URL.'/ticket.php?id='.$file->getVar('ticketid'); |
||
225 | $filesize = filesize($xhelpUploadDir.'/'.$file->getVar('filename')); |
||
226 | |||
227 | echo "<tr class='even'> |
||
228 | <td><input type='checkbox' name='files[]' value='".$file->getVar('id')."' /> ".$file->getVar('id')."</td> |
||
229 | <td><a href='".$ticketpath."' target='_BLANK'>".$file->getVar('ticketid')."</a></td> |
||
230 | <td><a href='".$filepath."'>".$file->getVar('filename')."</a></td> |
||
231 | <td>".xhelpPrettyBytes($filesize)."</td> |
||
232 | <td>".$file->getVar('mimetype')."</td> |
||
233 | <td> |
||
234 | <a href='".XHELP_ADMIN_URL."/file.php?op=deleteFile&fileid=".$file->getVar('id')."'><img src='".XOOPS_URL."/modules/xhelp/images/button_delete.png' title='"._AM_XHELP_TEXT_DELETE."' name='deleteFile' /></a> |
||
235 | </td> |
||
236 | </tr>"; |
||
237 | } |
||
238 | echo "<tr class='foot'><td colspan='6'> |
||
239 | <input type='checkbox' name='checkAllFiles' value='0' onclick='selectAll(this.form,\"files[]\",this.checked);' /> |
||
240 | <input type='submit' name='deleteFiles' id='deleteFiles' value='"._AM_XHELP_BUTTON_DELETE."' /></td></tr>"; |
||
241 | echo "</table></form>"; |
||
242 | echo "<div id='status_nav'>".$nav->renderNav()."</div>"; |
||
243 | } else { |
||
244 | echo "<tr class='even'<td colspan='6'>"._AM_XHELP_TEXT_NO_FILES."</td></tr>"; |
||
245 | echo "</table></form>"; |
||
246 | } |
||
247 | |||
248 | include_once "admin_footer.php"; |
||
249 | |||
250 | } |
||
251 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.