Skip to content

Commit 066c03d

Browse files
committed
refactor FileSizeUnit enum
* reorder cases and function * add DocBlock for return and throws
1 parent f1464e3 commit 066c03d

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

system/Files/FileSizeUnit.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,30 @@
1313

1414
namespace CodeIgniter\Files;
1515

16+
use InvalidArgumentException;
17+
1618
enum FileSizeUnit: int
1719
{
18-
case B = 0;
19-
case KB = 1;
20-
case MB = 2;
21-
case GB = 3;
22-
case TB = 4;
23-
20+
/**
21+
* Allows the creation of a FileSizeUnit from Strings like "kb" or "mb"
22+
*
23+
* @throws InvalidArgumentException
24+
*/
2425
public static function fromString(string $unit): self
2526
{
2627
return match (strtolower($unit)) {
27-
'b' => self::B,
28-
'kb' => self::KB,
29-
'mb' => self::MB,
30-
'gb' => self::GB,
31-
'tb' => self::TB,
32-
default => throw new InvalidArgumentException("Invalid unit: $unit"),
28+
'b' => self::B,
29+
'kb' => self::KB,
30+
'mb' => self::MB,
31+
'gb' => self::GB,
32+
'tb' => self::TB,
33+
default => throw new InvalidArgumentException("Invalid unit: {$unit}"),
3334
};
3435
}
36+
37+
case B = 0;
38+
case KB = 1;
39+
case MB = 2;
40+
case GB = 3;
41+
case TB = 4;
3542
}

0 commit comments

Comments
 (0)