Closed MarcHagen closed 10 months ago
Sorry for the delay. Finally getting to focus on this. Working to resolve it today.
i reverted the annotations in https://github.com/php-http/promise/pull/33 until we can figure out if there even is a way to correctly do them.
How about this:
/**
* Adds behavior for when the promise is resolved or rejected (response will be available, or error happens).
*
* If you do not care about one of the cases, you can set the corresponding callable to null
* The callback will be called when the value arrived and never more than once.
*
* @param callable(T): V|null $onFulfilled called when a response will be available
* @param callable(\Throwable): V|null $onRejected called when an exception occurs
*
* @return Promise<mixed> a new resolved promise with value of the executed callback (onFulfilled / onRejected)
*
* @template V
*/
public function then(callable $onFulfilled = null, callable $onRejected = null);
that's a half measure, but at least something. Following chained Promise will have mixed
type. We don't chain calls too often in PHP world anyway.
hm, yeah why not. it would help at least those those who want to handle the promise, if they don't chain things.
have you tried this in a project with phpstan, does it report mistakes correctly and not report issues when the callback is used correctly? if you did, do you want to do a pull request for this? i think the return should explain that we can't precisely specify the return but explain in words what happens.
PHP version: 8.1.22
Description
How to reproduce
PHPStan config:
PHPStan playground: https://phpstan.org/r/52113abc-06c9-4058-a970-4be7b8c9b311 ignore
Http\Client\Common\Plugin
errorPossible Solution You can add a custom PHPDoc with the correct code, but it seems a bit redundant. https://github.com/php-http/client-common/pull/233#issuecomment-1796282251 has an example of this.
Additional context Seems https://github.com/php-http/client-common/pull/234 is already on the way to get it fixed! But I could hardly find ANY information about "issue". So creating a new issue for documentation purposes.
/cc @ste93cry @Ndiritu