Skip to content

Update Client to handle response data in a new method #63

Closed
@thinkingserious

Description

@thinkingserious

Method makeRequest has 33 lines of code (exceeds 25 allowed). Consider refactoring.

https://codeclimate.com/github/sendgrid/php-http-client/lib/Client.php#issue_59f3f044c7fa44000100001a

Is it possible to move all of this to another method in the class?

$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
 
        $responseBody = substr($response, $headerSize);
        $responseHeaders = substr($response, 0, $headerSize);
 
        $responseHeaders = explode("\n", $responseHeaders);
        $responseHeaders = array_map('trim', $responseHeaders);
 
        curl_close($curl);
     
        $response = new Response($statusCode, $responseBody, $responseHeaders);

Also, can the retry logic be moved to another method?

       if ($statusCode == 429 && $retryOnLimit) {
            $headers = $response->headers(true);
            $sleepDurations = $headers['X-Ratelimit-Reset'] - time();
            sleep($sleepDurations > 0 ? $sleepDurations : 0);
            return $this->makeRequest($method, $url, $body, $headers, false);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions