File tree Expand file tree Collapse file tree 1 file changed +19
-12
lines changed
Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Original file line number Diff line number Diff line change 1313
1414namespace CodeIgniter \Files ;
1515
16+ use InvalidArgumentException ;
17+
1618enum 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}
You can’t perform that action at this time.
0 commit comments