| Conditions | 10 |
| Paths | 36 |
| Total Lines | 71 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 11 | ||
| Bugs | 1 | 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 |
||
| 72 | public function getResponse( |
||
| 73 | string $model, |
||
| 74 | string $calledMethod, |
||
| 75 | ?array $methodProperties, |
||
| 76 | ?bool $auth = true |
||
| 77 | ): array { |
||
| 78 | $url = $this->url.'/'.$model.'/'.$calledMethod; |
||
| 79 | |||
| 80 | $body= []; |
||
| 81 | $body['modelName'] = $model; |
||
| 82 | $body['calledMethod'] = $calledMethod; |
||
| 83 | $body['methodProperties'] = $methodProperties; |
||
| 84 | |||
| 85 | if ($auth) { |
||
| 86 | $body['apiKey'] = $this->api; |
||
| 87 | } |
||
| 88 | |||
| 89 | $response = Http::timeout(config('novaposhta.http_response_timeout', 3)) |
||
| 90 | ->retry( |
||
| 91 | config('novaposhta.http_retry_max_time', 2), |
||
| 92 | config('novaposhta.http_retry_delay', 200) |
||
| 93 | ) |
||
| 94 | ->withHeaders([ |
||
| 95 | 'Accept' => 'application/json', |
||
| 96 | 'Content-Type' => 'application/json', |
||
| 97 | ]) |
||
| 98 | ->post($url, $body); |
||
| 99 | |||
| 100 | if ($response->failed() || $response->json() === null) { |
||
| 101 | |||
| 102 | $this->return['info']['error'] = trans('novaposhta::novaposhta.error_data'); |
||
| 103 | |||
| 104 | if ($this->dev) { |
||
| 105 | $this->development($model, $calledMethod, $auth, $methodProperties, ''); |
||
|
|
|||
| 106 | } |
||
| 107 | |||
| 108 | return $this->return; |
||
| 109 | } |
||
| 110 | |||
| 111 | $answer = $response->json(); |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Development |
||
| 115 | */ |
||
| 116 | if ($this->dev) { |
||
| 117 | $this->development($model, $calledMethod, $auth, $methodProperties, $answer); |
||
| 118 | } |
||
| 119 | |||
| 120 | // TODO Возможно, исправлено |
||
| 121 | if ($auth === false && isset($answer[0])) { |
||
| 122 | /** |
||
| 123 | * Костыль для Новой Почты. |
||
| 124 | * Спасибо Вам большое, что нормально не выдаете ответ :). |
||
| 125 | */ |
||
| 126 | $answer = $answer[0]; |
||
| 127 | } |
||
| 128 | |||
| 129 | if (isset($answer['success'])) { |
||
| 130 | $this->return['success'] = $answer['success']; |
||
| 131 | } |
||
| 132 | |||
| 133 | if (isset($answer['data'])) { |
||
| 134 | $this->return['result'] = $answer['data']; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Формирование info |
||
| 139 | */ |
||
| 140 | $this->return['info'] = $this->addInfo($answer); |
||
| 141 | |||
| 142 | return $this->return; |
||
| 143 | } |
||
| 212 |