mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
Utils: allow validateCallableSignature() to accept a manually constructed CallbackType instead of a closure
this allows more fine-grained control without PHPStan yelling at us.
This commit is contained in:
parent
fd2df637b6
commit
912e612743
@ -488,17 +488,20 @@ final class Utils{
|
|||||||
* Verifies that the given callable is compatible with the desired signature. Throws a TypeError if they are
|
* Verifies that the given callable is compatible with the desired signature. Throws a TypeError if they are
|
||||||
* incompatible.
|
* incompatible.
|
||||||
*
|
*
|
||||||
* @param callable $signature Dummy callable with the required parameters and return type
|
* @param callable|CallbackType $signature Dummy callable with the required parameters and return type
|
||||||
* @param callable $subject Callable to check the signature of
|
* @param callable $subject Callable to check the signature of
|
||||||
* @phpstan-param anyCallable $signature
|
* @phpstan-param anyCallable|CallbackType $signature
|
||||||
* @phpstan-param anyCallable $subject
|
* @phpstan-param anyCallable $subject
|
||||||
*
|
*
|
||||||
* @throws \DaveRandom\CallbackValidator\InvalidCallbackException
|
* @throws \DaveRandom\CallbackValidator\InvalidCallbackException
|
||||||
* @throws \TypeError
|
* @throws \TypeError
|
||||||
*/
|
*/
|
||||||
public static function validateCallableSignature(callable $signature, callable $subject) : void{
|
public static function validateCallableSignature(callable|CallbackType $signature, callable $subject) : void{
|
||||||
if(!($sigType = CallbackType::createFromCallable($signature))->isSatisfiedBy($subject)){
|
if(!($signature instanceof CallbackType)){
|
||||||
throw new \TypeError("Declaration of callable `" . CallbackType::createFromCallable($subject) . "` must be compatible with `" . $sigType . "`");
|
$signature = CallbackType::createFromCallable($signature);
|
||||||
|
}
|
||||||
|
if(!$signature->isSatisfiedBy($subject)){
|
||||||
|
throw new \TypeError("Declaration of callable `" . CallbackType::createFromCallable($subject) . "` must be compatible with `" . $signature . "`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user