diff --git a/src/functions.php b/src/functions.php index 3ef0e45..611e827 100644 --- a/src/functions.php +++ b/src/functions.php @@ -323,6 +323,7 @@ function coroutine(callable $function, ...$args): PromiseInterface } $promise = null; + /** @var Deferred $deferred*/ $deferred = new Deferred(function () use (&$promise) { /** @var ?PromiseInterface $promise */ if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) { @@ -381,6 +382,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')) { @@ -430,6 +432,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(); } @@ -441,6 +444,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')) { @@ -485,6 +489,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(); } @@ -496,6 +501,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 397a0fa..f0becee 100644 --- a/tests/AwaitTest.php +++ b/tests/AwaitTest.php @@ -26,7 +26,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith } $promise = new Promise(function ($_, $reject) { - $reject(false); + $reject(false); // @phpstan-ignore-line }); $this->expectException(\UnexpectedValueException::class); @@ -41,7 +41,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith } $promise = new Promise(function ($_, $reject) { - $reject(null); + $reject(null); // @phpstan-ignore-line }); $this->expectException(\UnexpectedValueException::class); @@ -278,7 +278,7 @@ public function testAwaitShouldNotCreateAnyGarbageReferencesForPromiseRejectedWi gc_collect_cycles(); $promise = new Promise(function ($_, $reject) { - $reject(null); + $reject(null); // @phpstan-ignore-line }); try { React\Async\await($promise);