diff --git a/lib/ApiClient/Http/Client.php b/lib/ApiClient/Http/Client.php index 3f1d90b..d66000d 100644 --- a/lib/ApiClient/Http/Client.php +++ b/lib/ApiClient/Http/Client.php @@ -58,29 +58,14 @@ private function execute( array $formData = [] ): Response { try { - if ($formData) { - /** @var GuzzleResponse $response */ - $guzzleResponse = $this->guzzle->request( - $method, - $url, - [ - 'headers' => $headers, - 'form_params' => $formData, - 'timeout' => 30 - ] - ); - } else { - /** @var GuzzleResponse $response */ - $guzzleResponse = $this->guzzle->request( - $method, - $url, - [ - 'headers' => $headers, - 'body' => $content, - 'timeout' => 30 - ] - ); - } + $guzzleResponse = $this->doExecute( + $method, + $url, + $headers, + $content, + $formData + ); + } catch (ConnectException $e) { if (str_contains($e->getMessage(), 'cURL error 28')) { throw new HttpTimeOutException(); @@ -100,4 +85,32 @@ private function execute( $guzzleResponse->getHeaders() ); } + + private function doExecute( + string $method, + string $url, + array $headers, + ?string $content, + array $formData + ): GuzzleResponse { + $requestData = [ + 'headers' => $headers, + 'timeout' => 30 + ]; + + if ($formData) { + $requestData['form_params'] = $formData; + } else { + $requestData['body'] = $content; + } + + /** @var GuzzleResponse $response */ + $guzzleResponse = $this->guzzle->request( + $method, + $url, + $requestData + ); + + return $guzzleResponse; + } }