| Conditions | 36 |
| Paths | > 20000 |
| Total Lines | 121 |
| 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 |
||
| 70 | function ls($curpath, array $options = []) |
||
| 71 | { |
||
| 72 | extract($options, EXTR_OVERWRITE); |
||
| 73 | |||
| 74 | $_lang = ManagerTheme::getLexicon(); |
||
| 75 | $_style = ManagerTheme::getStyle(); |
||
| 76 | $dircounter = 0; |
||
| 77 | $filecounter = 0; |
||
| 78 | $filesizes = 0; |
||
| 79 | $dirs_array = array(); |
||
| 80 | $files_array = array(); |
||
| 81 | $curpath = str_replace('//', '/', $curpath . '/'); |
||
| 82 | |||
| 83 | if (!is_dir($curpath)) { |
||
| 84 | echo 'Invalid path "', $curpath, '"<br />'; |
||
| 85 | |||
| 86 | return; |
||
| 87 | } |
||
| 88 | $dir = scandir($curpath); |
||
| 89 | |||
| 90 | // first, get info |
||
| 91 | foreach ($dir as $file) { |
||
| 92 | $newpath = $curpath . $file; |
||
| 93 | if ($file === '..' || $file === '.') { |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | if (is_dir($newpath)) { |
||
| 97 | $dirs_array[$dircounter]['dir'] = $newpath; |
||
| 98 | $dirs_array[$dircounter]['stats'] = lstat($newpath); |
||
| 99 | if ($file === '..' || $file === '.') { |
||
| 100 | continue; |
||
| 101 | } elseif (!in_array($file, $excludes) && !in_array($newpath, $protected_path)) { |
||
| 102 | $dirs_array[$dircounter]['text'] = '<i class="' . $_style['files_folder'] . ' FilesFolder"></i> <a href="index.php?a=31&mode=drill&path=' . urlencode($newpath) . '"><b>' . $file . '</b></a>'; |
||
| 103 | |||
| 104 | $dfiles = scandir($newpath); |
||
| 105 | foreach ($dfiles as $i => $infile) { |
||
| 106 | switch ($infile) { |
||
| 107 | case '..': |
||
| 108 | case '.': |
||
| 109 | unset($dfiles[$i]); |
||
| 110 | break; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | $file_exists = (0 < count($dfiles)) ? 'file_exists' : ''; |
||
| 114 | |||
| 115 | $dirs_array[$dircounter]['delete'] = is_writable($curpath) ? '<a href="javascript: deleteFolder(\'' . urlencode($file) . '\',\'' . $file_exists . '\');"><i class="' . $_style['files_delete'] . '" title="' . $_lang['file_delete_folder'] . '"></i></a>' : ''; |
||
| 116 | } else { |
||
| 117 | $dirs_array[$dircounter]['text'] = '<span><i class="' . $_style['files_deleted_folder'] . ' FilesDeletedFolder"></i> ' . $file . '</span>'; |
||
| 118 | $dirs_array[$dircounter]['delete'] = is_writable($curpath) ? '<span class="disabled"><i class="' . $_style['files_delete'] . '" title="' . $_lang['file_delete_folder'] . '"></i></span>' : ''; |
||
| 119 | } |
||
| 120 | |||
| 121 | $dirs_array[$dircounter]['rename'] = is_writable($curpath) ? '<a href="javascript:renameFolder(\'' . urlencode($file) . '\');"><i class="' . $_style['files_rename'] . '" title="' . $_lang['rename'] . '"></i></a> ' : ''; |
||
| 122 | |||
| 123 | // increment the counter |
||
| 124 | $dircounter++; |
||
| 125 | } else { |
||
| 126 | $type = getExtension($newpath); |
||
| 127 | $files_array[$filecounter]['file'] = $newpath; |
||
| 128 | $files_array[$filecounter]['stats'] = lstat($newpath); |
||
| 129 | $files_array[$filecounter]['text'] = determineIcon($newpath, get_by_key($_REQUEST, 'path', ''), get_by_key($_REQUEST, 'mode', '')) . ' ' . $file; |
||
| 130 | $files_array[$filecounter]['view'] = (in_array($type, |
||
| 131 | $viewablefiles)) ? '<a href="javascript:;" onclick="viewfile(\'' . $webstart_path . substr($newpath, |
||
| 132 | $len, |
||
| 133 | strlen($newpath)) . '\');"><i class="' . $_style['files_view'] . '" title="' . $_lang['files_viewfile'] . '"></i></a>' : (($enablefiledownload && in_array($type, |
||
| 134 | $uploadablefiles)) ? '<a href="' . $webstart_path . implode('/', array_map('rawurlencode', |
||
| 135 | explode('/', substr($newpath, $len, |
||
| 136 | strlen($newpath))))) . '" style="cursor:pointer;"><i class="' . $_style['files_download'] . '" title="' . $_lang['file_download_file'] . '"></i></a>' : '<span class="disabled"><i class="' . $_style['files_view'] . '" title="' . $_lang['files_viewfile'] . '"></i></span>'); |
||
| 137 | $files_array[$filecounter]['view'] = (in_array($type, |
||
| 138 | $inlineviewablefiles)) ? '<a href="index.php?a=31&mode=view&path=' . urlencode($newpath) . '"><i class="' . $_style['files_view'] . '" title="' . $_lang['files_viewfile'] . '"></i></a>' : $files_array[$filecounter]['view']; |
||
| 139 | $files_array[$filecounter]['unzip'] = ($enablefileunzip && $type == '.zip') ? '<a href="javascript:unzipFile(\'' . urlencode($file) . '\');"><i class="' . $_style['files_unzip'] . '" title="' . $_lang['file_download_unzip'] . '"></i></a>' : ''; |
||
| 140 | $files_array[$filecounter]['edit'] = (in_array($type, |
||
| 141 | $editablefiles) && is_writable($curpath) && is_writable($newpath)) ? '<a href="index.php?a=31&mode=edit&path=' . urlencode($newpath) . '#file_editfile"><i class="' . $_style['files_edit'] . '" title="' . $_lang['files_editfile'] . '"></i></a>' : '<span class="disabled"><i class="' . $_style['files_edit'] . '" title="' . $_lang['files_editfile'] . '"></i></span>'; |
||
| 142 | $files_array[$filecounter]['duplicate'] = (in_array($type, |
||
| 143 | $editablefiles) && is_writable($curpath) && is_writable($newpath)) ? '<a href="javascript:duplicateFile(\'' . urlencode($file) . '\');"><i class="' . $_style['files_duplicate'] . '" title="' . $_lang['duplicate'] . '"></i></a>' : '<span class="disabled"><i class="' . $_style['files_duplicate'] . '" align="absmiddle" title="' . $_lang['duplicate'] . '"></i></span>'; |
||
| 144 | $files_array[$filecounter]['rename'] = (in_array($type, |
||
| 145 | $editablefiles) && is_writable($curpath) && is_writable($newpath)) ? '<a href="javascript:renameFile(\'' . urlencode($file) . '\');"><i class="' . $_style['files_rename'] . '" align="absmiddle" title="' . $_lang['rename'] . '"></i></a>' : '<span class="disabled"><i class="' . $_style['files_rename'] . '" align="absmiddle" title="' . $_lang['rename'] . '"></i></span>'; |
||
| 146 | $files_array[$filecounter]['delete'] = is_writable($curpath) && is_writable($newpath) ? '<a href="javascript:deleteFile(\'' . urlencode($file) . '\');"><i class="' . $_style['files_delete'] . '" title="' . $_lang['file_delete_file'] . '"></i></a>' : '<span class="disabled"><i class="' . $_style['files_delete'] . '" title="' . $_lang['file_delete_file'] . '"></i></span>'; |
||
| 147 | |||
| 148 | // increment the counter |
||
| 149 | $filecounter++; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | // dump array entries for directories |
||
| 154 | $folders = count($dirs_array); |
||
| 155 | sort($dirs_array); // sorting the array alphabetically (Thanks pxl8r!) |
||
| 156 | for ($i = 0; $i < $folders; $i++) { |
||
| 157 | $filesizes += $dirs_array[$i]['stats']['7']; |
||
| 158 | echo '<tr>'; |
||
| 159 | echo '<td>' . $dirs_array[$i]['text'] . '</td>'; |
||
| 160 | echo '<td class="text-nowrap">' . evolutionCMS()->toDateFormat($dirs_array[$i]['stats']['9']) . '</td>'; |
||
| 161 | echo '<td class="text-right">' . nicesize($dirs_array[$i]['stats']['7']) . '</td>'; |
||
| 162 | echo '<td class="actions text-right">'; |
||
| 163 | echo $dirs_array[$i]['rename']; |
||
| 164 | echo $dirs_array[$i]['delete']; |
||
| 165 | echo '</td>'; |
||
| 166 | echo '</tr>'; |
||
| 167 | } |
||
| 168 | |||
| 169 | // dump array entries for files |
||
| 170 | $files = count($files_array); |
||
| 171 | sort($files_array); // sorting the array alphabetically (Thanks pxl8r!) |
||
| 172 | for ($i = 0; $i < $files; $i++) { |
||
| 173 | $filesizes += $files_array[$i]['stats']['7']; |
||
| 174 | echo '<tr ' . markRow($files_array[$i]['file'], get_by_key($_REQUEST, 'path'), get_by_key($_REQUEST, 'mode')) . '>'; |
||
| 175 | echo '<td>' . $files_array[$i]['text'] . '</td>'; |
||
| 176 | echo '<td class="text-nowrap">' . evolutionCMS()->toDateFormat($files_array[$i]['stats']['9']) . '</td>'; |
||
| 177 | echo '<td class="text-right">' . nicesize($files_array[$i]['stats']['7']) . '</td>'; |
||
| 178 | echo '<td class="actions text-right">'; |
||
| 179 | echo $files_array[$i]['unzip']; |
||
| 180 | echo $files_array[$i]['view']; |
||
| 181 | echo $files_array[$i]['edit']; |
||
| 182 | echo $files_array[$i]['duplicate']; |
||
| 183 | echo $files_array[$i]['rename']; |
||
| 184 | echo $files_array[$i]['delete']; |
||
| 185 | echo '</td>'; |
||
| 186 | echo '</tr>'; |
||
| 187 | } |
||
| 188 | |||
| 189 | return compact('filesizes', 'files', 'folders'); |
||
| 190 | } |
||
| 191 | } |
||
| 580 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.