Skip to content

Commit

Permalink
refactor: move duplicated code to private method
Browse files Browse the repository at this point in the history
  • Loading branch information
George Borges committed Sep 24, 2020
1 parent 220248e commit 272b34c
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/Network/HttpClient.php
Expand Up @@ -94,20 +94,7 @@ public function post($url, array $options = [])
['User-Agent' => self::PHP_GA_MEASUREMENT_PROTOCOL_USER_AGENT]
);

$opts = $this->parseOptions($options);
$response = $this->getClient()->sendAsync($request, [
'synchronous' => !$opts['async'],
'timeout' => $opts['timeout'],
'connect_timeout' => $opts['timeout'],
]);

if ($opts['async']) {
self::$promises[] = $response;
} else {
$response = $response->wait();
}

return $this->getAnalyticsResponse($request, $response);
return $this->sendRequest($request, $options);
}

/**
Expand All @@ -130,6 +117,11 @@ public function batch($url, array $batchUrls, array $options = [])
$body
);

return $this->sendRequest($request, $options);
}

private function sendRequest(Request $request, array $options = [])
{
$opts = $this->parseOptions($options);
$response = $this->getClient()->sendAsync($request, [
'synchronous' => !$opts['async'],
Expand Down

0 comments on commit 272b34c

Please sign in to comment.