| Conditions | 10 |
| Paths | 26 |
| Total Lines | 62 |
| Code Lines | 39 |
| 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 |
||
| 48 | public function start(array $argv): void |
||
| 49 | { |
||
| 50 | $settings_file = $argv[2] ?? ''; |
||
| 51 | |||
| 52 | // Check if the settings file exists |
||
| 53 | if ( ! file_exists($settings_file)) { |
||
| 54 | Util::sysLogMsg("WorkerMakeLogFilesArchive", 'File with settings not found', LOG_ERR); |
||
| 55 | |||
| 56 | return; |
||
| 57 | } |
||
| 58 | $file_data = json_decode(file_get_contents($settings_file), true); |
||
| 59 | |||
| 60 | // Check if the 'result_file' key is present in the settings file |
||
| 61 | if ( ! isset($file_data['result_file'])) { |
||
| 62 | Util::sysLogMsg("WorkerMakeLogFilesArchive", 'Wrong settings', LOG_ERR); |
||
| 63 | |||
| 64 | return; |
||
| 65 | } |
||
| 66 | $tcpdump_only = $file_data['tcpdump_only'] ?? true; |
||
| 67 | $resultFile = $file_data['result_file']; |
||
| 68 | $this->progress_file = "{$resultFile}.progress"; |
||
| 69 | file_put_contents($this->progress_file, '1'); |
||
| 70 | |||
| 71 | $rmPath = Util::which('rm'); |
||
| 72 | $findPath = Util::which('find'); |
||
| 73 | |||
| 74 | // Remove the result file if it already exists |
||
| 75 | if (file_exists($resultFile)) { |
||
| 76 | Processes::mwExec("{$rmPath} -rf {$resultFile}"); |
||
| 77 | } |
||
| 78 | $logDir = System::getLogDir(); |
||
| 79 | $systemInfoFile = "{$logDir}/system-information.log"; |
||
| 80 | if ($tcpdump_only) { |
||
| 81 | $command = "{$findPath} {$logDir}/tcpDump -type f "; |
||
| 82 | } else { |
||
| 83 | // Collect system info |
||
| 84 | file_put_contents($systemInfoFile, SysinfoManagementProcessor::prepareSysyinfoContent()); |
||
| 85 | $command = "{$findPath} {$logDir} -type f "; |
||
| 86 | } |
||
| 87 | Processes::mwExec($command, $out); |
||
| 88 | $zip = new ZipArchive(); |
||
| 89 | |||
| 90 | $storageDir = ''; |
||
| 91 | Storage::isStorageDiskMounted('',$storageDir); |
||
| 92 | if($zip->open($resultFile, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true){ |
||
| 93 | foreach ($out as $filename) { |
||
| 94 | if ( !file_exists($filename)) { |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | $zip->addFile($filename, str_replace("$storageDir/mikopbx/", '', $filename)); |
||
| 98 | } |
||
| 99 | if(version_compare(PHP_VERSION, '8.0.0') >= 0){ |
||
| 100 | $zip->registerProgressCallback(0.05, [$this, "progress"]); |
||
|
|
|||
| 101 | } |
||
| 102 | $zip->close(); |
||
| 103 | } |
||
| 104 | file_put_contents($this->progress_file, '100'); |
||
| 105 | if ($tcpdump_only === true) { |
||
| 106 | // Delete TCP dump |
||
| 107 | Processes::mwExec("{$rmPath} -rf {$logDir}/tcpDump"); |
||
| 108 | } |
||
| 109 | Processes::mwExec("{$rmPath} -rf $systemInfoFile $settings_file"); |
||
| 110 | } |
||
| 123 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.