Skip to content

Commit

Permalink
allow FileSizeUnit selection from String
Browse files Browse the repository at this point in the history
Co-authored-by: Michal Sniatala <[email protected]>
  • Loading branch information
ThomasMeschke and michalsn authored Nov 19, 2024
1 parent bf9a9a8 commit 8829ea8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions system/Files/FileSizeUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ enum FileSizeUnit: int
case MB = 2;
case GB = 3;
case TB = 4;

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"),

Check failure on line 32 in system/Files/FileSizeUnit.php

View workflow job for this annotation

GitHub Actions / Psalm Analysis

UndefinedClass

system/Files/FileSizeUnit.php:32:34: UndefinedClass: Class, interface or enum named CodeIgniter\Files\InvalidArgumentException does not exist (see https://psalm.dev/019)

Check failure on line 32 in system/Files/FileSizeUnit.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Instantiated class CodeIgniter\Files\InvalidArgumentException not found.

Check failure on line 32 in system/Files/FileSizeUnit.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Throwing object of an unknown class CodeIgniter\Files\InvalidArgumentException.
};
}
}

0 comments on commit 8829ea8

Please sign in to comment.