Skip to content

Commit 68917c4

Browse files
committed
Update LibrariesIO.php
1 parent 51b57c6 commit 68917c4

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

src/LibrariesIO.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __construct(#[SensitiveParameter] string $apiKey, ?string $cache
121121

122122
$this->apiKey = $apiKey;
123123

124-
if ($cachePath !== null && is_dir($cachePath) && is_writable($cachePath)) {
124+
if (is_dir((string) $cachePath) && is_writable((string) $cachePath)) {
125125
$this->cachePath = $cachePath;
126126
}
127127
}
@@ -191,19 +191,18 @@ protected function makeRequest(string $endpoint, string $method = 'get'): Respon
191191
{
192192
// Attempt the request
193193
try {
194-
/** @phpstan-ignore-next-line **/
195194
return match($method) {
196-
'get' => $this->client->get($endpoint), /** @phpstan-ignore-line **/
197-
'post' => $this->client->post($endpoint), /** @phpstan-ignore-line **/
198-
'put' => $this->client->put($endpoint), /** @phpstan-ignore-line **/
199-
'delete' => $this->client->delete($endpoint) /** @phpstan-ignore-line **/
195+
'get' => $this->client->get($endpoint), /** @phpstan-ignore-line **/
196+
'post' => $this->client->post($endpoint), /** @phpstan-ignore-line **/
197+
'put' => $this->client->put($endpoint), /** @phpstan-ignore-line **/
198+
'delete' => $this->client->delete($endpoint), /** @phpstan-ignore-line **/
199+
default => $this->client->get($endpoint) /** @phpstan-ignore-line **/
200200
};
201201
} catch (ClientException $e) {
202202
if ($e->getResponse()->getStatusCode() === 429) {
203203
throw new RateLimitExceededException('Libraries.io API rate limit exceeded.', previous: $e);
204-
} else {
205-
throw $e;
206204
}
205+
throw $e;
207206
}
208207
}
209208

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

402401
// Build query
403-
$query = [];
404-
405-
if (isset($options['include_prerelease']) && ($endpoint === 'subscribe' || $endpoint === 'update')) {
406-
$query['include_prerelease'] = $options['include_prerelease'];
402+
if (isset($options['include_prerelease'])) {
403+
$query = ['include_prerelease' => $options['include_prerelease']];
407404
}
408405

409-
/** @phpstan-ignore-next-line **/
406+
$this->makeClient($query ?? []);
407+
408+
// Attempt the request
410409
$method = match($endpoint) {
411410
'subscribe' => 'post',
412411
'check' => 'get',
413412
'update' => 'put',
414-
'unsubscribe' => 'delete'
413+
'unsubscribe' => 'delete',
414+
default => 'get'
415415
};
416416

417-
$this->makeClient($query);
418-
419-
// Attempt the request
420417
$endpointParameters['format'] = $this->processEndpointFormat(/** @phpstan-ignore-line **/$endpointParameters['format'], $options);
421418

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

0 commit comments

Comments
 (0)