From ac6adafec5fa2720d77e11281976b741f62cbc97 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 15 Nov 2023 14:46:55 +0545 Subject: [PATCH] Increase phpstan level to 9 --- lib/EmitterTrait.php | 2 +- lib/Loop/Loop.php | 2 +- lib/Promise.php | 17 +++++++++++++---- lib/WildcardEmitterTrait.php | 6 +++--- phpstan.neon | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/EmitterTrait.php b/lib/EmitterTrait.php index c75645d..fdd376d 100644 --- a/lib/EmitterTrait.php +++ b/lib/EmitterTrait.php @@ -172,7 +172,7 @@ public function removeAllListeners(string $eventName = null): void /** * The list of listeners. * - * @var array, 2:array}> + * @var array, 2:array}> */ protected array $listeners = []; } diff --git a/lib/Loop/Loop.php b/lib/Loop/Loop.php index 2a9f767..5a9ef5d 100644 --- a/lib/Loop/Loop.php +++ b/lib/Loop/Loop.php @@ -302,7 +302,7 @@ protected function runStreams(?float $timeout): void /** * A list of timers, added by setTimeout. * - * @var array + * @var array */ protected array $timers = []; diff --git a/lib/Promise.php b/lib/Promise.php index 2928ce6..4c86ee2 100644 --- a/lib/Promise.php +++ b/lib/Promise.php @@ -188,8 +188,13 @@ public function wait() return $this->value; } else { // If we got here, it means that the asynchronous operation - // errored. Therefore we need to throw an exception. - throw $this->value; + // errored. Therefore, we need to throw an exception. + if ($this->value instanceof \Throwable) { + throw $this->value; + } + // The state should have been REJECTED, with "value" a Throwable + // But "value" was not a Throwable. So throw a more general exception. + throw new \LogicException('The Promise was not fulfilled but no exception was specified'); } } @@ -197,7 +202,7 @@ public function wait() * A list of subscribers. Subscribers are the callbacks that want us to let * them know if the callback was fulfilled or rejected. * - * @var array + * @var array, 1:callable|null, 2:callable|null}> */ protected array $subscribers = []; @@ -251,7 +256,11 @@ private function invokeCallback(Promise $subPromise, callable $callBack = null): if (self::FULFILLED === $this->state) { $subPromise->fulfill($this->value); } else { - $subPromise->reject($this->value); + if ($this->value instanceof \Throwable) { + $subPromise->reject($this->value); + } else { + throw new \LogicException('The subPromise was not fulfilled but no exception was specified'); + } } } }); diff --git a/lib/WildcardEmitterTrait.php b/lib/WildcardEmitterTrait.php index 03e98c7..af8432f 100644 --- a/lib/WildcardEmitterTrait.php +++ b/lib/WildcardEmitterTrait.php @@ -216,14 +216,14 @@ public function removeAllListeners(string $eventName = null): void /** * The list of listeners. * - * @var array + * @var array> */ protected array $listeners = []; /** * The list of "wildcard listeners". * - * @var array + * @var array> */ protected array $wildcardListeners = []; @@ -233,7 +233,7 @@ public function removeAllListeners(string $eventName = null): void * * If the list of listeners changes though, the index clears. * - * @var array + * @var array> */ protected array $listenerIndex = []; } diff --git a/phpstan.neon b/phpstan.neon index fd52a60..4b77189 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 8 + level: 9 phpVersion: 70430 # PHP 7.4.30 ignoreErrors: -