diff --git a/system/Files/FileSizeUnit.php b/system/Files/FileSizeUnit.php index 49dac2cebf25..23f58baed0c3 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, + '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; }