From 066c03d1175569a58afdbf1853529226233c2094 Mon Sep 17 00:00:00 2001 From: Thomas Meschke Date: Tue, 19 Nov 2024 16:13:49 +0100 Subject: [PATCH] refactor FileSizeUnit enum * reorder cases and function * add DocBlock for return and throws --- system/Files/FileSizeUnit.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/system/Files/FileSizeUnit.php b/system/Files/FileSizeUnit.php index 49dac2cebf25..581582689f05 100644 --- a/system/Files/FileSizeUnit.php +++ b/system/Files/FileSizeUnit.php @@ -13,23 +13,30 @@ namespace CodeIgniter\Files; +use InvalidArgumentException; + enum FileSizeUnit: int { - case B = 0; - case KB = 1; - case MB = 2; - case GB = 3; - case TB = 4; - + /** + * Allows the creation of a FileSizeUnit from Strings like "kb" or "mb" + * + * @throws InvalidArgumentException + */ public static function fromString(string $unit): self { return match (strtolower($unit)) { - 'b' => self::B, - 'kb' => self::KB, - 'mb' => self::MB, - 'gb' => self::GB, - 'tb' => self::TB, - default => throw new InvalidArgumentException("Invalid unit: $unit"), + 'b' => self::B, + 'kb' => self::KB, + 'mb' => self::MB, + 'gb' => self::GB, + 'tb' => self::TB, + default => throw new InvalidArgumentException("Invalid unit: {$unit}"), }; } + + case B = 0; + case KB = 1; + case MB = 2; + case GB = 3; + case TB = 4; }