mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-03 00:25:04 +00:00
EnumTrait: use a better method to initialize enums
this method is simpler, and is also safe at the native type level. Coincidentally, it also eliminates 30 PHPStan false-positives.
This commit is contained in:
@ -38,26 +38,9 @@ trait EnumTrait{
|
||||
self::_registryRegister($member->name(), $member);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of enum members to be registered.
|
||||
*
|
||||
* (This ought to be private, but traits suck too much for that.)
|
||||
*
|
||||
* @return self[]|iterable
|
||||
*/
|
||||
abstract protected static function setup() : iterable;
|
||||
|
||||
/**
|
||||
* @internal Lazy-inits the enum if necessary.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected static function checkInit() : void{
|
||||
if(self::$members === null){
|
||||
self::$members = [];
|
||||
foreach(self::setup() as $item){
|
||||
self::register($item);
|
||||
}
|
||||
protected static function registerAll(self ...$members) : void{
|
||||
foreach($members as $member){
|
||||
self::register($member);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user