Update CallbackValidator

This commit is contained in:
Dylan K. Taylor
2025-10-10 23:00:35 +01:00
parent a12592ab8c
commit f1c5c7b699
2 changed files with 11 additions and 9 deletions

8
composer.lock generated
View File

@@ -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",

View File

@@ -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`");
}
}