| Conditions | 3 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 88 | public static function stopLog(): PBXApiResult |
||
| 89 | { |
||
| 90 | $res = new PBXApiResult(); |
||
| 91 | $res->processor = __METHOD__; |
||
| 92 | $dir_all_log = System::getLogDir(); |
||
| 93 | |||
| 94 | Util::killByName('timeout'); |
||
| 95 | Util::killByName('tcpdump'); |
||
| 96 | |||
| 97 | $rmPath = Util::which('rm'); |
||
| 98 | $findPath = Util::which('find'); |
||
| 99 | $za7Path = Util::which('7za'); |
||
| 100 | $cpPath = Util::which('cp'); |
||
| 101 | $chownPath = Util::which('chown'); |
||
| 102 | |||
| 103 | $dirlog = $dir_all_log . '/dir_start_all_log'; |
||
| 104 | Util::mwMkdir($dirlog); |
||
| 105 | |||
| 106 | $log_dir = System::getLogDir(); |
||
| 107 | Util::mwExec("{$cpPath} -R {$log_dir} {$dirlog}"); |
||
| 108 | |||
| 109 | $di = Di::getDefault(); |
||
| 110 | $dirsConfig = $di->getShared('config'); |
||
| 111 | |||
| 112 | // Файл будет удален в cron скриптом cleaner_download_links.sh т.к. имя содержит "/temp-" |
||
| 113 | // через 5 минут, если не будет занят процессом. |
||
| 114 | $result = $dirsConfig->path('core.tempDir') . '/temp-all-log-'.time().'.zip'; |
||
| 115 | |||
| 116 | if (file_exists($result)) { |
||
| 117 | Util::mwExec("{$rmPath} -rf {$result}"); |
||
| 118 | } |
||
| 119 | // Пакуем логи. |
||
| 120 | Util::mwExec("{$za7Path} a -tzip -mx0 -spf '{$result}' '{$dirlog}'"); |
||
| 121 | // Удаляем логи. Оставляем только архив. |
||
| 122 | Util::mwExec("{$findPath} {$dir_all_log}" . '/ -name *_start_all_log | xargs rm -rf'); |
||
| 123 | |||
| 124 | if (file_exists($dirlog)) { |
||
| 125 | Util::mwExec("{$findPath} {$dirlog}" . '/ -name license.key | xargs rm -rf'); |
||
| 126 | } |
||
| 127 | // Удаляем каталог логов. |
||
| 128 | Util::mwExecBg("{$rmPath} -rf {$dirlog}"); |
||
| 129 | |||
| 130 | |||
| 131 | $uid = Util::generateRandomString(36); |
||
| 132 | $di = Di::getDefault(); |
||
| 133 | $downloadLink = $di->getShared('config')->path('www.downloadCacheDir'); |
||
| 134 | $result_dir = "{$downloadLink}/{$uid}"; |
||
| 135 | Util::mwMkdir($result_dir); |
||
| 136 | $link_name = md5($result) . '.' . Util::getExtensionOfFile($result); |
||
| 137 | $lnPath = Util::which('ln'); |
||
| 138 | |||
| 139 | Util::mwExec("{$lnPath} -s {$result} {$result_dir}/{$link_name}"); |
||
| 140 | Util::mwExec("{$chownPath} www:www {$result_dir}/{$link_name}"); |
||
| 141 | |||
| 142 | $res->success=true; |
||
| 143 | $res->data['filename'] = "{$uid}/{$link_name}"; |
||
| 144 | return $res; |
||
| 145 | } |
||
| 215 | } |