Skip to content

Commit

Permalink
Merge pull request #721 from pinkary-project/fix/link-preview-tests-r…
Browse files Browse the repository at this point in the history
…elated-errors

Fix/link preview tests related errors
  • Loading branch information
nunomaduro authored Nov 2, 2024
2 parents 5df17b8 + 561cfc2 commit bc02a32
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
14 changes: 8 additions & 6 deletions app/Services/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private function getData(): Collection

if ($response->ok()) {
$data = $this->parse($response->body())
->filter(fn ($value): bool => $value !== '');
->filter(fn (string $value): bool => $value !== '');
}
} catch (ConnectionException) {
// Catch but not capture the exception
Expand All @@ -77,8 +77,10 @@ private function fetchOEmbed(string $service, array $options): Collection
);

if ($response->ok()) {
$data = collect((array) $response->json())
->filter(fn ($value): bool => $value !== '');
/** @var Collection<string, string|null> $data */
$data = $response->collect();
$data = $data
->filter(fn (?string $value): bool => (string) $value !== '');
}
} catch (ConnectionException) {
// Catch but not capture the exception
Expand Down Expand Up @@ -116,9 +118,9 @@ private function parse(string $content): Collection
}

collect(['name', 'property'])
->map(fn ($name): string => $meta->getAttribute($name))
->filter(fn ($attribute): bool => in_array(explode(':', $attribute)[0], $interested_in))
->each(function ($attribute) use ($data, $allowed, $meta): void {
->map(fn (string $name): string => $meta->getAttribute($name))
->filter(fn (string $attribute): bool => in_array(explode(':', $attribute)[0], $interested_in))
->each(function (string $attribute) use ($data, $allowed, $meta): void {
$key = explode(':', $attribute)[1];
if (! $data->has($key) && in_array($key, $allowed, true)) {
$data->put($key, $meta->getAttribute('content'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
<a href="https://pinkary.com/@nunomaduro" target="_blank" rel="noopener noreferrer"
class="text-xs text-slate-500 group-hover/preview:text-pink-600">From: pinkary.com</a>
</div>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ Sure, here is the link: <div
<a href="https://laravel.com" target="_blank" rel="noopener noreferrer"
class="text-xs text-slate-500 group-hover/preview:text-pink-600">From: laravel.com</a>
</div>

</div>. Let me know if you have any questions.

0 comments on commit bc02a32

Please sign in to comment.