From 2916a606d3b390f4e9e8e2b8dd68581508be0f07 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 4 Jan 2024 19:38:38 +0100 Subject: [PATCH] revert generic annotations --- .github/workflows/tests.yml | 3 +++ CHANGELOG.md | 10 ++++++++-- src/FulfilledPromise.php | 19 +++---------------- src/Promise.php | 14 +++++--------- src/RejectedPromise.php | 19 +++---------------- 5 files changed, 22 insertions(+), 43 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 60d4f7a..ea0f7b8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -69,6 +69,9 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Remove phpspec + run: composer remove --dev friends-of-phpspec/phpspec-code-coverage phpspec/phpspec + - name: PHPStan uses: OskarStark/phpstan-ga@0.12.32 env: diff --git a/CHANGELOG.md b/CHANGELOG.md index a10d4e9..af1bac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ # Change Log -## 1.2.1 +## 1.3.0 - 2024-01-04 -### Added - 2023-11-08 +### Fixed + +- Reverted generic annotations on promise - as `then` returns another promise, there seems no way to properly document this. + +## 1.2.1 - 2023-11-08 + +### Added - Fixed PHPDoc for `wait()` and `then()`'s `onRejected` callable diff --git a/src/FulfilledPromise.php b/src/FulfilledPromise.php index c9158e7..d934a37 100644 --- a/src/FulfilledPromise.php +++ b/src/FulfilledPromise.php @@ -6,29 +6,22 @@ * A promise already fulfilled. * * @author Joel Wurtz - * - * @template-covariant T - * - * @implements Promise */ final class FulfilledPromise implements Promise { /** - * @var T + * @var mixed */ private $result; /** - * @param T $result + * @param mixed $result */ public function __construct($result) { $this->result = $result; } - /** - * {@inheritdoc} - */ public function then(callable $onFulfilled = null, callable $onRejected = null) { if (null === $onFulfilled) { @@ -42,23 +35,17 @@ public function then(callable $onFulfilled = null, callable $onRejected = null) } } - /** - * {@inheritdoc} - */ public function getState() { return Promise::FULFILLED; } - /** - * {@inheritdoc} - */ public function wait($unwrap = true) { if ($unwrap) { return $this->result; } - return; + return null; } } diff --git a/src/Promise.php b/src/Promise.php index 81434ae..35db1f7 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -12,8 +12,6 @@ * * @author Joel Wurtz * @author Márk Sági-Kazár - * - * @template-covariant T */ interface Promise { @@ -38,12 +36,10 @@ 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(T): V|null $onFulfilled called when a response will be available - * @param callable(\Throwable): V|null $onRejected called when an exception occurs - * - * @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) + * @param callable|null $onFulfilled called when a response will be available + * @param callable|null $onRejected called when an exception occurs * - * @template V + * @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) */ public function then(callable $onFulfilled = null, callable $onRejected = null); @@ -65,9 +61,9 @@ public function getState(); * * @param bool $unwrap Whether to return resolved value / throw reason or not * - * @return ($unwrap is true ? T : null) Resolved value, null if $unwrap is set to false + * @return ($unwrap is true ? mixed : null) Resolved value, null if $unwrap is set to false * - * @throws \Exception the rejection reason if $unwrap is set to true and the request failed + * @throws \Throwable the rejection reason if $unwrap is set to true and the request failed */ public function wait($unwrap = true); } diff --git a/src/RejectedPromise.php b/src/RejectedPromise.php index a500048..d6a0631 100644 --- a/src/RejectedPromise.php +++ b/src/RejectedPromise.php @@ -6,26 +6,19 @@ * A rejected promise. * * @author Joel Wurtz - * - * @template-covariant T - * - * @implements Promise */ final class RejectedPromise implements Promise { /** - * @var \Exception + * @var \Throwable */ private $exception; - public function __construct(\Exception $exception) + public function __construct(\Throwable $exception) { $this->exception = $exception; } - /** - * {@inheritdoc} - */ public function then(callable $onFulfilled = null, callable $onRejected = null) { if (null === $onRejected) { @@ -39,23 +32,17 @@ public function then(callable $onFulfilled = null, callable $onRejected = null) } } - /** - * {@inheritdoc} - */ public function getState() { return Promise::REJECTED; } - /** - * {@inheritdoc} - */ public function wait($unwrap = true) { if ($unwrap) { throw $this->exception; } - return; + return null; } }