From c67a182cf262a012a309802957b917e9a5092dc5 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Wed, 24 Sep 2025 19:35:06 +0200 Subject: [PATCH] test: resolve phpstan issues --- app/Models/Device.php | 27 +++++++++++++++++++++++++++ app/Models/PlaylistItem.php | 12 ++++++------ app/Models/Plugin.php | 18 +++++++++--------- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/app/Models/Device.php b/app/Models/Device.php index 5001a22..8d75fb5 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -10,6 +10,9 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Facades\Storage; +/** + * @property-read DeviceModel|null $deviceModel + */ class Device extends Model { use HasFactory; @@ -188,6 +191,30 @@ class Device extends Model return $this->belongsTo(DeviceModel::class); } + /** + * Get the color depth string (e.g., "4bit") for the associated device model. + */ + public function colorDepth(): ?string + { + return $this->deviceModel?->color_depth; + } + + /** + * Get the scale level (e.g., large/xlarge/xxlarge) for the associated device model. + */ + public function scaleLevel(): ?string + { + return $this->deviceModel?->scale_level; + } + + /** + * Get the device variant name, defaulting to 'og' if not available. + */ + public function deviceVariant(): string + { + return $this->deviceModel->name ?? 'og'; + } + public function logs(): HasMany { return $this->hasMany(DeviceLog::class); diff --git a/app/Models/PlaylistItem.php b/app/Models/PlaylistItem.php index 28f6454..9db5d4d 100644 --- a/app/Models/PlaylistItem.php +++ b/app/Models/PlaylistItem.php @@ -139,9 +139,9 @@ class PlaylistItem extends Model { if (! $this->isMashup()) { return view('trmnl-layouts.single', [ - 'colorDepth' => $device?->deviceModel?->color_depth, - 'deviceVariant' => $device?->deviceModel->name ?? 'og', - 'scaleLevel' => $device?->deviceModel?->scale_level, + 'colorDepth' => $device?->colorDepth(), + 'deviceVariant' => $device?->deviceVariant() ?? 'og', + 'scaleLevel' => $device?->scaleLevel(), 'slot' => $this->plugin instanceof Plugin ? $this->plugin->render('full', false) : throw new Exception('Invalid plugin instance'), @@ -163,9 +163,9 @@ class PlaylistItem extends Model } return view('trmnl-layouts.mashup', [ - 'colorDepth' => $device?->deviceModel?->color_depth, - 'deviceVariant' => $device?->deviceModel->name ?? 'og', - 'scaleLevel' => $device?->deviceModel?->scale_level, + 'colorDepth' => $device?->colorDepth(), + 'deviceVariant' => $device?->deviceVariant() ?? 'og', + 'scaleLevel' => $device?->scaleLevel(), 'mashupLayout' => $this->getMashupLayoutType(), 'slot' => implode('', $pluginMarkups), ])->render(); diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index f5f6928..ab2f825 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -345,18 +345,18 @@ class Plugin extends Model if ($standalone) { if ($size === 'full') { return view('trmnl-layouts.single', [ - 'colorDepth' => $device?->deviceModel?->color_depth, - 'deviceVariant' => $device?->deviceModel->name ?? 'og', - 'scaleLevel' => $device?->deviceModel?->scale_level, + 'colorDepth' => $device?->colorDepth(), + 'deviceVariant' => $device?->deviceVariant() ?? 'og', + 'scaleLevel' => $device?->scaleLevel(), 'slot' => $renderedContent, ])->render(); } return view('trmnl-layouts.mashup', [ 'mashupLayout' => $this->getPreviewMashupLayoutForSize($size), - 'colorDepth' => $device?->deviceModel?->color_depth, - 'deviceVariant' => $device?->deviceModel->name ?? 'og', - 'scaleLevel' => $device?->deviceModel?->scale_level, + 'colorDepth' => $device?->colorDepth(), + 'deviceVariant' => $device?->deviceVariant() ?? 'og', + 'scaleLevel' => $device?->scaleLevel(), 'slot' => $renderedContent, ])->render(); @@ -368,9 +368,9 @@ class Plugin extends Model if ($this->render_markup_view) { if ($standalone) { return view('trmnl-layouts.single', [ - 'colorDepth' => $device?->deviceModel?->color_depth, - 'deviceVariant' => $device?->deviceModel->name ?? 'og', - 'scaleLevel' => $device?->deviceModel?->scale_level, + 'colorDepth' => $device?->colorDepth(), + 'deviceVariant' => $device?->deviceVariant() ?? 'og', + 'scaleLevel' => $device?->scaleLevel(), 'slot' => view($this->render_markup_view, [ 'size' => $size, 'data' => $this->data_payload,