diff --git a/CHANGELOG.md b/CHANGELOG.md index 479deb8..e5312d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +### Added + +- Generic annotations + ## 1.1.0 - 2020-07-07 ### Added diff --git a/src/FulfilledPromise.php b/src/FulfilledPromise.php index b0e1574..dce0431 100644 --- a/src/FulfilledPromise.php +++ b/src/FulfilledPromise.php @@ -6,14 +6,21 @@ * A promise already fulfilled. * * @author Joel Wurtz + * + * @template-covariant T + * + * @implements Promise */ final class FulfilledPromise implements Promise { /** - * @var mixed + * @var T */ private $result; + /** + * @param T $result + */ public function __construct($result) { $this->result = $result; diff --git a/src/Promise.php b/src/Promise.php index 3258ed0..9383726 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -12,6 +12,8 @@ * * @author Joel Wurtz * @author Márk Sági-Kazár + * + * @template-covariant T */ interface Promise { @@ -36,10 +38,12 @@ interface Promise * 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|null $onFulfilled called when a response will be available - * @param callable|null $onRejected called when an exception occurs + * @param callable(T): V|null $onFulfilled called when a response will be available + * @param callable(\Exception): V|null $onRejected called when an exception occurs + * + * @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) * - * @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) + * @template V */ public function then(callable $onFulfilled = null, callable $onRejected = null); @@ -61,7 +65,7 @@ public function getState(); * * @param bool $unwrap Whether to return resolved value / throw reason or not * - * @return mixed Resolved value, null if $unwrap is set to false + * @return T Resolved value, null if $unwrap is set to false * * @throws \Exception the rejection reason if $unwrap is set to true and the request failed */ diff --git a/src/RejectedPromise.php b/src/RejectedPromise.php index 058d0fd..2cbefec 100644 --- a/src/RejectedPromise.php +++ b/src/RejectedPromise.php @@ -6,6 +6,10 @@ * A rejected promise. * * @author Joel Wurtz + * + * @template-covariant T + * + * @implements Promise */ final class RejectedPromise implements Promise {