From acfc26ecee7d0d04d0de50d1a619548d9807d41e Mon Sep 17 00:00:00 2001 From: Ivan Moroz Date: Thu, 28 May 2026 23:57:29 +0300 Subject: [PATCH] CONV-033: Implement format normalization Co-Authored-By: Claude Opus 4.7 --- app/Enums/FileFormat.php | 19 +++++++++++++++++++ .../Exceptions/UnsupportedFormatException.php | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 app/Support/Converters/Exceptions/UnsupportedFormatException.php diff --git a/app/Enums/FileFormat.php b/app/Enums/FileFormat.php index cd4acc8..99a25ab 100644 --- a/app/Enums/FileFormat.php +++ b/app/Enums/FileFormat.php @@ -2,10 +2,29 @@ namespace App\Enums; +use App\Support\Converters\Exceptions\UnsupportedFormatException; + enum FileFormat: string { case Png = 'png'; case Jpg = 'jpg'; case Webp = 'webp'; case Pdf = 'pdf'; + + public static function normalize(string $input): string + { + $value = ltrim(strtolower(trim($input)), '.'); + + if ($value === 'jpeg') { + return self::Jpg->value; + } + + foreach (self::cases() as $case) { + if ($case->value === $value) { + return $case->value; + } + } + + throw UnsupportedFormatException::forInput($input); + } } diff --git a/app/Support/Converters/Exceptions/UnsupportedFormatException.php b/app/Support/Converters/Exceptions/UnsupportedFormatException.php new file mode 100644 index 0000000..a713773 --- /dev/null +++ b/app/Support/Converters/Exceptions/UnsupportedFormatException.php @@ -0,0 +1,13 @@ +