| Conditions | 12 |
| Paths | 7 |
| Total Lines | 27 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 15 | public function formatResponse() |
||
| 16 | { |
||
| 17 | $response = $this->event->sender; |
||
| 18 | if ($response->data !== null) { |
||
| 19 | if (isset($response->data['code']) && isset($response->data['message'])) { |
||
| 20 | $response->data = [ |
||
| 21 | 'code' => $response->data['code'] ?: $response->statusCode, |
||
| 22 | 'data' => isset($response->data['data']) ? $response->data['data'] : null, |
||
| 23 | 'message' => $response->data['message'], |
||
| 24 | ]; |
||
| 25 | } elseif ($response->format != 'html' && !isset($response->data['message'])) { |
||
| 26 | $response->data = [ |
||
| 27 | 'code' => 0, |
||
| 28 | 'data' => $response->data, |
||
| 29 | 'message' => $this->successMessage ?: \Yii::t('app', 'Success Message'), |
||
| 30 | ]; |
||
| 31 | } elseif ((!empty($response->data['message'])) && !isset($response->data['code'])) { |
||
| 32 | $message = $response->data['message']; |
||
| 33 | unset($response->data['message']); |
||
| 34 | $response->data = [ |
||
| 35 | 'code' => 0, |
||
| 36 | 'data' => isset($response->data[0]) ? $response->data[0] : $response->data, |
||
| 37 | 'message' => $message, |
||
| 38 | ]; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | $this->formatHttpStatusCode($response); |
||
| 42 | } |
||
| 69 |