| Conditions | 5 |
| Paths | 6 |
| Total Lines | 58 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 46 | public static function main(string $filePath): PBXApiResult |
||
| 47 | { |
||
| 48 | $res = new PBXApiResult(); |
||
| 49 | $res->processor = __METHOD__; |
||
| 50 | $resModuleMetadata = Common::getMetadataFromModuleFile($filePath); |
||
| 51 | if (!$resModuleMetadata->success) { |
||
| 52 | return $resModuleMetadata; |
||
| 53 | } |
||
| 54 | |||
| 55 | $moduleUniqueID = $resModuleMetadata->data['uniqid']; |
||
| 56 | // Disable the module if it's enabled |
||
| 57 | $moduleWasEnabled = false; |
||
| 58 | if (PbxExtensionUtils::isEnabled($moduleUniqueID)) { |
||
| 59 | $res = DisableModule::main($moduleUniqueID); |
||
| 60 | if (!$res->success) { |
||
| 61 | return $res; |
||
| 62 | } |
||
| 63 | $moduleWasEnabled = true; |
||
| 64 | } |
||
| 65 | |||
| 66 | $currentModuleDir = PbxExtensionUtils::getModuleDir($moduleUniqueID); |
||
| 67 | $needBackup = is_dir($currentModuleDir); |
||
| 68 | |||
| 69 | if ($needBackup) { |
||
| 70 | UninstallModule::main($moduleUniqueID, true); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Start the background process to install the module |
||
| 74 | $temp_dir = dirname($filePath); |
||
| 75 | |||
| 76 | // Create a progress file to track the installation progress |
||
| 77 | file_put_contents($temp_dir . '/installation_progress', '0'); |
||
| 78 | |||
| 79 | // Create an error file to store any installation errors |
||
| 80 | file_put_contents($temp_dir . '/installation_error', ''); |
||
| 81 | |||
| 82 | $install_settings = [ |
||
| 83 | self::FILE_PATH => $filePath, |
||
| 84 | 'currentModuleDir' => $currentModuleDir, |
||
| 85 | 'uniqid' => $moduleUniqueID, |
||
| 86 | ]; |
||
| 87 | |||
| 88 | // Save the installation settings to a JSON file |
||
| 89 | $settings_file = "{$temp_dir}/install_settings.json"; |
||
| 90 | file_put_contents( |
||
| 91 | $settings_file, |
||
| 92 | json_encode($install_settings, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) |
||
| 93 | ); |
||
| 94 | $phpPath = Util::which('php'); |
||
| 95 | $workerFilesMergerPath = Util::getFilePathByClassName(WorkerModuleInstaller::class); |
||
| 96 | |||
| 97 | // Execute the background process to install the module |
||
| 98 | Processes::mwExecBg("{$phpPath} -f {$workerFilesMergerPath} start '{$settings_file}'"); |
||
| 99 | $res->data[self::FILE_PATH] = $filePath; |
||
| 100 | $res->data[self::MODULE_WAS_ENABLED] = $moduleWasEnabled; |
||
| 101 | $res->success = true; |
||
| 102 | |||
| 103 | return $res; |
||
| 104 | } |
||
| 105 | } |