Skip to content

Commit

Permalink
Update LibrariesIO.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsizemore committed Dec 29, 2023
1 parent 51b57c6 commit 68917c4
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/LibrariesIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function __construct(#[SensitiveParameter] string $apiKey, ?string $cache

$this->apiKey = $apiKey;

if ($cachePath !== null && is_dir($cachePath) && is_writable($cachePath)) {
if (is_dir((string) $cachePath) && is_writable((string) $cachePath)) {
$this->cachePath = $cachePath;
}
}
Expand Down Expand Up @@ -191,19 +191,18 @@ protected function makeRequest(string $endpoint, string $method = 'get'): Respon
{
// Attempt the request
try {
/** @phpstan-ignore-next-line **/
return match($method) {
'get' => $this->client->get($endpoint), /** @phpstan-ignore-line **/
'post' => $this->client->post($endpoint), /** @phpstan-ignore-line **/
'put' => $this->client->put($endpoint), /** @phpstan-ignore-line **/
'delete' => $this->client->delete($endpoint) /** @phpstan-ignore-line **/
'get' => $this->client->get($endpoint), /** @phpstan-ignore-line **/
'post' => $this->client->post($endpoint), /** @phpstan-ignore-line **/
'put' => $this->client->put($endpoint), /** @phpstan-ignore-line **/
'delete' => $this->client->delete($endpoint), /** @phpstan-ignore-line **/
default => $this->client->get($endpoint) /** @phpstan-ignore-line **/
};
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() === 429) {
throw new RateLimitExceededException('Libraries.io API rate limit exceeded.', previous: $e);
} else {
throw $e;
}
throw $e;
}
}

Expand Down Expand Up @@ -400,23 +399,21 @@ public function subscription(string $endpoint, array $options): ResponseInterfac
}

// Build query
$query = [];

if (isset($options['include_prerelease']) && ($endpoint === 'subscribe' || $endpoint === 'update')) {
$query['include_prerelease'] = $options['include_prerelease'];
if (isset($options['include_prerelease'])) {
$query = ['include_prerelease' => $options['include_prerelease']];
}

/** @phpstan-ignore-next-line **/
$this->makeClient($query ?? []);

// Attempt the request
$method = match($endpoint) {
'subscribe' => 'post',
'check' => 'get',
'update' => 'put',
'unsubscribe' => 'delete'
'unsubscribe' => 'delete',
default => 'get'
};

$this->makeClient($query);

// Attempt the request
$endpointParameters['format'] = $this->processEndpointFormat(/** @phpstan-ignore-line **/$endpointParameters['format'], $options);

return $this->makeRequest($endpointParameters['format'], $method);
Expand Down

0 comments on commit 68917c4

Please sign in to comment.