Skip to content

Commit

Permalink
refactor FileSizeUnit enum
Browse files Browse the repository at this point in the history
* reorder cases and function
* add DocBlock for return and throws
  • Loading branch information
ThomasMeschke committed Nov 19, 2024
1 parent f1464e3 commit 40f6d7b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions system/Files/FileSizeUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

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"
*
* @return FileSizeUnit
*
* @throws \InvalidArgumentException
*/
public static function fromString(string $unit): self
{
return match (strtolower($unit)) {
Expand All @@ -29,7 +30,13 @@ public static function fromString(string $unit): self
'mb' => self::MB,
'gb' => self::GB,
'tb' => self::TB,
default => throw new InvalidArgumentException("Invalid unit: $unit"),
default => throw new \InvalidArgumentException("Invalid unit: $unit"),
};
}

case B = 0;
case KB = 1;
case MB = 2;
case GB = 3;
case TB = 4;
}

0 comments on commit 40f6d7b

Please sign in to comment.