Utils: fixed testValidInstance() not accepting the same valid class for both className and baseName

this caused problems in PlayerCreationEvent because plugins set the base class and then set the player class to the same thing.
This commit is contained in:
Dylan K. Taylor 2021-10-26 00:31:30 +01:00
parent 94f4ef5862
commit 4178c81209
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -519,12 +519,10 @@ final class Utils{
if(!class_exists($className)){
throw new \InvalidArgumentException("Class $className does not exist");
}
$base = new \ReflectionClass($baseName);
$class = new \ReflectionClass($className);
if(!$class->isSubclassOf($baseName)){
throw new \InvalidArgumentException("Class $className does not " . ($base->isInterface() ? "implement" : "extend") . " " . $baseName);
if(!is_a($className, $baseName, true)){
throw new \InvalidArgumentException("Class $className does not extend or implement $baseName");
}
$class = new \ReflectionClass($className);
if(!$class->isInstantiable()){
throw new \InvalidArgumentException("Class $className cannot be constructed");
}