| Conditions | 18 |
| Paths | 4 |
| Total Lines | 33 |
| Code Lines | 28 |
| 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 |
||
| 48 | private function attemptGuzzle($method, $endpoint, $headers, $body) |
||
| 49 | { |
||
| 50 | if ($this->use_guzzle && |
||
| 51 | class_exists('\\GuzzleHttp\\Exception\\BadResponseException') && |
||
| 52 | class_exists('\\GuzzleHttp\\Exception\\ClientException') && |
||
| 53 | class_exists('\\GuzzleHttp\\Exception\\ConnectException') && |
||
| 54 | class_exists('\\GuzzleHttp\\Exception\\RequestException') && |
||
| 55 | class_exists('\\GuzzleHttp\\Exception\\ServerException') && |
||
| 56 | class_exists('\\GuzzleHttp\\Exception\\TooManyRedirectsException') && |
||
| 57 | class_exists('\\GuzzleHttp\\Client') && |
||
| 58 | class_exists('\\GuzzleHttp\\Psr7\\Request')) { |
||
| 59 | $request = new \GuzzleHttp\Psr7\Request(strtoupper($method), $endpoint, $headers, $body); |
||
| 60 | $client = new \GuzzleHttp\Client(); |
||
| 61 | try { |
||
| 62 | $response = $client->send($request); |
||
| 63 | } catch (\Exception $e) { |
||
| 64 | if (($e instanceof \GuzzleHttp\Exception\BadResponseException |
||
| 65 | || $e instanceof \GuzzleHttp\Exception\ClientException |
||
| 66 | || $e instanceof \GuzzleHttp\Exception\ConnectException |
||
| 67 | || $e instanceof \GuzzleHttp\Exception\RequestException |
||
| 68 | || $e instanceof \GuzzleHttp\Exception\ServerException |
||
| 69 | || $e instanceof \GuzzleHttp\Exception\TooManyRedirectsException |
||
| 70 | ) && $e->hasResponse()) { |
||
| 71 | $response = $e->getResponse(); |
||
| 72 | } else { |
||
| 73 | throw $e; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | return $response; |
||
| 77 | } else { |
||
| 78 | return false; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 151 |