| Conditions | 10 |
| Paths | 11 |
| Total Lines | 27 |
| Code Lines | 16 |
| 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 |
||
| 49 | private function determineStatusResult(string $body): string |
||
| 50 | { |
||
| 51 | if (!$this->parseResponse) { |
||
| 52 | return 'OK'; |
||
| 53 | } |
||
| 54 | $statuses = json_decode($body, true); |
||
| 55 | if (!is_array($statuses)) { |
||
| 56 | return 'Unexpected response'; |
||
| 57 | } |
||
| 58 | foreach ($statuses as $key => $status) { |
||
| 59 | if (!isset($status['id'])) { |
||
| 60 | return 'Missing id for status #' . $key; |
||
| 61 | } |
||
| 62 | if (isset($status['no_errors']) && gettype($status['no_errors']) === 'boolean') { |
||
| 63 | if ($status['no_errors'] === false) { |
||
| 64 | return 'Status error for check ' . $status['id']; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | if (!isset($status['status'])) { |
||
| 68 | return 'Status can not be determined for ' . $status['id']; |
||
| 69 | } |
||
| 70 | if ($status['status'] !== 'OK') { |
||
| 71 | return 'Status error for check ' . $status['id']; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | return 'OK'; |
||
| 76 | } |
||
| 78 |