diff --git a/composer.json b/composer.json index 859292b39..5d0bcbd05 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "pocketmine/bedrock-item-upgrade-schema": "~1.15.0+bedrock-1.21.100", "pocketmine/bedrock-protocol": "~40.0.0+bedrock-1.21.100", "pocketmine/binaryutils": "^0.2.1", - "pocketmine/callback-validator": "^1.0.2", + "pocketmine/callback-validator": "dev-rewrite", "pocketmine/color": "^0.3.0", "pocketmine/errorhandler": "^0.7.0", "pocketmine/locale-data": "~2.25.0", diff --git a/composer.lock b/composer.lock index f605564fe..6dd977435 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "326e0882230a0614d3dd2f0dce8e2efc", + "content-hash": "deb7c003ba4a6101153256d5d590da42", "packages": [ { "name": "adhocore/json-comment", @@ -344,30 +344,30 @@ }, { "name": "pocketmine/callback-validator", - "version": "1.0.3", + "version": "dev-rewrite", "source": { "type": "git", "url": "https://github.com/pmmp/CallbackValidator.git", - "reference": "64787469766bcaa7e5885242e85c23c25e8c55a2" + "reference": "4b9b375590872cdd98a2a07c5aa0e1e99af5ceda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/CallbackValidator/zipball/64787469766bcaa7e5885242e85c23c25e8c55a2", - "reference": "64787469766bcaa7e5885242e85c23c25e8c55a2", + "url": "https://api.github.com/repos/pmmp/CallbackValidator/zipball/4b9b375590872cdd98a2a07c5aa0e1e99af5ceda", + "reference": "4b9b375590872cdd98a2a07c5aa0e1e99af5ceda", "shasum": "" }, "require": { "ext-reflection": "*", - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "replace": { "daverandom/callback-validator": "*" }, "require-dev": { "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "0.12.59", - "phpstan/phpstan-strict-rules": "^0.12.4", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.0" + "phpstan/phpstan": "2.1.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.0 || ^10.0 || ^11.0" }, "type": "library", "autoload": { @@ -388,9 +388,9 @@ "description": "Fork of daverandom/callback-validator - Tools for validating callback signatures", "support": { "issues": "https://github.com/pmmp/CallbackValidator/issues", - "source": "https://github.com/pmmp/CallbackValidator/tree/1.0.3" + "source": "https://github.com/pmmp/CallbackValidator/tree/rewrite" }, - "time": "2020-12-11T01:45:37+00:00" + "time": "2025-01-03T17:50:24+00:00" }, { "name": "pocketmine/color", @@ -2734,6 +2734,7 @@ ], "minimum-stability": "stable", "stability-flags": { + "pocketmine/callback-validator": 20, "pocketmine/math": 20 }, "prefer-stable": false, diff --git a/src/entity/EntityFactory.php b/src/entity/EntityFactory.php index 970fd986f..c41f76d64 100644 --- a/src/entity/EntityFactory.php +++ b/src/entity/EntityFactory.php @@ -23,9 +23,6 @@ declare(strict_types=1); namespace pocketmine\entity; -use DaveRandom\CallbackValidator\CallbackType; -use DaveRandom\CallbackValidator\ParameterType; -use DaveRandom\CallbackValidator\ReturnType; use pocketmine\block\RuntimeBlockStateRegistry; use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap; use pocketmine\data\bedrock\PotionTypeIdMap; @@ -206,11 +203,7 @@ final class EntityFactory{ throw new \InvalidArgumentException("At least one save name must be provided"); } Utils::testValidInstance($className, Entity::class); - Utils::validateCallableSignature(new CallbackType( - new ReturnType(Entity::class), - new ParameterType("world", World::class), - new ParameterType("nbt", CompoundTag::class) - ), $creationFunc); + Utils::validateCallableSignature(fn(World $world, CompoundTag $nbt) : Entity => die(), $creationFunc); foreach($saveNames as $name){ $this->creationFuncs[$name] = $creationFunc; diff --git a/src/item/enchantment/Enchantment.php b/src/item/enchantment/Enchantment.php index e8335d5f3..f36943b57 100644 --- a/src/item/enchantment/Enchantment.php +++ b/src/item/enchantment/Enchantment.php @@ -23,9 +23,6 @@ declare(strict_types=1); namespace pocketmine\item\enchantment; -use DaveRandom\CallbackValidator\CallbackType; -use DaveRandom\CallbackValidator\ParameterType; -use DaveRandom\CallbackValidator\ReturnType; use pocketmine\lang\Translatable; use pocketmine\utils\NotCloneable; use pocketmine\utils\NotSerializable; @@ -55,10 +52,7 @@ class Enchantment{ ){ $this->minEnchantingPower = $minEnchantingPower ?? fn(int $level) : int => 1; - Utils::validateCallableSignature(new CallbackType( - new ReturnType("int"), - new ParameterType("level", "int") - ), $this->minEnchantingPower); + Utils::validateCallableSignature(fn(int $level) : int => die(), $this->minEnchantingPower); } /** diff --git a/src/scheduler/ClosureTask.php b/src/scheduler/ClosureTask.php index 4b8166f22..97e12183d 100644 --- a/src/scheduler/ClosureTask.php +++ b/src/scheduler/ClosureTask.php @@ -23,8 +23,6 @@ declare(strict_types=1); namespace pocketmine\scheduler; -use DaveRandom\CallbackValidator\CallbackType; -use DaveRandom\CallbackValidator\ReturnType; use pocketmine\utils\Utils; /** @@ -46,7 +44,7 @@ class ClosureTask extends Task{ public function __construct( private \Closure $closure ){ - Utils::validateCallableSignature(new CallbackType(new ReturnType()), $closure); + Utils::validateCallableSignature(function() : void{}, $closure); } public function getName() : string{ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index c132e6636..b3f995213 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -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) . "`"); } } diff --git a/src/world/BlockTransaction.php b/src/world/BlockTransaction.php index 46cbc7903..103b8cd88 100644 --- a/src/world/BlockTransaction.php +++ b/src/world/BlockTransaction.php @@ -127,7 +127,7 @@ class BlockTransaction{ * @phpstan-param \Closure(ChunkManager $world, int $x, int $y, int $z) : bool $validator */ public function addValidator(\Closure $validator) : void{ - Utils::validateCallableSignature([$this, 'dummyValidator'], $validator); + Utils::validateCallableSignature($this->dummyValidator(...), $validator); $this->validators[] = $validator; }