| Conditions | 7 |
| Paths | 36 |
| Total Lines | 55 |
| 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 |
||
| 52 | public function exec(Request $request, array $params): Response |
||
| 53 | { |
||
| 54 | $connection = $this->getConnection(); |
||
| 55 | |||
| 56 | $client = $this->_getGuzzleClient($connection->isPersistent()); |
||
| 57 | |||
| 58 | $options = [ |
||
| 59 | 'base_uri' => $this->_getBaseUrl($connection), |
||
| 60 | 'headers' => [ |
||
| 61 | 'Content-Type' => $request->getContentType(), |
||
| 62 | ], |
||
| 63 | 'exceptions' => false, // 4xx and 5xx is expected and NOT an exceptions in this context |
||
| 64 | ]; |
||
| 65 | if ($connection->getTimeout()) { |
||
| 66 | $options['timeout'] = $connection->getTimeout(); |
||
| 67 | } |
||
| 68 | |||
| 69 | if (null !== $proxy = $connection->getProxy()) { |
||
| 70 | $options['proxy'] = $proxy; |
||
| 71 | } |
||
| 72 | |||
| 73 | $req = $this->_createPsr7Request($request, $connection); |
||
| 74 | |||
| 75 | try { |
||
| 76 | $start = \microtime(true); |
||
| 77 | $res = $client->send($req, $options); |
||
| 78 | $end = \microtime(true); |
||
| 79 | } catch (TransferException $ex) { |
||
| 80 | throw new GuzzleException($ex, $request, new Response($ex->getMessage())); |
||
| 81 | } |
||
| 82 | |||
| 83 | $responseBody = (string) $res->getBody(); |
||
| 84 | $response = new Response($responseBody, $res->getStatusCode()); |
||
| 85 | $response->setQueryTime($end - $start); |
||
| 86 | if ($connection->hasConfig('bigintConversion')) { |
||
| 87 | $response->setJsonBigintConversion($connection->getConfig('bigintConversion')); |
||
|
|
|||
| 88 | } |
||
| 89 | |||
| 90 | $response->setTransferInfo( |
||
| 91 | [ |
||
| 92 | 'request_header' => $request->getMethod(), |
||
| 93 | 'http_code' => $res->getStatusCode(), |
||
| 94 | ] |
||
| 95 | ); |
||
| 96 | |||
| 97 | if ($response->hasError()) { |
||
| 98 | throw new ResponseException($request, $response); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($response->hasFailedShards()) { |
||
| 102 | throw new PartialShardFailureException($request, $response); |
||
| 103 | } |
||
| 104 | |||
| 105 | return $response; |
||
| 106 | } |
||
| 107 | |||
| 205 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: