From 972fed24c81714210de75f210516be2ef7a9fed4 Mon Sep 17 00:00:00 2001 From: Matthias Nagel Date: Thu, 3 Feb 2022 18:51:23 +0100 Subject: [PATCH] Fix some potential null references --- app/Console/Commands/PhotosAddedNotification.php | 2 +- app/Models/Extensions/Thumb.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/PhotosAddedNotification.php b/app/Console/Commands/PhotosAddedNotification.php index 7b7d4ce4810..6eb488bc3c2 100644 --- a/app/Console/Commands/PhotosAddedNotification.php +++ b/app/Console/Commands/PhotosAddedNotification.php @@ -68,7 +68,7 @@ public function handle(): int ]; } - $thumbUrl = $photo->size_variants->getThumb()->url; + $thumbUrl = $photo->size_variants->getThumb()?->url; logger($thumbUrl); // If the url config doesn't contain a trailing slash then add it diff --git a/app/Models/Extensions/Thumb.php b/app/Models/Extensions/Thumb.php index 057f066d69a..a4f97634f0a 100644 --- a/app/Models/Extensions/Thumb.php +++ b/app/Models/Extensions/Thumb.php @@ -14,10 +14,10 @@ class Thumb implements Arrayable, JsonSerializable { protected string $id; protected string $type; - protected ?string $thumbUrl; + protected string $thumbUrl; protected ?string $thumb2xUrl; - protected function __construct(string $id, string $type, ?string $thumbUrl, ?string $thumb2xUrl = null) + protected function __construct(string $id, string $type, string $thumbUrl, ?string $thumb2xUrl = null) { $this->id = $id; $this->type = $type; @@ -76,12 +76,15 @@ public static function createFromPhoto(?Photo $photo): ?Thumb return null; } $thumb = $photo->size_variants->getThumb(); + if (!$thumb) { + return null; + } $thumb2x = $photo->size_variants->getThumb2x(); return new self( $photo->id, $photo->type, - $thumb?->url, + $thumb->url, $thumb2x?->url ); }