From f1c5c7b6991d22baa7040ada74ed2574f292a1c8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 10 Oct 2025 23:00:35 +0100 Subject: [PATCH] Update CallbackValidator --- composer.lock | 8 ++++---- src/utils/Utils.php | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index c01cdc3fa..7cadc08ba 100644 --- a/composer.lock +++ b/composer.lock @@ -349,12 +349,12 @@ "source": { "type": "git", "url": "https://github.com/pmmp/CallbackValidator.git", - "reference": "4b9b375590872cdd98a2a07c5aa0e1e99af5ceda" + "reference": "8e0e3be58e89c2611beac9c6954a036b81b2b6fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/CallbackValidator/zipball/4b9b375590872cdd98a2a07c5aa0e1e99af5ceda", - "reference": "4b9b375590872cdd98a2a07c5aa0e1e99af5ceda", + "url": "https://api.github.com/repos/pmmp/CallbackValidator/zipball/8e0e3be58e89c2611beac9c6954a036b81b2b6fc", + "reference": "8e0e3be58e89c2611beac9c6954a036b81b2b6fc", "shasum": "" }, "require": { @@ -391,7 +391,7 @@ "issues": "https://github.com/pmmp/CallbackValidator/issues", "source": "https://github.com/pmmp/CallbackValidator/tree/rewrite" }, - "time": "2025-01-03T17:50:24+00:00" + "time": "2025-10-10T21:55:21+00:00" }, { "name": "pocketmine/color", diff --git a/src/utils/Utils.php b/src/utils/Utils.php index b3f995213..cc2505573 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -554,14 +554,16 @@ final class Utils{ * Verifies that the given callable is compatible with the desired signature. Throws a TypeError if they are * incompatible. * - * @param \Closure $signature Dummy callable with the required parameters and return type - * @param \Closure $subject Callable to check the signature of + * @param Prototype|\Closure $signature Dummy callable with the required parameters and return type, or a manually constructed Prototype + * @param \Closure $subject Callable to check the signature of * @phpstan-param anyClosure $signature * @phpstan-param anyClosure $subject */ - 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) . "`"); + public static function validateCallableSignature(Prototype|\Closure $signature, \Closure $subject) : void{ + $signaturePrototype = $signature instanceof Prototype ? $signature : Prototype::fromClosure($signature); + $subjectPrototype = Prototype::fromClosure($subject); + if(!$signaturePrototype->isSatisfiedBy($subjectPrototype)){ + throw new \TypeError("Declaration of callable `$subjectPrototype` must be compatible with `$signaturePrototype`"); } }