From 2b402e525a3f0015b294961a5100e2c32efb12b2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 29 Jan 2020 15:03:55 +0000 Subject: [PATCH] add some PHPStan-specific callable prototypes --- src/pocketmine/scheduler/AsyncPool.php | 9 ++++++++- src/pocketmine/scheduler/ClosureTask.php | 6 +++++- src/pocketmine/utils/Internet.php | 1 + src/pocketmine/utils/Utils.php | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/scheduler/AsyncPool.php b/src/pocketmine/scheduler/AsyncPool.php index b0b4f9754..4aca3a5d9 100644 --- a/src/pocketmine/scheduler/AsyncPool.php +++ b/src/pocketmine/scheduler/AsyncPool.php @@ -68,7 +68,10 @@ class AsyncPool{ /** @var int[] */ private $workerLastUsed = []; - /** @var \Closure[] */ + /** + * @var \Closure[] + * @phpstan-var (\Closure(int $workerId) : void)[] + */ private $workerStartHooks = []; public function __construct(Server $server, int $size, int $workerMemoryLimit, \ClassLoader $classLoader, \ThreadedLogger $logger){ @@ -100,6 +103,8 @@ class AsyncPool{ * The signature should be `function(int $worker) : void` * * This function will call the hook for every already-running worker. + * + * @phpstan-param \Closure(int $workerId) : void $hook */ public function addWorkerStartHook(\Closure $hook) : void{ Utils::validateCallableSignature(function(int $worker) : void{}, $hook); @@ -111,6 +116,8 @@ class AsyncPool{ /** * Removes a previously-registered callback listening for workers being started. + * + * @phpstan-param \Closure(int $workerId) : void $hook */ public function removeWorkerStartHook(\Closure $hook) : void{ unset($this->workerStartHooks[spl_object_hash($hook)]); diff --git a/src/pocketmine/scheduler/ClosureTask.php b/src/pocketmine/scheduler/ClosureTask.php index f023173d4..78610ef71 100644 --- a/src/pocketmine/scheduler/ClosureTask.php +++ b/src/pocketmine/scheduler/ClosureTask.php @@ -38,11 +38,15 @@ use pocketmine\utils\Utils; */ class ClosureTask extends Task{ - /** @var \Closure */ + /** + * @var \Closure + * @phpstan-var \Closure(int) : void + */ private $closure; /** * @param \Closure $closure Must accept only ONE parameter, $currentTick + * @phpstan-param \Closure(int) : void $closure */ public function __construct(\Closure $closure){ Utils::validateCallableSignature(function(int $currentTick) : void{}, $closure); diff --git a/src/pocketmine/utils/Internet.php b/src/pocketmine/utils/Internet.php index 0055bd041..732865c36 100644 --- a/src/pocketmine/utils/Internet.php +++ b/src/pocketmine/utils/Internet.php @@ -183,6 +183,7 @@ class Internet{ * @param string[] $extraHeaders extra headers to send as a plain string array * @param array $extraOpts extra CURLOPT_* to set as an [opt => value] map * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. + * @phpstan-param (callable(resource) : void)|null $onSuccess * * @return array a plain array of three [result body : string, headers : array[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values * diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 7d1a51470..10ce678eb 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -454,6 +454,7 @@ class Utils{ * @param string[] $extraHeaders extra headers to send as a plain string array * @param array $extraOpts extra CURLOPT_* to set as an [opt => value] map * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. + * @phpstan-param (callable(resource) : void)|null $onSuccess * * @return array a plain array of three [result body : string, headers : array[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values *