| Conditions | 7 |
| Paths | 64 |
| Total Lines | 56 |
| Code Lines | 29 |
| 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 |
||
| 108 | public function request( |
||
| 109 | string $method, |
||
| 110 | string $url, |
||
| 111 | $body, |
||
| 112 | array $query = [], |
||
| 113 | array $header = [], |
||
| 114 | ?SerializerInterface $inputSerializer = null, |
||
| 115 | ?SerializerInterface $outputSerializer = null |
||
| 116 | ): Response { |
||
| 117 | $requestId = $this->incrementRequestCounter(); |
||
| 118 | |||
| 119 | $outputSerializer ??= $this->defaultSerializer; |
||
| 120 | $inputSerializer ??= $this->defaultSerializer; |
||
| 121 | |||
| 122 | if ($inputSerializer) { |
||
| 123 | $header['Content-Type'] = $header['Content-Type'] ?? $inputSerializer->getContentType(); |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($outputSerializer) { |
||
| 127 | $header['Accept'] = $header['Accept'] ?? $outputSerializer->getContentType(); |
||
| 128 | } |
||
| 129 | |||
| 130 | $this->logger->debug("({$requestId}) {$method} {$url} : Sending request", ['body' => $body, 'query' => $query, 'header' => $header]); |
||
|
|
|||
| 131 | |||
| 132 | try { |
||
| 133 | $response = $this->httpClient->request( |
||
| 134 | $method, |
||
| 135 | $url, |
||
| 136 | // @NOTE: |
||
| 137 | // We are not using our custom serializer from args |
||
| 138 | // because it easier for an external user to send an alternative body encoded |
||
| 139 | // with another serialization method (Ex: XML) as an string instead of |
||
| 140 | // assuming that the response from the current endpoint is also expecting |
||
| 141 | // to receive XML data. |
||
| 142 | $this->serialize($body, $inputSerializer), |
||
| 143 | $query, |
||
| 144 | $header |
||
| 145 | ) ?? ''; |
||
| 146 | |||
| 147 | $response = Response::from($response, $this->httpClient->lastResponseHeaders(), $this->httpClient->lastResponseStatusCode()); |
||
| 148 | $response->setSerializer($outputSerializer); |
||
| 149 | |||
| 150 | $this->logger->debug("({$requestId}) {$method} {$url} : Read successful", ['response' => $response->getBody()]); |
||
| 151 | return $this->responseReceived($response) ?? $response; |
||
| 152 | } catch (HttpException $e) { |
||
| 153 | $response = $e->getResponse(); |
||
| 154 | $this->logger->error("({$requestId}) {$method} {$url} : Read failed with status code {$e->getStatusCode()} {$e->getStatusMessage()}", ['exception' => strval($e), 'response' => $response ? $response->getBody() : null]); |
||
| 155 | |||
| 156 | if ($response) { |
||
| 157 | $response->setSerializer($outputSerializer); |
||
| 158 | } |
||
| 159 | |||
| 160 | $this->exceptionThrown($e); |
||
| 161 | } catch (Throwable $e) { |
||
| 162 | $this->logger->error("({$requestId}) {$method} {$url} : Read failed with unhandled exception", ['exception' => strval($e)]); |
||
| 163 | $this->exceptionThrown($e); |
||
| 164 | } |
||
| 199 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.