mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +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{
|
trait RegistryTrait{
|
||||||
/**
|
/**
|
||||||
* @var object[]
|
* @var object[]|null
|
||||||
* @phpstan-var array<string, object>
|
* @phpstan-var array<string, object>|null
|
||||||
*/
|
*/
|
||||||
private static $members = null;
|
private static $members = null;
|
||||||
|
|
||||||
@ -54,6 +54,9 @@ trait RegistryTrait{
|
|||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
private static function _registryRegister(string $name, object $member) : void{
|
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);
|
self::verifyName($name);
|
||||||
$upperName = mb_strtoupper($name);
|
$upperName = mb_strtoupper($name);
|
||||||
if(isset(self::$members[$upperName])){
|
if(isset(self::$members[$upperName])){
|
||||||
@ -86,6 +89,9 @@ trait RegistryTrait{
|
|||||||
*/
|
*/
|
||||||
private static function _registryFromString(string $name) : object{
|
private static function _registryFromString(string $name) : object{
|
||||||
self::checkInit();
|
self::checkInit();
|
||||||
|
if(self::$members === null){
|
||||||
|
throw new AssumptionFailedError(self::class . "::checkInit() did not initialize self::\$members correctly");
|
||||||
|
}
|
||||||
$upperName = mb_strtoupper($name);
|
$upperName = mb_strtoupper($name);
|
||||||
if(!isset(self::$members[$upperName])){
|
if(!isset(self::$members[$upperName])){
|
||||||
throw new \InvalidArgumentException("No such registry member: " . self::class . "::" . $upperName);
|
throw new \InvalidArgumentException("No such registry member: " . self::class . "::" . $upperName);
|
||||||
@ -121,6 +127,6 @@ trait RegistryTrait{
|
|||||||
*/
|
*/
|
||||||
private static function _registryGetAll() : array{
|
private static function _registryGetAll() : array{
|
||||||
self::checkInit();
|
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