From 631826923ab1b7796f250c2756c80789114467ac Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sun, 13 Sep 2020 17:56:29 +0100 Subject: [PATCH] =?UTF-8?q?Use=20Laravel=E2=80=99s=20Array=20helper=20to?= =?UTF-8?q?=20ease=20accessing=20data=20in=20authorship=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Jobs/SaveProfileImage.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Jobs/SaveProfileImage.php b/app/Jobs/SaveProfileImage.php index 44073f23..cf2197e3 100644 --- a/app/Jobs/SaveProfileImage.php +++ b/app/Jobs/SaveProfileImage.php @@ -10,6 +10,7 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Arr; use Jonnybarnes\WebmentionsParser\Authorship; use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException; @@ -19,8 +20,7 @@ class SaveProfileImage implements ShouldQueue use Queueable; use SerializesModels; - /** @var array */ - protected $microformats; + protected array $microformats; /** * Create a new job instance. @@ -44,17 +44,18 @@ class SaveProfileImage implements ShouldQueue } catch (AuthorshipParserException $e) { return; } - $photo = $author['properties']['photo'][0]; - $home = $author['properties']['url'][0]; + $photo = Arr::get($author, 'properties.photo.0'); + $home = Arr::get($author, 'properties.url.0'); //dont save pbs.twimg.com links if ( - parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com' + $photo + && parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com' && parse_url($photo, PHP_URL_HOST) != 'twitter.com' ) { $client = resolve(Client::class); try { $response = $client->get($photo); - $image = $response->getBody(true); + $image = $response->getBody(); } catch (RequestException $e) { // we are opening and reading the default image so that $default = public_path() . '/assets/profile-images/default-image';