Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Module/Repository/Internal/GitHub/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@
// GitHub rate limit responses have format: ["API rate limit ...", "https://docs.github.com/..."]
if (\is_array($decoded)
&& \count($decoded) === 2
&& \is_string($decoded[0])
&& \is_string($decoded[1])
&& \str_contains($decoded[0], 'API rate limit')
&& \is_string(\reset($decoded))
&& \is_string(\next($decoded))
&& \str_contains(\reset($decoded), 'API rate limit')

Check failure on line 91 in src/Module/Repository/Internal/GitHub/Api/Client.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MixedArgument

src/Module/Repository/Internal/GitHub/Api/Client.php:91:34: MixedArgument: Argument 1 of str_contains cannot be mixed, expecting string (see https://psalm.dev/030)

Check failure on line 91 in src/Module/Repository/Internal/GitHub/Api/Client.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MixedArgument

src/Module/Repository/Internal/GitHub/Api/Client.php:91:34: MixedArgument: Argument 1 of str_contains cannot be mixed, expecting string (see https://psalm.dev/030)
) {
throw GitHubRateLimitException::fromApiResponse($decoded);

Check failure on line 93 in src/Module/Repository/Internal/GitHub/Api/Client.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MixedArgumentTypeCoercion

src/Module/Repository/Internal/GitHub/Api/Client.php:93:65: MixedArgumentTypeCoercion: Argument 1 of Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException::fromApiResponse expects array{0?: string, 1?: string, documentation_url?: string, message?: string}, but parent type non-empty-array<array-key, mixed> provided (see https://psalm.dev/194)

Check failure on line 93 in src/Module/Repository/Internal/GitHub/Api/Client.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MixedArgumentTypeCoercion

src/Module/Repository/Internal/GitHub/Api/Client.php:93:65: MixedArgumentTypeCoercion: Argument 1 of Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException::fromApiResponse expects array{0?: string, 1?: string, documentation_url?: string, message?: string}, but parent type non-empty-array<array-key, mixed> provided (see https://psalm.dev/194)
}
} catch (\JsonException) {
// Not a JSON response, continue without rate limit check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
public function __construct(
public readonly string $documentationUrl,
string $message = 'GitHub API rate limit exceeded',
string $message = 'GitHub API rate limit exceeded. Check the GitHub Token or try again later.',
?\Throwable $previous = null,
) {
parent::__construct($message, 0, $previous);
Expand All @@ -23,13 +23,13 @@
/**
* Creates exception from GitHub API response body.
*
* @param array{0: string, 1: string} $responseData
* @param array{0: string, 1: string}|array{message: string, documentation_url: string} $responseData
*/
public static function fromApiResponse(array $responseData): self
{
return new self(
documentationUrl: $responseData[1],
message: $responseData[0],
documentationUrl: $responseData[1] ?? $responseData['documentation_url'],

Check failure on line 31 in src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyUndefinedArrayOffset

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php:31:51: PossiblyUndefinedArrayOffset: Possibly undefined array key $responseData['documentation_url'] on array{0?: string, 1?: string, documentation_url?: string, message?: string} (see https://psalm.dev/167)

Check failure on line 31 in src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyNullArgument

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php:31:31: PossiblyNullArgument: Argument 1 of Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException::__construct cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 31 in src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyUndefinedArrayOffset

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php:31:51: PossiblyUndefinedArrayOffset: Possibly undefined array key $responseData['documentation_url'] on array{0?: string, 1?: string, documentation_url?: string, message?: string} (see https://psalm.dev/167)

Check failure on line 31 in src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyNullArgument

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php:31:31: PossiblyNullArgument: Argument 1 of Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException::__construct cannot be null, possibly null value provided (see https://psalm.dev/078)
message: $responseData[0] ?? $responseData['message'],

Check failure on line 32 in src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyUndefinedArrayOffset

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php:32:42: PossiblyUndefinedArrayOffset: Possibly undefined array key $responseData['message'] on array{0?: string, 1?: string, documentation_url?: string, message?: string} (see https://psalm.dev/167)

Check failure on line 32 in src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyNullArgument

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php:32:22: PossiblyNullArgument: Argument 2 of Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException::__construct cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 32 in src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyUndefinedArrayOffset

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php:32:42: PossiblyUndefinedArrayOffset: Possibly undefined array key $responseData['message'] on array{0?: string, 1?: string, documentation_url?: string, message?: string} (see https://psalm.dev/167)

Check failure on line 32 in src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyNullArgument

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php:32:22: PossiblyNullArgument: Argument 2 of Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException::__construct cannot be null, possibly null value provided (see https://psalm.dev/078)
);
}
}
3 changes: 3 additions & 0 deletions src/Module/Repository/Internal/GitHub/GitHubRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Internal\Destroy\Destroyable;
use Internal\DLoad\Module\Repository\Collection\ReleasesCollection;
use Internal\DLoad\Module\Repository\Internal\GitHub\Api\RepositoryApi;
use Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException;
use Internal\DLoad\Module\Repository\Repository;

/**
Expand Down Expand Up @@ -73,6 +74,8 @@ public function getReleases(): ReleasesCollection

// Check if there are more pages by getting next page
$hasMorePages = $paginator->getNextPage() !== null;
} catch (GitHubRateLimitException $e) {
throw $e;
} catch (\Throwable) {
return;
}
Expand Down
Loading