Upgrade CallbackValidator

closes #6343
This commit is contained in:
Dylan K. Taylor
2025-08-30 19:23:38 +01:00
parent 06b48d97e9
commit 9a9506b793
7 changed files with 25 additions and 45 deletions

View File

@@ -27,7 +27,7 @@ declare(strict_types=1);
namespace pocketmine\utils;
use DaveRandom\CallbackValidator\CallbackType;
use DaveRandom\CallbackValidator\Prototype;
use pocketmine\entity\Location;
use pocketmine\errorhandler\ErrorTypeToStringMap;
use pocketmine\math\Vector3;
@@ -554,20 +554,14 @@ final class Utils{
* Verifies that the given callable is compatible with the desired signature. Throws a TypeError if they are
* incompatible.
*
* @param callable|CallbackType $signature Dummy callable with the required parameters and return type
* @param callable $subject Callable to check the signature of
* @phpstan-param anyCallable|CallbackType $signature
* @phpstan-param anyCallable $subject
*
* @throws \DaveRandom\CallbackValidator\InvalidCallbackException
* @throws \TypeError
* @param \Closure $signature Dummy callable with the required parameters and return type
* @param \Closure $subject Callable to check the signature of
* @phpstan-param anyClosure $signature
* @phpstan-param anyClosure $subject
*/
public static function validateCallableSignature(callable|CallbackType $signature, callable $subject) : void{
if(!($signature instanceof CallbackType)){
$signature = CallbackType::createFromCallable($signature);
}
if(!$signature->isSatisfiedBy($subject)){
throw new \TypeError("Declaration of callable `" . CallbackType::createFromCallable($subject) . "` must be compatible with `" . $signature . "`");
public static function validateCallableSignature(\Closure $signature, \Closure $subject) : void{
if(!Prototype::isSatisfiedBy($signature, $subject)){
throw new \TypeError("Declaration of callable `" . Prototype::print($subject) . "` must be compatible with `" . Prototype::print($signature) . "`");
}
}