mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
added some callable prototypes for phpstan
This commit is contained in:
parent
68bea6d4aa
commit
5c4487c980
@ -44,9 +44,15 @@ class EffectManager{
|
||||
/** @var bool */
|
||||
protected $onlyAmbientEffects = false;
|
||||
|
||||
/** @var \Closure[] */
|
||||
/**
|
||||
* @var \Closure[]
|
||||
* @phpstan-var (\Closure(EffectInstance, bool $replacesOldEffect) : void)[]
|
||||
*/
|
||||
protected $effectAddHooks = [];
|
||||
/** @var \Closure[] */
|
||||
/**
|
||||
* @var \Closure[]
|
||||
* @phpstan-var (\Closure(EffectInstance) : void)[]
|
||||
*/
|
||||
protected $effectRemoveHooks = [];
|
||||
|
||||
public function __construct(Living $entity){
|
||||
@ -214,11 +220,17 @@ class EffectManager{
|
||||
return !empty($this->effects);
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param \Closure(EffectInstance, bool $replacesOldEffect) : void $closure
|
||||
*/
|
||||
public function onEffectAdd(\Closure $closure) : void{
|
||||
Utils::validateCallableSignature(function(EffectInstance $effect, bool $replacesOldEffect) : void{}, $closure);
|
||||
$this->effectAddHooks[spl_object_id($closure)] = $closure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param \Closure(EffectInstance) : void $closure
|
||||
*/
|
||||
public function onEffectRemove(\Closure $closure) : void{
|
||||
Utils::validateCallableSignature(function(EffectInstance $effect) : void{}, $closure);
|
||||
$this->effectRemoveHooks[spl_object_id($closure)] = $closure;
|
||||
|
@ -48,6 +48,9 @@ class ChunkRequestTask extends AsyncTask{
|
||||
/** @var string */
|
||||
private $tiles = "";
|
||||
|
||||
/**
|
||||
* @phpstan-param (\Closure() : void)|null $onError
|
||||
*/
|
||||
public function __construct(int $chunkX, int $chunkZ, Chunk $chunk, CompressBatchPromise $promise, ?\Closure $onError = null){
|
||||
$this->compressionLevel = Zlib::$LEVEL;
|
||||
|
||||
@ -68,7 +71,10 @@ class ChunkRequestTask extends AsyncTask{
|
||||
}
|
||||
|
||||
public function onError() : void{
|
||||
/** @var \Closure|null $hook */
|
||||
/**
|
||||
* @var \Closure|null $hook
|
||||
* @phpstan-var (\Closure() : void)|null $hook
|
||||
*/
|
||||
$hook = $this->fetchLocal(self::TLS_KEY_ERROR_HOOK);
|
||||
if($hook !== null){
|
||||
$hook();
|
||||
|
@ -430,6 +430,9 @@ class NetworkSession{
|
||||
$this->sender->send($payload, $immediate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param \Closure() : void $func
|
||||
*/
|
||||
private function tryDisconnect(\Closure $func, string $reason) : void{
|
||||
if($this->connected and !$this->disconnectGuard){
|
||||
$this->disconnectGuard = true;
|
||||
@ -731,6 +734,7 @@ class NetworkSession{
|
||||
/**
|
||||
* Instructs the networksession to start using the chunk at the given coordinates. This may occur asynchronously.
|
||||
* @param \Closure $onCompletion To be called when chunk sending has completed.
|
||||
* @phpstan-param \Closure(int $chunkX, int $chunkZ) : void $onCompletion
|
||||
*/
|
||||
public function startUsingChunk(int $chunkX, int $chunkZ, \Closure $onCompletion) : void{
|
||||
Utils::validateCallableSignature(function(int $chunkX, int $chunkZ){}, $onCompletion);
|
||||
|
@ -27,7 +27,10 @@ use pocketmine\utils\Utils;
|
||||
use function array_push;
|
||||
|
||||
class CompressBatchPromise{
|
||||
/** @var \Closure[] */
|
||||
/**
|
||||
* @var \Closure[]
|
||||
* @phpstan-var (\Closure(self) : void)[]
|
||||
*/
|
||||
private $callbacks = [];
|
||||
|
||||
/** @var string|null */
|
||||
@ -36,6 +39,9 @@ class CompressBatchPromise{
|
||||
/** @var bool */
|
||||
private $cancelled = false;
|
||||
|
||||
/**
|
||||
* @phpstan-param \Closure(self) : void ...$callbacks
|
||||
*/
|
||||
public function onResolve(\Closure ...$callbacks) : void{
|
||||
$this->checkCancelled();
|
||||
foreach($callbacks as $callback){
|
||||
@ -65,6 +71,7 @@ class CompressBatchPromise{
|
||||
|
||||
/**
|
||||
* @return \Closure[]
|
||||
* @phpstan-return (\Closure(self) : void)[]
|
||||
*/
|
||||
public function getResolveCallbacks() : array{
|
||||
return $this->callbacks;
|
||||
|
@ -499,6 +499,7 @@ class PluginManager{
|
||||
}
|
||||
}
|
||||
|
||||
/** @phpstan-var \ReflectionClass<Event> $eventClass */
|
||||
$this->registerEvent($eventClass->getName(), $handlerClosure, $priority, $plugin, $handleCancelled);
|
||||
}
|
||||
}
|
||||
@ -507,6 +508,10 @@ class PluginManager{
|
||||
/**
|
||||
* @param string $event Class name that extends Event
|
||||
*
|
||||
* @phpstan-template TEvent of Event
|
||||
* @phpstan-param class-string<TEvent> $event
|
||||
* @phpstan-param \Closure(TEvent) : void $handler
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function registerEvent(string $event, \Closure $handler, int $priority, Plugin $plugin, bool $handleCancelled = false) : void{
|
||||
|
@ -45,7 +45,10 @@ class CancellableClosureTask extends Task{
|
||||
public const CONTINUE = true;
|
||||
public const CANCEL = false;
|
||||
|
||||
/** @var \Closure */
|
||||
/**
|
||||
* @var \Closure
|
||||
* @phpstan-var \Closure(int $currentTick) : bool
|
||||
*/
|
||||
private $closure;
|
||||
|
||||
/**
|
||||
@ -53,6 +56,8 @@ class CancellableClosureTask extends Task{
|
||||
*
|
||||
* The closure should follow the signature callback(int $currentTick) : bool. The return value will be used to
|
||||
* decide whether to continue repeating.
|
||||
*
|
||||
* @phpstan-param \Closure(int $currentTick) : bool $closure
|
||||
*/
|
||||
public function __construct(\Closure $closure){
|
||||
Utils::validateCallableSignature(function(int $currentTick) : bool{ return false; }, $closure);
|
||||
|
@ -197,6 +197,10 @@ class TimingsHandler{
|
||||
|
||||
/**
|
||||
* @return mixed the result of the given closure
|
||||
*
|
||||
* @phpstan-template TClosureReturn
|
||||
* @phpstan-param \Closure() : TClosureReturn $closure
|
||||
* @phpstan-return TClosureReturn
|
||||
*/
|
||||
public function time(\Closure $closure){
|
||||
$this->startTiming();
|
||||
|
@ -131,6 +131,9 @@ class Utils{
|
||||
return $reflect->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-return \Closure(object) : object
|
||||
*/
|
||||
public static function cloneCallback() : \Closure{
|
||||
return static function(object $o){
|
||||
return clone $o;
|
||||
|
@ -34,7 +34,10 @@ class BlockTransaction{
|
||||
/** @var Block[][][] */
|
||||
private $blocks = [];
|
||||
|
||||
/** @var \Closure[] */
|
||||
/**
|
||||
* @var \Closure[]
|
||||
* @phpstan-var (\Closure(ChunkManager $world, int $x, int $y, int $z) : bool)[]
|
||||
*/
|
||||
private $validators = [];
|
||||
|
||||
public function __construct(ChunkManager $world){
|
||||
@ -115,6 +118,8 @@ class BlockTransaction{
|
||||
* Add a validation predicate which will be used to validate every block.
|
||||
* The callable signature should be the same as the below dummy function.
|
||||
* @see BlockTransaction::dummyValidator()
|
||||
*
|
||||
* @phpstan-param \Closure(ChunkManager $world, int $x, int $y, int $z) : bool $validator
|
||||
*/
|
||||
public function addValidator(\Closure $validator) : void{
|
||||
Utils::validateCallableSignature([$this, 'dummyValidator'], $validator);
|
||||
|
@ -45,7 +45,10 @@ class SubChunkIteratorManager{
|
||||
/** @var int */
|
||||
protected $currentZ;
|
||||
|
||||
/** @var \Closure|null */
|
||||
/**
|
||||
* @var \Closure|null
|
||||
* @phpstan-var (\Closure() : void)|null
|
||||
*/
|
||||
private $onSubChunkChangeFunc = null;
|
||||
|
||||
public function __construct(ChunkManager $world){
|
||||
@ -83,6 +86,9 @@ class SubChunkIteratorManager{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param \Closure() : void $callback
|
||||
*/
|
||||
public function onSubChunkChange(\Closure $callback) : void{
|
||||
Utils::validateCallableSignature(function(){}, $callback);
|
||||
$this->onSubChunkChangeFunc = $callback;
|
||||
|
Loading…
x
Reference in New Issue
Block a user