Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael-at-bunny committed Jul 26, 2024
1 parent 666bb19 commit a2df99f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@

namespace Bunny\Storage;

use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Promise\Utils as PromiseUtils;
use Psr\Http\Message\ResponseInterface;

class Client
{
private string $apiAccessKey;
private string $storageZoneName;
private string $baseUrl;
private \GuzzleHttp\Client $httpClient;
private HttpClient $httpClient;

public function __construct(
string $apiKey,
string $storageZoneName,
string $storageZoneRegion = Region::FALKENSTEIN,
?\GuzzleHttp\Client $httpClient = null
?HttpClient $httpClient = null
) {
if (!isset(Region::LIST[$storageZoneRegion])) {
throw new InvalidRegionException();
Expand All @@ -25,7 +29,7 @@ public function __construct(
$this->storageZoneName = $storageZoneName;
$this->baseUrl = Region::getBaseUrl($storageZoneRegion);

$this->httpClient = $httpClient ?? new \GuzzleHttp\Client([
$this->httpClient = $httpClient ?? new HttpClient([
'allow_redirects' => false,
'http_errors' => false,
'base_uri' => $this->baseUrl,
Expand Down Expand Up @@ -259,10 +263,10 @@ public function deleteMultiple(array $to_delete): array
$requests[$path] = $this->httpClient->requestAsync('DELETE', $this->normalizePath($path, $isDirectory));
}

$results = \GuzzleHttp\Promise\Utils::unwrap($requests);
$results = PromiseUtils::unwrap($requests);
$errors = [];

/** @var \Psr\Http\Message\ResponseInterface $response */
/** @var ResponseInterface $response */
foreach ($results as $path => $response) {
if (200 !== $response->getStatusCode()) {
$data = json_decode($response->getBody()->getContents(), true);
Expand Down

0 comments on commit a2df99f

Please sign in to comment.