promises icon indicating copy to clipboard operation
promises copied to clipboard

Make the promise interface a generic in phpDoc

Open apokryfos opened this issue 2 years ago • 1 comments

Description Can we add generic phpDoc blocks for promises?

Example For example in the promise interface:

<?php

namespace GuzzleHttp\Promise;

/**
 * @template T
 */
interface PromiseInterface
{
   // ...  

   /**
     * @param callable(): T $onFulfilled Invoked when the promise fulfills.
     * @param callable $onRejected  Invoked when the promise is rejected.
     * @return PromiseInterface<T>
     */
    public function then(
        callable $onFulfilled = null,
        callable $onRejected = null
    );

    //...
    /**
     * Resolve the promise with the given value.
     *
     * @param T $value
     *
     * @throws \RuntimeException if the promise is already resolved.
     */
    public function resolve($value);

    /**
     * Waits until the promise completes if possible.
     *
     * Pass $unwrap as true to unwrap the result of the promise, either
     * returning the resolved value or throwing the rejected exception.
     *
     * If the promise cannot be waited on, then the promise will be rejected.
     *
     * @param bool $unwrap
     *
     * @return ($unwrap is true ? T : PromiseInterface)
     *
     * @throws \LogicException if the promise has no wait function or if the
     *                         promise does not settle after waiting.
     */
    public function wait($unwrap = true);
}

I imagine the rest of the classes need to have their docblocks updated to reflect this.

Additional context

I can help to implement this but I'm not too confident on the code base to do it alone.

Let me know what you think of this

apokryfos avatar Oct 02 '23 09:10 apokryfos