Skip to content

Commit

Permalink
fix code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
datlechin committed Nov 10, 2024
1 parent 0a053c0 commit 11842e0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Api/Controllers/BatchLinkPreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function processUrls(array $urls): array
$processResult = $this->preProcessUrl($url);
if (isset($processResult['data'])) {
$result[$url] = $processResult['data'];
} else if (isset($processResult['fetch'])) {
} elseif (isset($processResult['fetch'])) {
$urlsToFetch[$url] = $processResult['fetch'];
} else {
$result[$url] = $processResult['error'];
Expand All @@ -52,7 +52,7 @@ protected function processUrls(array $urls): array

foreach ($urlsToFetch as $originalUrl => $normalizedUrl) {
$result[$originalUrl] = $fetchResults[$originalUrl] ?? [
'error' => 'Failed to fetch preview'
'error' => 'Failed to fetch preview',
];
}

Expand All @@ -63,15 +63,15 @@ protected function preProcessUrl(string $url): array
{
if (!$this->service->isValidUrl($url)) {
return [
'error' => $this->service->getErrorResponse('datlechin-link-preview.forum.site_cannot_be_reached')
'error' => $this->service->getErrorResponse('datlechin-link-preview.forum.site_cannot_be_reached'),
];
}

$normalizedUrl = $this->service->normalizeUrl($url);

if (!$this->service->isUrlAllowed($normalizedUrl)) {
return [
'error' => $this->service->getErrorResponse('datlechin-link-preview.forum.site_cannot_be_reached')
'error' => $this->service->getErrorResponse('datlechin-link-preview.forum.site_cannot_be_reached'),
];
}

Expand All @@ -93,7 +93,7 @@ protected function fetchUrls(array $urlsToFetch): array
$promises[$originalUrl] = $this->service->getClient()->getAsync($originalUrl);
} catch (Throwable $e) {
$results[$originalUrl] = [
'error' => 'Failed to create request: ' . $e->getMessage()
'error' => 'Failed to create request: ' . $e->getMessage(),
];
}
}
Expand All @@ -112,7 +112,7 @@ protected function fetchUrls(array $urlsToFetch): array
$results[$originalUrl] = [
'error' => $response['reason'] instanceof \Exception ?
$response['reason']->getMessage() :
'Failed to fetch preview'
'Failed to fetch preview',
];
continue;
}
Expand All @@ -124,7 +124,7 @@ protected function fetchUrls(array $urlsToFetch): array
$results[$originalUrl] = $data;
} catch (Throwable $e) {
$results[$originalUrl] = [
'error' => $e->getMessage()
'error' => $e->getMessage(),
];
}
}
Expand Down

0 comments on commit 11842e0

Please sign in to comment.