test: resolve phpstan issues

This commit is contained in:
Benjamin Nussbaum 2025-09-24 19:35:06 +02:00
parent a1a57014b6
commit c67a182cf2
3 changed files with 42 additions and 15 deletions

View file

@ -10,6 +10,9 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
/**
* @property-read DeviceModel|null $deviceModel
*/
class Device extends Model class Device extends Model
{ {
use HasFactory; use HasFactory;
@ -188,6 +191,30 @@ class Device extends Model
return $this->belongsTo(DeviceModel::class); 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 public function logs(): HasMany
{ {
return $this->hasMany(DeviceLog::class); return $this->hasMany(DeviceLog::class);

View file

@ -139,9 +139,9 @@ class PlaylistItem extends Model
{ {
if (! $this->isMashup()) { if (! $this->isMashup()) {
return view('trmnl-layouts.single', [ return view('trmnl-layouts.single', [
'colorDepth' => $device?->deviceModel?->color_depth, 'colorDepth' => $device?->colorDepth(),
'deviceVariant' => $device?->deviceModel->name ?? 'og', 'deviceVariant' => $device?->deviceVariant() ?? 'og',
'scaleLevel' => $device?->deviceModel?->scale_level, 'scaleLevel' => $device?->scaleLevel(),
'slot' => $this->plugin instanceof Plugin 'slot' => $this->plugin instanceof Plugin
? $this->plugin->render('full', false) ? $this->plugin->render('full', false)
: throw new Exception('Invalid plugin instance'), : throw new Exception('Invalid plugin instance'),
@ -163,9 +163,9 @@ class PlaylistItem extends Model
} }
return view('trmnl-layouts.mashup', [ return view('trmnl-layouts.mashup', [
'colorDepth' => $device?->deviceModel?->color_depth, 'colorDepth' => $device?->colorDepth(),
'deviceVariant' => $device?->deviceModel->name ?? 'og', 'deviceVariant' => $device?->deviceVariant() ?? 'og',
'scaleLevel' => $device?->deviceModel?->scale_level, 'scaleLevel' => $device?->scaleLevel(),
'mashupLayout' => $this->getMashupLayoutType(), 'mashupLayout' => $this->getMashupLayoutType(),
'slot' => implode('', $pluginMarkups), 'slot' => implode('', $pluginMarkups),
])->render(); ])->render();

View file

@ -345,18 +345,18 @@ class Plugin extends Model
if ($standalone) { if ($standalone) {
if ($size === 'full') { if ($size === 'full') {
return view('trmnl-layouts.single', [ return view('trmnl-layouts.single', [
'colorDepth' => $device?->deviceModel?->color_depth, 'colorDepth' => $device?->colorDepth(),
'deviceVariant' => $device?->deviceModel->name ?? 'og', 'deviceVariant' => $device?->deviceVariant() ?? 'og',
'scaleLevel' => $device?->deviceModel?->scale_level, 'scaleLevel' => $device?->scaleLevel(),
'slot' => $renderedContent, 'slot' => $renderedContent,
])->render(); ])->render();
} }
return view('trmnl-layouts.mashup', [ return view('trmnl-layouts.mashup', [
'mashupLayout' => $this->getPreviewMashupLayoutForSize($size), 'mashupLayout' => $this->getPreviewMashupLayoutForSize($size),
'colorDepth' => $device?->deviceModel?->color_depth, 'colorDepth' => $device?->colorDepth(),
'deviceVariant' => $device?->deviceModel->name ?? 'og', 'deviceVariant' => $device?->deviceVariant() ?? 'og',
'scaleLevel' => $device?->deviceModel?->scale_level, 'scaleLevel' => $device?->scaleLevel(),
'slot' => $renderedContent, 'slot' => $renderedContent,
])->render(); ])->render();
@ -368,9 +368,9 @@ class Plugin extends Model
if ($this->render_markup_view) { if ($this->render_markup_view) {
if ($standalone) { if ($standalone) {
return view('trmnl-layouts.single', [ return view('trmnl-layouts.single', [
'colorDepth' => $device?->deviceModel?->color_depth, 'colorDepth' => $device?->colorDepth(),
'deviceVariant' => $device?->deviceModel->name ?? 'og', 'deviceVariant' => $device?->deviceVariant() ?? 'og',
'scaleLevel' => $device?->deviceModel?->scale_level, 'scaleLevel' => $device?->scaleLevel(),
'slot' => view($this->render_markup_view, [ 'slot' => view($this->render_markup_view, [
'size' => $size, 'size' => $size,
'data' => $this->data_payload, 'data' => $this->data_payload,