| Conditions | 5 |
| Paths | 28 |
| Total Lines | 53 |
| Code Lines | 30 |
| 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 |
||
| 44 | public static function main(string $moduleUniqueID, bool $keepSettings): PBXApiResult |
||
| 45 | { |
||
| 46 | $res = new PBXApiResult(); |
||
| 47 | $res->processor = __METHOD__; |
||
| 48 | $currentModuleDir = PbxExtensionUtils::getModuleDir($moduleUniqueID); |
||
| 49 | |||
| 50 | // Kill all module processes |
||
| 51 | if (is_dir("{$currentModuleDir}/bin")) { |
||
| 52 | $busyboxPath = Util::which('busybox'); |
||
| 53 | $killPath = Util::which('kill'); |
||
| 54 | $lsofPath = Util::which('lsof'); |
||
| 55 | $grepPath = Util::which('grep'); |
||
| 56 | $awkPath = Util::which('awk'); |
||
| 57 | $uniqPath = Util::which('uniq'); |
||
| 58 | |||
| 59 | // Execute the command to kill all processes related to the module |
||
| 60 | Processes::mwExec( |
||
| 61 | "{$busyboxPath} {$killPath} -9 $({$lsofPath} {$currentModuleDir}/bin/* | {$busyboxPath} {$grepPath} -v COMMAND | {$busyboxPath} {$awkPath} '{ print $2}' | {$busyboxPath} {$uniqPath})" |
||
| 62 | ); |
||
| 63 | } |
||
| 64 | |||
| 65 | // Uninstall module with keep settings and backup db |
||
| 66 | $moduleClass = "Modules\\{$moduleUniqueID}\\Setup\\PbxExtensionSetup"; |
||
| 67 | |||
| 68 | try { |
||
| 69 | if (class_exists($moduleClass) |
||
| 70 | && method_exists($moduleClass, 'uninstallModule')) { |
||
| 71 | // Instantiate the module setup class and call the uninstallModule method |
||
| 72 | $setup = new $moduleClass($moduleUniqueID); |
||
| 73 | } else { |
||
| 74 | |||
| 75 | // Use a fallback class to uninstall the module from the database if it doesn't exist on disk |
||
| 76 | $moduleClass = PbxExtensionSetupFailure::class; |
||
| 77 | $setup = new $moduleClass($moduleUniqueID); |
||
| 78 | } |
||
| 79 | $setup->uninstallModule($keepSettings); |
||
| 80 | } finally { |
||
| 81 | if (is_dir($currentModuleDir)) { |
||
| 82 | // If the module directory still exists, force uninstallation |
||
| 83 | $rmPath = Util::which('rm'); |
||
| 84 | |||
| 85 | // Remove the module directory recursively |
||
| 86 | Processes::mwExec("{$rmPath} -rf {$currentModuleDir}"); |
||
| 87 | |||
| 88 | // Use the fallback class to unregister the module from the database |
||
| 89 | $moduleClass = PbxExtensionSetupFailure::class; |
||
| 90 | $setup = new $moduleClass($moduleUniqueID); |
||
| 91 | $setup->unregisterModule(); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | $res->success = true; |
||
| 95 | |||
| 96 | return $res; |
||
| 97 | } |
||
| 99 | } |