| Conditions | 18 |
| Paths | 100 |
| Total Lines | 66 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 84 | public function prepareAnswer($message): void |
||
| 85 | { |
||
| 86 | try { |
||
| 87 | $request = json_decode($message->getBody(), true, 512, JSON_THROW_ON_ERROR); |
||
| 88 | $processor = $request['processor']; |
||
| 89 | |||
| 90 | switch ($processor) { |
||
| 91 | case 'advices': |
||
| 92 | $res = AdvicesProcessor::advicesCallBack($request); |
||
| 93 | break; |
||
| 94 | case 'cdr': |
||
| 95 | $res = CdrDBProcessor::cdrCallBack($request); |
||
| 96 | break; |
||
| 97 | case 'sip': |
||
| 98 | $res = SIPStackProcessor::sipCallBack($request); |
||
| 99 | break; |
||
| 100 | case 'iax': |
||
| 101 | $res = IAXStackProcessor::iaxCallBack($request); |
||
| 102 | break; |
||
| 103 | case 'system': |
||
| 104 | $res = SystemManagementProcessor::systemCallBack($request); |
||
| 105 | break; |
||
| 106 | case 'syslog': |
||
| 107 | $res = LogsManagementProcessor::syslogCallBack($request); |
||
| 108 | break; |
||
| 109 | case 'sysinfo': |
||
| 110 | $res = SysinfoManagementProcessor::sysinfoCallBack($request); |
||
| 111 | break; |
||
| 112 | case 'storage': |
||
| 113 | $res = StorageManagementProcessor::storageCallBack($request); |
||
| 114 | break; |
||
| 115 | case 'upload': |
||
| 116 | $res = FilesManagementProcessor::uploadCallBack($request); |
||
| 117 | break; |
||
| 118 | case 'modules': |
||
| 119 | $res = $this->modulesCallBack($request); |
||
| 120 | break; |
||
| 121 | default: |
||
| 122 | $res = new PBXApiResult(); |
||
| 123 | $res->processor = __METHOD__; |
||
| 124 | $res->success = false; |
||
| 125 | $res->messages[] = "Unknown processor - {$processor} in prepareAnswer"; |
||
| 126 | } |
||
| 127 | } catch (\Exception $exception) { |
||
| 128 | $res = new PBXApiResult(); |
||
| 129 | $res->processor = __METHOD__; |
||
| 130 | $res->messages[] = 'Exception on WorkerApiCommands - ' . $exception->getMessage(); |
||
| 131 | } |
||
| 132 | |||
| 133 | $message->reply(json_encode($res->getResult())); |
||
| 134 | |||
| 135 | // Check if new code added from modules |
||
| 136 | if (is_array($res->data) |
||
| 137 | && array_key_exists('needRestartWorkers', $res->data) |
||
| 138 | && $res->data['needRestartWorkers'] |
||
| 139 | ) { |
||
| 140 | System::restartAllWorkers(); |
||
| 141 | $this->needRestart=true; |
||
| 142 | } |
||
| 143 | |||
| 144 | // Check if modules change state |
||
| 145 | if (is_array($res->data) |
||
| 146 | && array_key_exists('needReloadModules', $res->data) |
||
| 147 | && $res->data['needReloadModules'] |
||
| 148 | ) { |
||
| 149 | $this->registerModulesProcessors(); |
||
| 150 | } |
||
| 202 |