| Conditions | 33 |
| Paths | 30 |
| Total Lines | 147 |
| Code Lines | 131 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 207 | private function systemCallBack($request) |
||
| 208 | { |
||
| 209 | $action = $request['action']; |
||
| 210 | $data = $request['data']; |
||
| 211 | |||
| 212 | $result = [ |
||
| 213 | 'result' => 'ERROR', |
||
| 214 | ]; |
||
| 215 | |||
| 216 | switch ($action) { |
||
| 217 | case 'reboot': |
||
| 218 | $result['result'] = 'Success'; |
||
| 219 | System::rebootSync(); |
||
| 220 | break; |
||
| 221 | case 'shutdown': |
||
| 222 | $result['result'] = 'Success'; |
||
| 223 | System::shutdown(); |
||
| 224 | break; |
||
| 225 | case 'mergeUploadedFile': |
||
| 226 | $result['result'] = 'Success'; |
||
| 227 | $phpPath = Util::which('php'); |
||
| 228 | $workerDownloaderPath = Util::getFilePathByClassName(WorkerMergeUploadedFile::class); |
||
| 229 | Util::mwExecBg("{$phpPath} -f {$workerDownloaderPath} '{$data['settings_file']}'"); |
||
| 230 | break; |
||
| 231 | case 'setDate': |
||
| 232 | $result = TimeManagement::setDate($data['date']); |
||
| 233 | break; |
||
| 234 | case 'getInfo': |
||
| 235 | $result = System::getInfo(); |
||
| 236 | break; |
||
| 237 | case 'sendMail': |
||
| 238 | if (isset($data['email']) && isset($data['subject']) && isset($data['body'])) { |
||
| 239 | if (isset($data['encode']) && $data['encode'] === 'base64') { |
||
| 240 | $data['subject'] = base64_decode($data['subject']); |
||
| 241 | $data['body'] = base64_decode($data['body']); |
||
| 242 | } |
||
| 243 | $result = Notifications::sendMail($data['email'], $data['subject'], $data['body']); |
||
| 244 | } else { |
||
| 245 | $result['message'] = 'Not all query parameters are populated.'; |
||
| 246 | } |
||
| 247 | break; |
||
| 248 | case 'fileReadContent': |
||
| 249 | $result = Util::fileReadContent($data['filename'], $data['needOriginal']); |
||
| 250 | break; |
||
| 251 | case 'getExternalIpInfo': |
||
| 252 | $result = System::getExternalIpInfo(); |
||
| 253 | break; |
||
| 254 | case 'reloadMsmtp': |
||
| 255 | $notifications = new Notifications(); |
||
| 256 | $result = $notifications->configure(); |
||
| 257 | $OtherConfigs = new VoiceMailConf(); |
||
| 258 | $OtherConfigs->generateConfig(); |
||
| 259 | $asteriskPath = Util::which('asterisk'); |
||
| 260 | Util::mwExec("{$asteriskPath} -rx 'voicemail reload'"); |
||
| 261 | break; |
||
| 262 | case 'unBanIp': |
||
| 263 | $result = Firewall::fail2banUnbanAll($data['ip']); |
||
| 264 | break; |
||
| 265 | case 'getBanIp': |
||
| 266 | $result['result'] = 'Success'; |
||
| 267 | $result['data'] = Firewall::getBanIp(); |
||
| 268 | break; |
||
| 269 | case 'startLog': |
||
| 270 | $result['result'] = 'Success'; |
||
| 271 | Util::startLog(); |
||
| 272 | break; |
||
| 273 | case 'stopLog': |
||
| 274 | $result['result'] = 'Success'; |
||
| 275 | $result['filename'] = Util::stopLog(); |
||
| 276 | break; |
||
| 277 | case 'downloadNewFirmware': |
||
| 278 | $result = System::downloadNewFirmware($request['data']); |
||
| 279 | break; |
||
| 280 | case 'firmwareDownloadStatus': |
||
| 281 | $result = System::firmwareDownloadStatus(); |
||
| 282 | break; |
||
| 283 | case 'upgrade': |
||
| 284 | $result = System::upgradeFromImg($data['temp_filename']); |
||
| 285 | break; |
||
| 286 | case 'removeAudioFile': |
||
| 287 | $result = Util::removeAudioFile($data['filename']); |
||
| 288 | break; |
||
| 289 | case 'convertAudioFile': |
||
| 290 | $mvPath = Util::which('mv'); |
||
| 291 | Util::mwExec("{$mvPath} {$data['temp_filename']} {$data['filename']}"); |
||
| 292 | $result = UploadAndConvertFiles::convertAudioFile($data['filename']); |
||
| 293 | break; |
||
| 294 | case 'downloadNewModule': |
||
| 295 | $module = $request['data']['uniqid']; |
||
| 296 | System::moduleStartDownload( |
||
| 297 | $module, |
||
| 298 | $request['data']['url'], |
||
| 299 | $request['data']['md5'] |
||
| 300 | ); |
||
| 301 | $result['uniqid'] = $module; |
||
| 302 | $result['result'] = 'Success'; |
||
| 303 | break; |
||
| 304 | case 'moduleDownloadStatus': |
||
| 305 | $module = $request['data']['uniqid']; |
||
| 306 | $result = System::moduleDownloadStatus($module); |
||
| 307 | $result['function'] = $action; |
||
| 308 | $result['result'] = 'Success'; |
||
| 309 | break; |
||
| 310 | case 'installNewModule': |
||
| 311 | $moduleMetadata = UploadAndConvertFiles::getMetadataFromModuleFile($request['data']['filePath']); |
||
| 312 | if ($moduleMetadata['result'] === 'Error') { |
||
| 313 | return $moduleMetadata; |
||
| 314 | } else { |
||
| 315 | $result = PbxExtensionUtils::installModule( |
||
| 316 | $request['data']['filePath'], |
||
| 317 | $moduleMetadata['data']['uniqid'] |
||
| 318 | ); |
||
| 319 | } |
||
| 320 | break; |
||
| 321 | case 'enableModule': |
||
| 322 | $moduleUniqueID = $request['data']['uniqid']; |
||
| 323 | $moduleStateProcessor = new PbxExtensionState($moduleUniqueID); |
||
| 324 | if ($moduleStateProcessor->enableModule() === false) { |
||
| 325 | $result['messages'] = $moduleStateProcessor->getMessages(); |
||
| 326 | } else { |
||
| 327 | unset($result); |
||
| 328 | $result['result'] = 'Success'; |
||
| 329 | } |
||
| 330 | break; |
||
| 331 | case 'disableModule': |
||
| 332 | $moduleUniqueID = $request['data']['uniqid']; |
||
| 333 | $moduleStateProcessor = new PbxExtensionState($moduleUniqueID); |
||
| 334 | if ($moduleStateProcessor->disableModule() === false) { |
||
| 335 | $result['messages'] = $moduleStateProcessor->getMessages(); |
||
| 336 | } else { |
||
| 337 | unset($result); |
||
| 338 | $result['result'] = 'Success'; |
||
| 339 | } |
||
| 340 | break; |
||
| 341 | case 'uninstallModule': |
||
| 342 | $result = PbxExtensionUtils::uninstallModule( |
||
| 343 | $request['data']['uniqid'], |
||
| 344 | $request['data']['keepSettings'] |
||
| 345 | ); |
||
| 346 | break; |
||
| 347 | default: |
||
| 348 | $result['message'] = 'API action not found in systemCallBack;'; |
||
| 349 | } |
||
| 350 | |||
| 351 | $result['function'] = $action; |
||
| 352 | |||
| 353 | return $result; |
||
| 354 | } |
||
| 475 |