diff --git a/src/functions.php b/src/functions.php index 6c27936..8d314d8 100644 --- a/src/functions.php +++ b/src/functions.php @@ -191,6 +191,7 @@ function async(callable $function): callable { return static function (mixed ...$args) use ($function): PromiseInterface { $fiber = null; + /** @var PromiseInterface $promise*/ $promise = new Promise(function (callable $resolve, callable $reject) use ($function, $args, &$fiber): void { $fiber = new \Fiber(function () use ($resolve, $reject, $function, $args, &$fiber): void { try { @@ -627,6 +628,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface } $promise = null; + /** @var Deferred $deferred*/ $deferred = new Deferred(function () use (&$promise) { /** @var ?PromiseInterface $promise */ if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) { @@ -685,6 +687,7 @@ function parallel(iterable $tasks): PromiseInterface { /** @var array> $pending */ $pending = []; + /** @var Deferred> $deferred */ $deferred = new Deferred(function () use (&$pending) { foreach ($pending as $promise) { if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) { @@ -734,6 +737,7 @@ function parallel(iterable $tasks): PromiseInterface $deferred->resolve($results); } + /** @var PromiseInterface> Remove once defining `Deferred()` above is supported by PHPStan, see https://github.com/phpstan/phpstan/issues/11032 */ return $deferred->promise(); } @@ -745,6 +749,7 @@ function parallel(iterable $tasks): PromiseInterface function series(iterable $tasks): PromiseInterface { $pending = null; + /** @var Deferred> $deferred */ $deferred = new Deferred(function () use (&$pending) { /** @var ?PromiseInterface $pending */ if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) { @@ -789,6 +794,7 @@ function series(iterable $tasks): PromiseInterface $next(); + /** @var PromiseInterface> Remove once defining `Deferred()` above is supported by PHPStan, see https://github.com/phpstan/phpstan/issues/11032 */ return $deferred->promise(); } @@ -800,6 +806,7 @@ function series(iterable $tasks): PromiseInterface function waterfall(iterable $tasks): PromiseInterface { $pending = null; + /** @var Deferred $deferred*/ $deferred = new Deferred(function () use (&$pending) { /** @var ?PromiseInterface $pending */ if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) { diff --git a/tests/AwaitTest.php b/tests/AwaitTest.php index 25e269b..7eced26 100644 --- a/tests/AwaitTest.php +++ b/tests/AwaitTest.php @@ -129,7 +129,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith } $promise = new Promise(function ($_, $reject) { - $reject(false); + $reject(false); // @phpstan-ignore-line }); $this->expectException(\UnexpectedValueException::class); @@ -147,7 +147,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith } $promise = new Promise(function ($_, $reject) { - $reject(null); + $reject(null); // @phpstan-ignore-line }); try { @@ -331,7 +331,7 @@ public function testAwaitShouldNotCreateAnyGarbageReferencesForPromiseRejectedWi gc_collect_cycles(); $promise = new Promise(function ($_, $reject) { - $reject(null); + $reject(null); // @phpstan-ignore-line }); try { $await($promise);