Skip to content

Commit 85d2b2f

Browse files
committed
Cleaned up code
1 parent da58440 commit 85d2b2f

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/ApiClient.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ protected function getRequestUrl(string $rel, array $values = []): string
521521

522522
$url = $index[$rel]['href'] ?? null;
523523
if (null === $url) {
524-
throw $this->createRuntimeException(sprintf('Cannot get rel %s', $rel));
524+
$message = sprintf('Cannot get rel %s', $rel);
525+
throw $this->createRuntimeException($message);
525526
}
526527

527528
return $this->replacePlaceholders($url, $values);
@@ -547,13 +548,15 @@ protected function getSearchRequestUrl(string $rel, array $values): string
547548
// @mago-ignore analysis:mixed-array-access,non-documented-property
548549
$searchUrl = (string) $sxe->Url['template'];
549550
if (!filter_var($searchUrl, FILTER_VALIDATE_URL)) {
550-
throw $this->createRuntimeException(sprintf('Cannot get search template URL for %s', $url));
551+
$message = sprintf('Cannot get search template URL for %s', $url);
552+
throw $this->createRuntimeException($message);
551553
}
552554

553555
return $searchUrl;
554556
});
555557
} catch (\Exception $e) {
556-
throw $this->createRuntimeException(sprintf('Cannot get search URL for rel %s', $rel), previous: $e);
558+
$message = sprintf('Cannot get search URL for rel %s', $rel);
559+
throw $this->createRuntimeException($message, previous: $e);
557560
}
558561

559562
return $this->replacePlaceholders($url, $values);
@@ -570,7 +573,8 @@ protected function replacePlaceholders(string $url, array $values): string
570573
function (array $matches) use ($url, $values): string {
571574
$name = $matches['name'];
572575
if (!array_key_exists($name, $values)) {
573-
throw $this->createRuntimeException(sprintf('Missing value %s for URL %s', $name, $url));
576+
$message = sprintf('Missing value %s for URL %s', $name, $url);
577+
throw $this->createRuntimeException($message);
574578
}
575579

576580
return rawurlencode((string) $values[$name]);
@@ -594,14 +598,16 @@ protected function getCache(): CacheInterface
594598
protected function computeCacheKey(array $context): string
595599
{
596600
if (0 === count($context)) {
597-
throw new RuntimeException('Cache key context cannot be empty');
601+
$message = 'Cache key context cannot be empty';
602+
throw $this->createRuntimeException($message);
598603
}
599604
try {
600605
return sha1(json_encode($this->options + [$context], JSON_THROW_ON_ERROR));
601606
} catch (\Exception $exception) {
602607
// JSON encode context without throwing any exceptions.
603608
$encodedContext = (string) json_encode($context);
604-
throw new RuntimeException(sprintf('Cannot compute cache key for context %s', $encodedContext), previous: $exception);
609+
$message = sprintf('Cannot compute cache key for context %s', $encodedContext);
610+
throw $this->createRuntimeException($message, previous: $exception);
605611
}
606612
}
607613

@@ -656,7 +662,8 @@ private function getHeader(string $name, ResponseInterface $response): string
656662
$headers = $response->getHeaders();
657663
$name = strtolower($name);
658664
if (!array_key_exists($name, $headers) || 0 === count($headers[$name])) {
659-
throw $this->createRuntimeException(sprintf('Header "%s" not found.', $name));
665+
$message = sprintf('Header "%s" not found.', $name);
666+
throw $this->createRuntimeException($message);
660667
}
661668

662669
return reset($headers[$name]);

src/Command/F2ApiClientCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public function __invoke(
2727
?string $arg = null,
2828
#[Option(description: 'Show links.')]
2929
bool $showLinks = false,
30-
#[Option(description: 'Path to to cache directory. If not specified, the default file system cache directory will be used.')]
30+
#[Option(
31+
description: 'Path to to cache directory. If not specified, the default file system cache directory will be used.',
32+
)]
3133
?string $cacheDirectory = null,
3234
): int {
3335
$client = $this->createClient(cacheDirectory: $cacheDirectory);

0 commit comments

Comments
 (0)