mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
RegistryTrait: fixed mishandling of self::$members
Since PHPStan doesn't warn about potential nulls on untyped properties, this flew under the radar.
This commit is contained in:
parent
fe94379a93
commit
a5aeabd836
@ -37,8 +37,8 @@ use function preg_match;
|
||||
*/
|
||||
trait RegistryTrait{
|
||||
/**
|
||||
* @var object[]
|
||||
* @phpstan-var array<string, object>
|
||||
* @var object[]|null
|
||||
* @phpstan-var array<string, object>|null
|
||||
*/
|
||||
private static $members = null;
|
||||
|
||||
@ -54,6 +54,9 @@ trait RegistryTrait{
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private static function _registryRegister(string $name, object $member) : void{
|
||||
if(self::$members === null){
|
||||
throw new AssumptionFailedError("Cannot register members outside of " . self::class . "::setup()");
|
||||
}
|
||||
self::verifyName($name);
|
||||
$upperName = mb_strtoupper($name);
|
||||
if(isset(self::$members[$upperName])){
|
||||
@ -86,6 +89,9 @@ trait RegistryTrait{
|
||||
*/
|
||||
private static function _registryFromString(string $name) : object{
|
||||
self::checkInit();
|
||||
if(self::$members === null){
|
||||
throw new AssumptionFailedError(self::class . "::checkInit() did not initialize self::\$members correctly");
|
||||
}
|
||||
$upperName = mb_strtoupper($name);
|
||||
if(!isset(self::$members[$upperName])){
|
||||
throw new \InvalidArgumentException("No such registry member: " . self::class . "::" . $upperName);
|
||||
@ -121,6 +127,6 @@ trait RegistryTrait{
|
||||
*/
|
||||
private static function _registryGetAll() : array{
|
||||
self::checkInit();
|
||||
return array_map(self::preprocessMember(...), self::$members);
|
||||
return array_map(self::preprocessMember(...), self::$members ?? throw new AssumptionFailedError(self::class . "::checkInit() did not initialize self::\$members correctly"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user