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