mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 04:38:35 +00:00
EventPriority: hardcode name -> value mapping instead of using constant()
this would have caught fire if additional non-priority constants were added, or if the constants were renamed.
This commit is contained in:
parent
f5e033ad5d
commit
e9038336e3
@ -23,8 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\event;
|
namespace pocketmine\event;
|
||||||
|
|
||||||
use function constant;
|
|
||||||
use function defined;
|
|
||||||
use function mb_strtoupper;
|
use function mb_strtoupper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,10 +82,16 @@ final class EventPriority{
|
|||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public static function fromString(string $name) : int{
|
public static function fromString(string $name) : int{
|
||||||
$name = mb_strtoupper($name);
|
$value = [
|
||||||
$const = self::class . "::" . $name;
|
"LOWEST" => self::LOWEST,
|
||||||
if($name !== "ALL" and defined($const)){
|
"LOW" => self::LOW,
|
||||||
return constant($const);
|
"NORMAL" => self::NORMAL,
|
||||||
|
"HIGH" => self::HIGH,
|
||||||
|
"HIGHEST" => self::HIGHEST,
|
||||||
|
"MONITOR" => self::MONITOR
|
||||||
|
][mb_strtoupper($name)] ?? null;
|
||||||
|
if($value !== null){
|
||||||
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException("Unable to resolve priority \"$name\"");
|
throw new \InvalidArgumentException("Unable to resolve priority \"$name\"");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user