From b097b0a7d7ce57faf1dedc3c5efbb0b2e3530a78 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Thu, 15 Jan 2026 13:14:50 +0100 Subject: [PATCH] chore: phpstan fixes, rector --- app/Liquid/Filters/StringMarkup.php | 2 +- app/Models/Plugin.php | 6 +++--- app/Services/ImageGenerationService.php | 8 ++++---- app/Services/PluginImportService.php | 8 ++++---- .../{Volt => Livewire/Catalog}/CatalogTrmnlTest.php | 0 tests/Feature/{Volt => Livewire}/DevicePalettesTest.php | 4 +--- tests/Feature/PluginImportTest.php | 4 ++-- 7 files changed, 15 insertions(+), 17 deletions(-) rename tests/Feature/{Volt => Livewire/Catalog}/CatalogTrmnlTest.php (100%) rename tests/Feature/{Volt => Livewire}/DevicePalettesTest.php (99%) diff --git a/app/Liquid/Filters/StringMarkup.php b/app/Liquid/Filters/StringMarkup.php index 10c5abc..6cdf4c0 100644 --- a/app/Liquid/Filters/StringMarkup.php +++ b/app/Liquid/Filters/StringMarkup.php @@ -73,7 +73,7 @@ class StringMarkup extends FiltersProvider // Default module_size is 11 // Size calculation: (21 modules for QR code + 4 modules margin on each side * 2) * module_size // = (21 + 8) * module_size = 29 * module_size - $moduleSize = $moduleSize ?? 11; + $moduleSize ??= 11; $size = 29 * $moduleSize; $qrCode = QrCode::format('svg') diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 68f8e7e..31841bc 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -174,8 +174,8 @@ class Plugin extends Model // resolve and clean URLs $resolvedPollingUrls = $this->resolveLiquidVariables($this->polling_url); $urls = array_values(array_filter( // array_values ensures 0, 1, 2... - array_map('trim', explode("\n", $resolvedPollingUrls)), - fn ($url): bool => filled($url) + array_map(trim(...), explode("\n", $resolvedPollingUrls)), + filled(...) )); $combinedResponse = []; @@ -624,7 +624,7 @@ class Plugin extends Model // File doesn't exist, remove the view reference $attributes['render_markup_view'] = null; } - } catch (Exception $e) { + } catch (Exception) { // If file reading fails, remove the view reference $attributes['render_markup_view'] = null; } diff --git a/app/Services/ImageGenerationService.php b/app/Services/ImageGenerationService.php index 405ea3f..87fb6d9 100644 --- a/app/Services/ImageGenerationService.php +++ b/app/Services/ImageGenerationService.php @@ -61,9 +61,9 @@ class ImageGenerationService try { // Get image generation settings from DeviceModel or Device (for legacy devices) - $imageSettings = $deviceModel + $imageSettings = $deviceModel instanceof DeviceModel ? self::getImageSettingsFromModel($deviceModel) - : ($device ? self::getImageSettings($device) : self::getImageSettingsFromModel(null)); + : ($device instanceof Device ? self::getImageSettings($device) : self::getImageSettingsFromModel(null)); $fileExtension = $imageSettings['mime_type'] === 'image/bmp' ? 'bmp' : 'png'; $outputPath = Storage::disk('public')->path('/images/generated/'.$uuid.'.'.$fileExtension); @@ -78,7 +78,7 @@ class ImageGenerationService $browserStage->html($markup); // Set timezone from user or fall back to app timezone - $timezone = $user?->timezone ?? config('app.timezone'); + $timezone = $user->timezone ?? config('app.timezone'); $browserStage->timezone($timezone); if (config('app.puppeteer_window_size_strategy') === 'v2') { @@ -186,7 +186,7 @@ class ImageGenerationService */ private static function getImageSettingsFromModel(?DeviceModel $deviceModel): array { - if ($deviceModel) { + if ($deviceModel instanceof DeviceModel) { return [ 'width' => $deviceModel->width, 'height' => $deviceModel->height, diff --git a/app/Services/PluginImportService.php b/app/Services/PluginImportService.php index 49dce99..51a9aee 100644 --- a/app/Services/PluginImportService.php +++ b/app/Services/PluginImportService.php @@ -33,11 +33,11 @@ class PluginImportService foreach ($settings['custom_fields'] as $field) { if (isset($field['field_type']) && $field['field_type'] === 'multi_string') { - if (isset($field['default']) && str_contains($field['default'], ',')) { + if (isset($field['default']) && str_contains((string) $field['default'], ',')) { throw new Exception("Validation Error: The default value for multistring fields like `{$field['keyname']}` cannot contain commas."); } - if (isset($field['placeholder']) && str_contains($field['placeholder'], ',')) { + if (isset($field['placeholder']) && str_contains((string) $field['placeholder'], ',')) { throw new Exception("Validation Error: The placeholder value for multistring fields like `{$field['keyname']}` cannot contain commas."); } @@ -159,7 +159,7 @@ class PluginImportService : null, 'polling_body' => $settings['polling_body'] ?? null, 'markup_language' => $markupLanguage, - 'render_markup' => $fullLiquid, + 'render_markup' => $fullLiquid ?? null, 'configuration_template' => $configurationTemplate, 'data_payload' => json_decode($settings['static_data'] ?? '{}', true), ]); @@ -321,7 +321,7 @@ class PluginImportService : null, 'polling_body' => $settings['polling_body'] ?? null, 'markup_language' => $markupLanguage, - 'render_markup' => $fullLiquid, + 'render_markup' => $fullLiquid ?? null, 'configuration_template' => $configurationTemplate, 'data_payload' => json_decode($settings['static_data'] ?? '{}', true), 'preferred_renderer' => $preferredRenderer, diff --git a/tests/Feature/Volt/CatalogTrmnlTest.php b/tests/Feature/Livewire/Catalog/CatalogTrmnlTest.php similarity index 100% rename from tests/Feature/Volt/CatalogTrmnlTest.php rename to tests/Feature/Livewire/Catalog/CatalogTrmnlTest.php diff --git a/tests/Feature/Volt/DevicePalettesTest.php b/tests/Feature/Livewire/DevicePalettesTest.php similarity index 99% rename from tests/Feature/Volt/DevicePalettesTest.php rename to tests/Feature/Livewire/DevicePalettesTest.php index f94708e..3c37934 100644 --- a/tests/Feature/Volt/DevicePalettesTest.php +++ b/tests/Feature/Livewire/DevicePalettesTest.php @@ -156,9 +156,7 @@ test('can delete a device palette', function (): void { ->call('deleteDevicePalette', $palette->id); expect(DevicePalette::find($palette->id))->toBeNull(); - $component->assertSet('devicePalettes', function ($palettes) use ($palette) { - return $palettes->where('id', $palette->id)->isEmpty(); - }); + $component->assertSet('devicePalettes', fn ($palettes) => $palettes->where('id', $palette->id)->isEmpty()); }); test('can duplicate a device palette', function (): void { diff --git a/tests/Feature/PluginImportTest.php b/tests/Feature/PluginImportTest.php index f3ef1fa..cc47e67 100644 --- a/tests/Feature/PluginImportTest.php +++ b/tests/Feature/PluginImportTest.php @@ -467,7 +467,7 @@ YAML; $zipFile = UploadedFile::fake()->createWithContent('invalid-default.zip', $zipContent); $pluginImportService = new PluginImportService(); - expect(fn () => $pluginImportService->importFromZip($zipFile, $user)) + expect(fn (): Plugin => $pluginImportService->importFromZip($zipFile, $user)) ->toThrow(Exception::class, 'Validation Error: The default value for multistring fields like `api_key` cannot contain commas.'); }); @@ -497,7 +497,7 @@ YAML; $zipFile = UploadedFile::fake()->createWithContent('invalid-placeholder.zip', $zipContent); $pluginImportService = new PluginImportService(); - expect(fn () => $pluginImportService->importFromZip($zipFile, $user)) + expect(fn (): Plugin => $pluginImportService->importFromZip($zipFile, $user)) ->toThrow(Exception::class, 'Validation Error: The placeholder value for multistring fields like `api_key` cannot contain commas.'); });