From 8aea83703c0503dd6f9cf97b1701164c31d77c59 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Mon, 6 Oct 2025 23:47:27 +0200 Subject: [PATCH] chore: format --- app/Liquid/Filters/Date.php | 12 ++++++------ app/Liquid/Utils/ExpressionUtils.php | 3 ++- app/Models/Plugin.php | 10 ++++++---- app/Notifications/BatteryLow.php | 2 +- tests/Unit/Liquid/Filters/DateTest.php | 21 ++++++++++----------- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/Liquid/Filters/Date.php b/app/Liquid/Filters/Date.php index 20c412c..6bc81fc 100644 --- a/app/Liquid/Filters/Date.php +++ b/app/Liquid/Filters/Date.php @@ -35,21 +35,21 @@ class Date extends FiltersProvider { $date = Carbon::parse($dateStr); $ordinalDay = $date->ordinal('day'); - + // Convert strftime format to PHP date format $phpFormat = ExpressionUtils::strftimeToPhpFormat($strftimeExp); - + // Split the format string by the ordinal day placeholder $parts = explode('<>', $phpFormat); - + if (count($parts) === 2) { $before = $date->format($parts[0]); $after = $date->format($parts[1]); - return $before . $ordinalDay . $after; + + return $before.$ordinalDay.$after; } - + // Fallback: if no placeholder found, just format normally return $date->format($phpFormat); } - } diff --git a/app/Liquid/Utils/ExpressionUtils.php b/app/Liquid/Utils/ExpressionUtils.php index 924bcf0..8a5bdb0 100644 --- a/app/Liquid/Utils/ExpressionUtils.php +++ b/app/Liquid/Utils/ExpressionUtils.php @@ -84,6 +84,7 @@ class ExpressionUtils if (self::evaluateCondition($condition['left'], $variable, $object)) { return true; } + return self::evaluateCondition($condition['right'], $variable, $object); case 'comparison': @@ -179,7 +180,7 @@ class ExpressionUtils '%-S' => 's', // Second without leading zero (Ruby) -> second without leading zero (PHP) '%z' => 'O', // Timezone offset (Ruby) -> timezone offset (PHP) '%Z' => 'T', // Timezone name (Ruby) -> timezone name (PHP) - + // Standard strftime conversions '%A' => 'l', // Full weekday name '%a' => 'D', // Abbreviated weekday name diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index f0a1dd9..b372cdd 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -237,7 +237,7 @@ class Plugin extends Model // Converts to: {% assign temp_filtered = collection | filter: "key", "value" %}{% for item in temp_filtered %} $template = preg_replace_callback( '/{%\s*for\s+(\w+)\s+in\s+([^|%}]+)\s*\|\s*([^%}]+)%}/', - function ($matches): string { + function (array $matches): string { $variableName = mb_trim($matches[1]); $collection = mb_trim($matches[2]); $filter = mb_trim($matches[3]); @@ -259,10 +259,11 @@ class Plugin extends Model // Handle date filter formats: date: "format" or date: 'format' $template = preg_replace_callback( '/date:\s*(["\'])([^"\']+)\1/', - function ($matches): string { + function (array $matches): string { $quote = $matches[1]; $format = $matches[2]; $convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format); + return 'date: '.$quote.$convertedFormat.$quote; }, $template @@ -271,13 +272,14 @@ class Plugin extends Model // Handle l_date filter formats: l_date: "format" or l_date: 'format' $template = preg_replace_callback( '/l_date:\s*(["\'])([^"\']+)\1/', - function ($matches): string { + function (array $matches): string { $quote = $matches[1]; $format = $matches[2]; $convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format); + return 'l_date: '.$quote.$convertedFormat.$quote; }, - $template + (string) $template ); return $template; diff --git a/app/Notifications/BatteryLow.php b/app/Notifications/BatteryLow.php index e590398..17fb1da 100644 --- a/app/Notifications/BatteryLow.php +++ b/app/Notifications/BatteryLow.php @@ -36,7 +36,7 @@ class BatteryLow extends Notification return (new MailMessage)->markdown('mail.battery-low', ['device' => $this->device]); } - public function toWebhook(object $notifiable): \App\Notifications\Messages\WebhookMessage + public function toWebhook(object $notifiable): WebhookMessage { return WebhookMessage::create() ->data([ diff --git a/tests/Unit/Liquid/Filters/DateTest.php b/tests/Unit/Liquid/Filters/DateTest.php index cf31e13..7de8949 100644 --- a/tests/Unit/Liquid/Filters/DateTest.php +++ b/tests/Unit/Liquid/Filters/DateTest.php @@ -51,45 +51,44 @@ test('ordinalize filter handles different ordinal suffixes', function (): void { // 1st expect($filter->ordinalize('2025-01-01', '<>')) ->toBe('1st'); - + // 2nd expect($filter->ordinalize('2025-01-02', '<>')) ->toBe('2nd'); - + // 3rd expect($filter->ordinalize('2025-01-03', '<>')) ->toBe('3rd'); - + // 4th expect($filter->ordinalize('2025-01-04', '<>')) ->toBe('4th'); - + // 11th (special case) expect($filter->ordinalize('2025-01-11', '<>')) ->toBe('11th'); - + // 12th (special case) expect($filter->ordinalize('2025-01-12', '<>')) ->toBe('12th'); - + // 13th (special case) expect($filter->ordinalize('2025-01-13', '<>')) ->toBe('13th'); - + // 21st expect($filter->ordinalize('2025-01-21', '<>')) ->toBe('21st'); - + // 22nd expect($filter->ordinalize('2025-01-22', '<>')) ->toBe('22nd'); - + // 23rd expect($filter->ordinalize('2025-01-23', '<>')) ->toBe('23rd'); - + // 24th expect($filter->ordinalize('2025-01-24', '<>')) ->toBe('24th'); }); -