diff --git a/.styleci.yml b/.styleci.yml index 296cab4..56775ca 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -6,5 +6,3 @@ finder: path: - "src" -enabled: - - short_array_syntax 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 f60f686..def54a8 100644 --- a/src/FulfilledPromise.php +++ b/src/FulfilledPromise.php @@ -6,16 +6,19 @@ * A promise already fulfilled. * * @author Joel Wurtz + * + * @template-covariant T + * @implements Promise */ final class FulfilledPromise implements Promise { /** - * @var mixed + * @var T */ private $result; /** - * @param $result + * @param T $result */ public function __construct($result) { diff --git a/src/Promise.php b/src/Promise.php index 3258ed0..146faba 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,11 @@ 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 +64,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 e396a40..ad7bdf5 100644 --- a/src/RejectedPromise.php +++ b/src/RejectedPromise.php @@ -6,6 +6,9 @@ * A rejected promise. * * @author Joel Wurtz + * + * @template-covariant T + * @implements Promise */ final class RejectedPromise implements Promise { @@ -14,9 +17,6 @@ final class RejectedPromise implements Promise */ private $exception; - /** - * @param \Exception $exception - */ public function __construct(\Exception $exception) { $this->exception = $exception;