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
2 changes: 1 addition & 1 deletion src/SchemaLoader/CompositeSchemaLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CompositeSchemaLoader implements SchemaLoaderInterface
/**
* @param list<SchemaLoaderInterface> $loaders
*/
public function __construct(private readonly array $loaders) {}
public function __construct(protected readonly array $loaders) {}

public function loadSchemas(): array
{
Expand Down
21 changes: 11 additions & 10 deletions src/SchemaLoader/GithubSchemaLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class GithubSchemaLoader implements SchemaLoaderInterface
* @param list<array{url: string, token_env: string|null}> $sources
*/
public function __construct(
private readonly array $sources,
private readonly ClientInterface $httpClient,
private readonly RequestFactoryInterface $requestFactory
protected readonly array $sources,
protected readonly ClientInterface $httpClient,
protected readonly RequestFactoryInterface $requestFactory
) {}

public function loadSchemas(): array
Expand All @@ -32,7 +32,7 @@ public function loadSchemas(): array

if ($tokenEnv !== null) {
$envValue = $_ENV[$tokenEnv] ?? getenv($tokenEnv);
$token = \is_string($envValue) ? $envValue : null;
$token = \is_string($envValue) && $envValue !== '' ? $envValue : null;
}

$parsed = $this->parseGithubUrl($url);
Expand Down Expand Up @@ -120,14 +120,14 @@ private function fetchDirectoryContents(
\sprintf(
'GitHub API request failed for "%s" (%s): %s',
$apiUrl,
$token !== null && $token !== '' ? 'with authentication' : 'without authentication',
$token === null ? 'without authentication' : 'with authentication',
$e->getMessage()
),
previous: $e
);
}

$this->validateResponse($response, $apiUrl);
$this->validateResponse($response, $apiUrl, $token);
$contents = $this->decodeJsonResponse($response, $apiUrl);

$schemas = [];
Expand Down Expand Up @@ -177,19 +177,19 @@ private function fetchFileContent(string $url, ?string $token): string
\sprintf(
'Failed to fetch file from "%s" (%s): %s',
$url,
$token !== null && $token !== '' ? 'with authentication' : 'without authentication',
$token === null ? 'without authentication' : 'with authentication',
$e->getMessage(),
),
previous: $e
);
}

$this->validateResponse($response, $url);
$this->validateResponse($response, $url, $token);

return $response->getBody()->getContents();
}

private function validateResponse(ResponseInterface $response, string $url): void
private function validateResponse(ResponseInterface $response, string $url, ?string $token): void
{
$statusCode = $response->getStatusCode();

Expand All @@ -210,8 +210,9 @@ private function validateResponse(ResponseInterface $response, string $url): voi

throw new SchemaLoaderException(
\sprintf(
'GitHub API request failed for "%s": HTTP %d %s',
'GitHub API request failed for "%s" (%s): HTTP %d %s',
$url,
$token === null ? 'without authentication' : 'with authentication',
$statusCode,
$response->getReasonPhrase()
)
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaLoader/LocalSchemaLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class LocalSchemaLoader implements SchemaLoaderInterface
/**
* @param list<string> $paths
*/
public function __construct(private readonly array $paths) {}
public function __construct(protected readonly array $paths) {}

public function loadSchemas(): array
{
Expand Down