| Conditions | 35 |
| Paths | 35 |
| Total Lines | 154 |
| Code Lines | 138 |
| 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 |
||
| 196 | private function systemCallBack($request) |
||
| 197 | { |
||
| 198 | $action = $request['action']; |
||
| 199 | $data = $request['data']; |
||
| 200 | |||
| 201 | $result = [ |
||
| 202 | 'result' => 'ERROR', |
||
| 203 | ]; |
||
| 204 | |||
| 205 | switch ($action){ |
||
| 206 | case 'reboot': |
||
| 207 | $result['result'] = 'Success'; |
||
| 208 | System::rebootSync(); |
||
| 209 | break; |
||
| 210 | case 'shutdown': |
||
| 211 | $result['result'] = 'Success'; |
||
| 212 | System::shutdown(); |
||
| 213 | break; |
||
| 214 | case 'mergeUploadedFile': |
||
| 215 | $result['result'] = 'Success'; |
||
| 216 | $phpPath = Util::which('php'); |
||
| 217 | $workerDownloaderPath = Util::getFilePathByClassName(WorkerMergeUploadedFile::class); |
||
| 218 | Util::mwExecBg("{$phpPath} -f {$workerDownloaderPath} '{$data['settings_file']}'"); |
||
| 219 | break; |
||
| 220 | case 'setDate': |
||
| 221 | $result = TimeManagement::setDate($data['date']); |
||
| 222 | break; |
||
| 223 | case 'getInfo': |
||
| 224 | $result = System::getInfo(); |
||
| 225 | break; |
||
| 226 | case 'sendMail': |
||
| 227 | if (isset($data['email']) && isset($data['subject']) && isset($data['body'])) { |
||
| 228 | if (isset($data['encode']) && $data['encode'] === 'base64') { |
||
| 229 | $data['subject'] = base64_decode($data['subject']); |
||
| 230 | $data['body'] = base64_decode($data['body']); |
||
| 231 | } |
||
| 232 | $result = Notifications::sendMail($data['email'], $data['subject'], $data['body']); |
||
| 233 | } else { |
||
| 234 | $result['message'] = 'Not all query parameters are populated.'; |
||
| 235 | } |
||
| 236 | break; |
||
| 237 | case 'fileReadContent': |
||
| 238 | $result = Util::fileReadContent($data['filename'], $data['needOriginal']); |
||
| 239 | break; |
||
| 240 | case 'getExternalIpInfo': |
||
| 241 | $result = System::getExternalIpInfo(); |
||
| 242 | break; |
||
| 243 | case 'reloadMsmtp': |
||
| 244 | $notifications = new Notifications(); |
||
| 245 | $result = $notifications->configure(); |
||
| 246 | $OtherConfigs = new VoiceMailConf(); |
||
| 247 | $OtherConfigs->generateConfig(); |
||
| 248 | $asteriskPath = Util::which('asterisk'); |
||
| 249 | Util::mwExec("{$asteriskPath} -rx 'voicemail reload'"); |
||
| 250 | break; |
||
| 251 | case 'unBanIp': |
||
| 252 | $result = Firewall::fail2banUnbanAll($data['ip']); |
||
| 253 | break; |
||
| 254 | case 'getBanIp': |
||
| 255 | $result['result'] = 'Success'; |
||
| 256 | $result['data'] = Firewall::getBanIp(); |
||
| 257 | break; |
||
| 258 | case 'startLog': |
||
| 259 | $result['result'] = 'Success'; |
||
| 260 | Util::startLog(); |
||
| 261 | break; |
||
| 262 | case 'stopLog': |
||
| 263 | $result['result'] = 'Success'; |
||
| 264 | $result['filename'] = Util::stopLog(); |
||
| 265 | break; |
||
| 266 | case 'statusUpgrade': |
||
| 267 | $result = System::statusUpgrade(); |
||
| 268 | break; |
||
| 269 | case 'upgradeOnline': |
||
| 270 | $result = System::upgradeOnline($request['data']); |
||
| 271 | break; |
||
| 272 | case 'upgrade': |
||
| 273 | $result = System::upgradeFromImg(); |
||
| 274 | break; |
||
| 275 | case 'removeAudioFile': |
||
| 276 | $result = Util::removeAudioFile($data['filename']); |
||
| 277 | break; |
||
| 278 | case 'convertAudioFile': |
||
| 279 | $mvPath = Util::which('mv'); |
||
| 280 | Util::mwExec("{$mvPath} {$data['uploadedBlob']} {$data['filename']}"); |
||
| 281 | $result = Util::convertAudioFile($data['filename']); |
||
| 282 | break; |
||
| 283 | case 'uploadNewModule': |
||
| 284 | $module = $request['data']['uniqid']; |
||
| 285 | System::moduleStartDownload( |
||
| 286 | $module, |
||
| 287 | $request['data']['url'], |
||
| 288 | $request['data']['md5'] |
||
| 289 | ); |
||
| 290 | $result['uniqid'] = $module; |
||
| 291 | $result['result'] = 'Success'; |
||
| 292 | break; |
||
| 293 | case 'statusUploadingNewModule': |
||
| 294 | $module = $request['data']['uniqid']; |
||
| 295 | $result = System::moduleDownloadStatus($module); |
||
| 296 | $result['function'] = $action; |
||
| 297 | $result['result'] = 'Success'; |
||
| 298 | break; |
||
| 299 | case 'enableModule': |
||
| 300 | $module = $request['data']['uniqid']; |
||
| 301 | $moduleStateProcessor = new PbxExtensionState($module); |
||
| 302 | if ($moduleStateProcessor->enableModule() === false) { |
||
| 303 | $result['messages'] = $moduleStateProcessor->getMessages(); |
||
| 304 | } else { |
||
| 305 | unset($result); |
||
| 306 | $result['result'] = 'Success'; |
||
| 307 | } |
||
| 308 | break; |
||
| 309 | case 'disableModule': |
||
| 310 | $module = $request['data']['uniqid']; |
||
| 311 | $moduleStateProcessor = new PbxExtensionState($module); |
||
| 312 | if ($moduleStateProcessor->disableModule() === false) { |
||
| 313 | $result['messages'] = $moduleStateProcessor->getMessages(); |
||
| 314 | } else { |
||
| 315 | unset($result); |
||
| 316 | $result['result'] = 'Success'; |
||
| 317 | } |
||
| 318 | break; |
||
| 319 | case 'uninstallModule': |
||
| 320 | $module = $request['data']['uniqid']; |
||
| 321 | $moduleClass = "\\Modules\\{$module}\\Setup\\PbxExtensionSetup"; |
||
| 322 | if (class_exists($moduleClass) |
||
| 323 | && method_exists($moduleClass, 'uninstallModule')) { |
||
| 324 | $setup = new $moduleClass($module); |
||
| 325 | } else { |
||
| 326 | // Заглушка которая позволяет удалить модуль из базы данных, которого нет на диске |
||
| 327 | $moduleClass = PbxExtensionSetupFailure::class; |
||
| 328 | $setup = new $moduleClass($module); |
||
| 329 | } |
||
| 330 | $prams = json_decode($request['input'], true); |
||
| 331 | if (array_key_exists('keepSettings', $prams)) { |
||
| 332 | $keepSettings = $prams['keepSettings'] === 'true'; |
||
| 333 | } else { |
||
| 334 | $keepSettings = false; |
||
| 335 | } |
||
| 336 | if ($setup->uninstallModule($keepSettings)) { |
||
| 337 | $result['result'] = 'Success'; |
||
| 338 | } else { |
||
| 339 | $result['result'] = 'Error'; |
||
| 340 | $result['data'] = implode('<br>', $setup->getMessages()); |
||
| 341 | } |
||
| 342 | WorkerSafeScriptsCore::restartAllWorkers(); |
||
| 343 | break; |
||
| 344 | default: |
||
| 345 | $result['message'] = 'API action not found in systemCallBack;'; |
||
| 346 | } |
||
| 347 | |||
| 348 | $result['function'] = $action; |
||
| 349 | return $result; |
||
| 350 | } |
||
| 469 |