| Conditions | 7 |
| Paths | 10 |
| Total Lines | 52 |
| 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 |
||
| 64 | * Sends a PSR-7 request. |
||
| 65 | * |
||
| 66 | * @param \Psr\Http\Message\RequestInterface $request |
||
| 67 | * |
||
| 68 | * @return \Psr\Http\Message\ResponseInterface |
||
| 69 | * |
||
| 70 | * @throws \Http\Client\Exception If an error happens during processing the request. |
||
| 71 | * @throws \Exception If processing the request is impossible (eg. bad configuration). |
||
| 72 | */ |
||
| 73 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
||
| 74 | $handle = new CurlHandle($request, $this->responseFactory->createResponse(), $this->options); |
||
| 75 | $handle->init(); |
||
| 76 | |||
| 77 | curl_exec($handle->ch); |
||
| 78 | |||
| 79 | $errno = curl_errno($handle->ch); |
||
| 80 | |||
| 81 | if($errno !== CURLE_OK){ |
||
| 82 | $error = curl_error($handle->ch); |
||
| 83 | |||
| 84 | $network_errors = [ |
||
| 85 | CURLE_COULDNT_RESOLVE_PROXY, |
||
| 86 | CURLE_COULDNT_RESOLVE_HOST, |
||
| 87 | CURLE_COULDNT_CONNECT, |
||
| 88 | CURLE_OPERATION_TIMEOUTED, |
||
| 89 | CURLE_SSL_CONNECT_ERROR, |
||
| 90 | CURLE_GOT_NOTHING, |
||
| 91 | ]; |
||
| 92 | |||
| 93 | if(in_array($errno, $network_errors, true)){ |
||
| 94 | throw new NetworkException($error, $request); |
||
| 95 | } |
||
| 96 | |||
| 97 | throw new RequestException($error, $request); |
||
| 98 | } |
||
| 99 | |||
| 100 | $handle->close(); |
||
| 101 | $handle->response->getBody()->rewind(); |
||
| 102 | |||
| 103 | return $handle->response; |
||
| 104 | |||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param string $uri |
||
| 109 | * @param string|null $method |
||
| 110 | * @param array|null $query |
||
| 111 | * @param mixed|null $body |
||
| 112 | * @param array|null $headers |
||
| 113 | * |
||
| 114 | * @return \Psr\Http\Message\ResponseInterface |
||
| 115 | */ |
||
| 116 | public function request(string $uri, string $method = null, array $query = null, $body = null, array $headers = null):ResponseInterface{ |
||
| 149 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.