| Conditions | 8 |
| Paths | 22 |
| Total Lines | 77 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 101 | private function oneRun( |
||
| 102 | RunModel $model, |
||
| 103 | stdClass $rpc |
||
| 104 | ): string { |
||
| 105 | $res = [ |
||
| 106 | 'jsonrpc' => '2.0', |
||
| 107 | ]; |
||
| 108 | |||
| 109 | $errorLevel = null; |
||
| 110 | |||
| 111 | try { |
||
| 112 | /** валидируем и парсим JsonRPC */ |
||
| 113 | $rpcObj = $this->getRpcService()->getRpc($rpc); |
||
| 114 | |||
| 115 | /** Проверим авторизацию */ |
||
| 116 | $this->authCheck($rpcObj->getMethod(), $model->isResultAuth(), $model->getMethodsWithoutAuth()); |
||
| 117 | |||
| 118 | /** Пытаемся выполнить запрос */ |
||
| 119 | $res['result'] = $this->getApiExeService()->exe( |
||
| 120 | $model, |
||
| 121 | $rpcObj |
||
| 122 | ); |
||
| 123 | } catch (InvalidAuthorizeException $e) { |
||
| 124 | $res['error'] = [ |
||
| 125 | 'code' => -32001, |
||
| 126 | 'message' => $e->getMessage(), |
||
| 127 | ]; |
||
| 128 | $errorLevel = LogLevel::INFO; |
||
| 129 | } catch (ParseErrorException $e) { |
||
| 130 | $res['error'] = [ |
||
| 131 | 'code' => -32700, |
||
| 132 | 'message' => 'Parse error: ' . $e->getMessage(), |
||
| 133 | ]; |
||
| 134 | $errorLevel = LogLevel::ERROR; |
||
| 135 | } catch (InvalidRequestException $e) { |
||
| 136 | $res['error'] = [ |
||
| 137 | 'code' => -32600, |
||
| 138 | 'message' => 'Invalid Request: ' . $e->getMessage(), |
||
| 139 | ]; |
||
| 140 | $errorLevel = LogLevel::ERROR; |
||
| 141 | } catch (MethodNotFoundException $e) { |
||
| 142 | $res['error'] = [ |
||
| 143 | 'code' => -32601, |
||
| 144 | 'message' => $e->getMessage(), // 'Method not found', |
||
| 145 | ]; |
||
| 146 | $errorLevel = LogLevel::ERROR; |
||
| 147 | } catch (InvalidParamsException $e) { |
||
| 148 | $res['error'] = [ |
||
| 149 | 'code' => -32602, |
||
| 150 | 'message' => $e->getMessage(), // 'Invalid params', |
||
| 151 | 'data' => $e->getData(), |
||
| 152 | ]; |
||
| 153 | $errorLevel = LogLevel::ERROR; |
||
| 154 | } catch (MethodErrorException $e) { |
||
| 155 | $res['error'] = [ |
||
| 156 | 'code' => $e->getCode(), |
||
| 157 | 'message' => $e->getMessage(), |
||
| 158 | 'data' => $e->getData(), |
||
| 159 | ]; |
||
| 160 | $errorLevel = LogLevel::NOTICE; |
||
| 161 | } catch (Throwable $t) { |
||
| 162 | $res['error'] = [ |
||
| 163 | 'code' => -32603, |
||
| 164 | 'message' => 'Internal error: ' . $t->getMessage(), |
||
| 165 | 'data' => [ |
||
| 166 | 'exception' => get_class($t), |
||
| 167 | 'code' => $t->getCode(), |
||
| 168 | 'file' => $t->getFile(), |
||
| 169 | 'line' => $t->getLine(), |
||
| 170 | ] |
||
| 171 | ]; |
||
| 172 | $errorLevel = LogLevel::EMERGENCY; |
||
| 173 | } |
||
| 174 | |||
| 175 | $this->log($errorLevel, $res); |
||
| 176 | |||
| 177 | return $this->getJsonResult($rpc, $res); |
||
| 178 | } |
||
| 268 |